mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 12:04:58 +00:00

SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Function.h>
|
|
#include <AK/String.h>
|
|
#include <AK/Types.h>
|
|
|
|
#include "Parser.h"
|
|
|
|
void Parser::write(const StringView& data)
|
|
{
|
|
for (size_t i = 0; i < data.length(); i++) {
|
|
u8 ch = data[i];
|
|
|
|
switch (m_state) {
|
|
case State::Free:
|
|
switch (ch) {
|
|
case IAC:
|
|
m_state = State::ReadCommand;
|
|
break;
|
|
case '\r':
|
|
if (on_data)
|
|
on_data("\n");
|
|
break;
|
|
default:
|
|
if (on_data)
|
|
on_data(StringView(&ch, 1));
|
|
break;
|
|
}
|
|
break;
|
|
case State::ReadCommand:
|
|
switch (ch) {
|
|
case IAC: {
|
|
m_state = State::Free;
|
|
if (on_data)
|
|
on_data("\xff");
|
|
break;
|
|
}
|
|
case CMD_WILL:
|
|
case CMD_WONT:
|
|
case CMD_DO:
|
|
case CMD_DONT:
|
|
m_command = ch;
|
|
m_state = State::ReadSubcommand;
|
|
break;
|
|
default:
|
|
m_state = State::Error;
|
|
if (on_error)
|
|
on_error();
|
|
break;
|
|
}
|
|
break;
|
|
case State::ReadSubcommand: {
|
|
auto command = m_command;
|
|
m_command = 0;
|
|
m_state = State::Free;
|
|
if (on_command)
|
|
on_command({ command, ch });
|
|
break;
|
|
}
|
|
case State::Error:
|
|
// ignore everything
|
|
break;
|
|
}
|
|
}
|
|
}
|