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:
Rodrigo Tobar 2022-12-11 22:20:53 +08:00 committed by Andreas Kling
parent d94f3b902c
commit d9718064d1
Notes: sideshowbarker 2024-07-18 03:35:30 +09:00

View file

@ -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)