PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfUtils.h
1// SPDX-FileCopyrightText: 2022 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_UTILS_H
5#define PDF_UTILS_H
6
8
9namespace PoDoFo
10{
11 inline bool IsCharWhitespace(char ch)
12 {
13 switch (ch)
14 {
15 case '\0': // NULL
16 return true;
17 case '\t': // TAB
18 return true;
19 case '\n': // Line Feed
20 return true;
21 case '\f': // Form Feed
22 return true;
23 case '\r': // Carriage Return
24 return true;
25 case ' ': // White space
26 return true;
27 default:
28 return false;
29 }
30 }
31
32 inline bool IsCharDelimiter(char ch)
33 {
34 switch (ch)
35 {
36 case '(':
37 return true;
38 case ')':
39 return true;
40 case '<':
41 return true;
42 case '>':
43 return true;
44 case '[':
45 return true;
46 case ']':
47 return true;
48 case '{':
49 return true;
50 case '}':
51 return true;
52 case '/':
53 return true;
54 case '%':
55 return true;
56 default:
57 return false;
58 }
59 }
60
61 inline bool IsCharTokenDelimiter(char ch, PdfTokenType& tokenType)
62 {
63 switch (ch)
64 {
65 case '(':
66 tokenType = PdfTokenType::ParenthesisLeft;
67 return true;
68 case ')':
69 tokenType = PdfTokenType::ParenthesisRight;
70 return true;
71 case '[':
72 tokenType = PdfTokenType::SquareBracketLeft;
73 return true;
74 case ']':
75 tokenType = PdfTokenType::SquareBracketRight;
76 return true;
77 case '{':
78 tokenType = PdfTokenType::BraceLeft;
79 return true;
80 case '}':
81 tokenType = PdfTokenType::BraceRight;
82 return true;
83 case '/':
84 tokenType = PdfTokenType::Slash;
85 return true;
86 default:
87 tokenType = PdfTokenType::Unknown;
88 return false;
89 }
90 }
91
93 inline bool IsCharRegular(char ch)
94 {
95 return !(IsCharWhitespace(ch) || IsCharDelimiter(ch));
96 }
97
100 inline bool IsCharASCIIPrintable(char ch)
101 {
102 return ch > 32 && ch < 127;
103 }
104}
105
106#endif // PDF_UTILS_H
This file should be included as the FIRST file in every header of PoDoFo lib.
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
bool IsCharASCIIPrintable(char ch)
Check if the character is within the range of non control code ASCII characters.
Definition PdfUtils.h:100
bool IsCharRegular(char ch)
Checks if a character is neither whitespace or delimiter.
Definition PdfUtils.h:93