LibIMAP: Add and use Parser::consume_until_end_of_line()

This commit is contained in:
Linus Groh 2021-07-24 20:54:30 +01:00
parent 8e8d1383b7
commit ddd11b98d9
Notes: sideshowbarker 2024-07-18 08:22:45 +09:00
2 changed files with 11 additions and 8 deletions

View File

@ -22,7 +22,7 @@ ParseStatus Parser::parse(ByteBuffer&& buffer, bool expecting_tag)
if (try_consume("+")) {
consume(" ");
auto data = consume_while([](u8 x) { return x != '\r'; });
auto data = consume_until_end_of_line();
consume("\r\n");
return { true, { ContinueRequest { data } } };
}
@ -182,12 +182,9 @@ void Parser::parse_untagged()
consume_while([](u8 x) { return x != ']'; });
}
consume("]");
consume_while([](u8 x) { return x != '\r'; });
consume("\r\n");
} else {
consume_while([](u8 x) { return x != '\r'; });
consume("\r\n");
}
consume_until_end_of_line();
consume("\r\n");
} else if (try_consume("SEARCH")) {
Vector<unsigned> ids;
while (!try_consume("\r\n")) {
@ -197,7 +194,7 @@ void Parser::parse_untagged()
}
m_response.data().set_search_results(move(ids));
} else if (try_consume("BYE")) {
auto message = consume_while([](u8 x) { return x != '\r'; });
auto message = consume_until_end_of_line();
consume("\r\n");
m_response.data().set_bye(message.is_empty() ? Optional<String>() : Optional<String>(message));
} else if (try_consume("STATUS")) {
@ -236,7 +233,7 @@ void Parser::parse_untagged()
try_consume(" "); // Not in the spec but the Outlook server sends a space for some reason.
consume("\r\n");
} else {
auto x = consume_while([](u8 x) { return x != '\r'; });
auto x = consume_until_end_of_line();
consume("\r\n");
dbgln("ignored {}", x);
}
@ -687,6 +684,11 @@ StringView Parser::consume_while(Function<bool(u8)> should_consume)
return StringView(m_buffer.data() + position - chars, chars);
}
StringView Parser::consume_until_end_of_line()
{
return consume_while([](u8 x) { return x != '\r'; });
}
FetchCommand::DataItem Parser::parse_fetch_data_item()
{
auto msg_attr = consume_while([](u8 x) { return is_ascii_alpha(x) != 0; });

View File

@ -28,6 +28,7 @@ private:
void consume(StringView);
bool try_consume(StringView);
StringView consume_while(Function<bool(u8)> should_consume);
StringView consume_until_end_of_line();
bool at_end() { return position >= m_buffer.size(); };