Coverage Report

Created: 2026-07-25 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibPDF/Reader.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Matthew Olsson <mattco@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibPDF/Reader.h>
8
#include <ctype.h>
9
10
namespace PDF {
11
12
bool Reader::is_eol(char c)
13
10.6M
{
14
10.6M
    return c == 0xa || c == 0xd;
15
10.6M
}
16
17
bool Reader::is_whitespace(char c)
18
118k
{
19
118k
    return is_eol(c) || is_non_eol_whitespace(c);
20
118k
}
21
22
bool Reader::is_non_eol_whitespace(char c)
23
112k
{
24
    // 3.1.1 Character Set
25
112k
    return c == 0 || c == 0x9 || c == 0xc || c == ' ';
26
112k
}
27
28
bool Reader::matches_eol() const
29
10.5M
{
30
10.5M
    return !done() && is_eol(peek());
31
10.5M
}
32
33
bool Reader::matches_whitespace() const
34
118k
{
35
118k
    return !done() && is_whitespace(peek());
36
118k
}
37
38
bool Reader::matches_non_eol_whitespace() const
39
0
{
40
0
    return !done() && is_non_eol_whitespace(peek());
41
0
}
42
43
bool Reader::matches_number() const
44
137
{
45
137
    if (done())
46
0
        return false;
47
137
    auto ch = peek();
48
137
    return isdigit(ch) || ch == '-' || ch == '+' || ch == '.';
49
137
}
50
51
bool Reader::matches_delimiter() const
52
283
{
53
283
    return matches_any('(', ')', '<', '>', '[', ']', '{', '}', '/', '%');
54
283
}
55
56
bool Reader::matches_regular_character() const
57
283
{
58
283
    return !done() && !matches_delimiter() && !matches_whitespace();
59
283
}
60
61
bool Reader::consume_eol()
62
104k
{
63
104k
    if (done()) {
64
0
        return false;
65
0
    }
66
104k
    if (matches("\r\n")) {
67
1.98k
        consume(2);
68
1.98k
        return true;
69
1.98k
    }
70
102k
    if (matches_eol()) {
71
102k
        consume();
72
102k
        return true;
73
102k
    }
74
10
    return false;
75
102k
}
76
77
bool Reader::consume_whitespace()
78
104k
{
79
104k
    bool consumed = false;
80
117k
    while (matches_whitespace()) {
81
13.1k
        consumed = true;
82
13.1k
        consume();
83
13.1k
    }
84
104k
    return consumed;
85
104k
}
86
87
bool Reader::consume_non_eol_whitespace()
88
0
{
89
0
    bool consumed = false;
90
0
    while (matches_non_eol_whitespace()) {
91
0
        consumed = true;
92
0
        consume();
93
0
    }
94
0
    return consumed;
95
0
}
96
97
char Reader::consume()
98
120k
{
99
120k
    return read();
100
120k
}
101
102
void Reader::consume(int amount)
103
1.99k
{
104
6.02k
    for (size_t i = 0; i < static_cast<size_t>(amount); i++)
105
4.02k
        consume();
106
1.99k
}
107
108
bool Reader::consume(char ch)
109
111
{
110
111
    return consume() == ch;
111
111
}
112
113
}