mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:07:43 +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
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()
|
DeprecatedString Parser::parse_comment()
|
||||||
{
|
{
|
||||||
if (!m_reader.matches('%'))
|
StringBuilder comment;
|
||||||
return {};
|
while (true) {
|
||||||
|
if (!m_reader.matches('%'))
|
||||||
|
break;
|
||||||
|
|
||||||
m_reader.consume();
|
m_reader.consume();
|
||||||
auto comment_start_offset = m_reader.offset();
|
auto comment_start_offset = m_reader.offset();
|
||||||
m_reader.move_until([&](auto) {
|
m_reader.move_until([&](auto) {
|
||||||
return m_reader.matches_eol();
|
return m_reader.matches_eol();
|
||||||
});
|
});
|
||||||
DeprecatedString str = StringView(m_reader.bytes().slice(comment_start_offset, m_reader.offset() - comment_start_offset));
|
comment.append(m_reader.bytes().slice(comment_start_offset, m_reader.offset() - comment_start_offset));
|
||||||
m_reader.consume_eol();
|
m_reader.consume_eol();
|
||||||
m_reader.consume_whitespace();
|
m_reader.consume_whitespace();
|
||||||
return str;
|
}
|
||||||
|
return comment.to_deprecated_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFErrorOr<Value> Parser::parse_value(CanBeIndirectValue can_be_indirect_value)
|
PDFErrorOr<Value> Parser::parse_value(CanBeIndirectValue can_be_indirect_value)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue