mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibPDF: Add support for multi-line comments
The code parsing comments parsed only a single line of comments, but callers assumed they parsed all comments that appeared contiguously in a block. The latter is an easier to understand API, so this commit changes the parse_comment function to parse entire blocks of comments instead of single lines.
This commit is contained in:
parent
d94f3b902c
commit
d9718064d1
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/d9718064d1 Pull-request: https://github.com/SerenityOS/serenity/pull/16496
1 changed files with 14 additions and 11 deletions
|
@ -39,18 +39,21 @@ void Parser::set_document(WeakPtr<Document> const& document)
|
|||
|
||||
DeprecatedString Parser::parse_comment()
|
||||
{
|
||||
if (!m_reader.matches('%'))
|
||||
return {};
|
||||
StringBuilder comment;
|
||||
while (true) {
|
||||
if (!m_reader.matches('%'))
|
||||
break;
|
||||
|
||||
m_reader.consume();
|
||||
auto comment_start_offset = m_reader.offset();
|
||||
m_reader.move_until([&](auto) {
|
||||
return m_reader.matches_eol();
|
||||
});
|
||||
DeprecatedString str = StringView(m_reader.bytes().slice(comment_start_offset, m_reader.offset() - comment_start_offset));
|
||||
m_reader.consume_eol();
|
||||
m_reader.consume_whitespace();
|
||||
return str;
|
||||
m_reader.consume();
|
||||
auto comment_start_offset = m_reader.offset();
|
||||
m_reader.move_until([&](auto) {
|
||||
return m_reader.matches_eol();
|
||||
});
|
||||
comment.append(m_reader.bytes().slice(comment_start_offset, m_reader.offset() - comment_start_offset));
|
||||
m_reader.consume_eol();
|
||||
m_reader.consume_whitespace();
|
||||
}
|
||||
return comment.to_deprecated_string();
|
||||
}
|
||||
|
||||
PDFErrorOr<Value> Parser::parse_value(CanBeIndirectValue can_be_indirect_value)
|
||||
|
|
Loading…
Reference in a new issue