Debian Codegraph @

include/prism/util/pm_char.h

raw symbols SCIP
1 /**
2 * @file pm_char.h
3 *
4 * Functions for working with characters and strings.
5 */
6 #ifndef PRISM_CHAR_H
7 #define PRISM_CHAR_H
8
9 #include "prism/defines.h"
10 #include "prism/util/pm_newline_list.h"
11
12 #include <stdbool.h>
13 #include <stddef.h>
14
15 /**
16 * Returns the number of characters at the start of the string that are
17 * whitespace. Disallows searching past the given maximum number of characters.
18 *
19 * @param string The string to search.
20 * @param length The maximum number of characters to search.
21 * @return The number of characters at the start of the string that are
22 * whitespace.
23 */
24 size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
25
26 /**
27 * Returns the number of characters at the start of the string that are
28 * whitespace while also tracking the location of each newline. Disallows
29 * searching past the given maximum number of characters.
30 *
31 * @param string The string to search.
32 * @param length The maximum number of characters to search.
33 * @param newline_list The list of newlines to populate.
34 * @return The number of characters at the start of the string that are
35 * whitespace.
36 */
37 size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
38
39 /**
40 * Returns the number of characters at the start of the string that are inline
41 * whitespace. Disallows searching past the given maximum number of characters.
42 *
43 * @param string The string to search.
44 * @param length The maximum number of characters to search.
45 * @return The number of characters at the start of the string that are inline
46 * whitespace.
47 */
48 size_t pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length);
49
50 /**
51 * Returns the number of characters at the start of the string that are decimal
52 * digits. Disallows searching past the given maximum number of characters.
53 *
54 * @param string The string to search.
55 * @param length The maximum number of characters to search.
56 * @return The number of characters at the start of the string that are decimal
57 * digits.
58 */
59 size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length);
60
61 /**
62 * Returns the number of characters at the start of the string that are
63 * hexadecimal digits. Disallows searching past the given maximum number of
64 * characters.
65 *
66 * @param string The string to search.
67 * @param length The maximum number of characters to search.
68 * @return The number of characters at the start of the string that are
69 * hexadecimal digits.
70 */
71 size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length);
72
73 /**
74 * Returns the number of characters at the start of the string that are octal
75 * digits or underscores. Disallows searching past the given maximum number of
76 * characters.
77 *
78 * If multiple underscores are found in a row or if an underscore is
79 * found at the end of the number, then the invalid pointer is set to the index
80 * of the first invalid underscore.
81 *
82 * @param string The string to search.
83 * @param length The maximum number of characters to search.
84 * @param invalid The pointer to set to the index of the first invalid
85 * underscore.
86 * @return The number of characters at the start of the string that are octal
87 * digits or underscores.
88 */
89 size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
90
91 /**
92 * Returns the number of characters at the start of the string that are decimal
93 * digits or underscores. Disallows searching past the given maximum number of
94 * characters.
95 *
96 * If multiple underscores are found in a row or if an underscore is
97 * found at the end of the number, then the invalid pointer is set to the index
98 * of the first invalid underscore.
99 *
100 * @param string The string to search.
101 * @param length The maximum number of characters to search.
102 * @param invalid The pointer to set to the index of the first invalid
103 * underscore.
104 * @return The number of characters at the start of the string that are decimal
105 * digits or underscores.
106 */
107 size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
108
109 /**
110 * Returns the number of characters at the start of the string that are
111 * hexadecimal digits or underscores. Disallows searching past the given maximum
112 * number of characters.
113 *
114 * If multiple underscores are found in a row or if an underscore is
115 * found at the end of the number, then the invalid pointer is set to the index
116 * of the first invalid underscore.
117 *
118 * @param string The string to search.
119 * @param length The maximum number of characters to search.
120 * @param invalid The pointer to set to the index of the first invalid
121 * underscore.
122 * @return The number of characters at the start of the string that are
123 * hexadecimal digits or underscores.
124 */
125 size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
126
127 /**
128 * Returns the number of characters at the start of the string that are regexp
129 * options. Disallows searching past the given maximum number of characters.
130 *
131 * @param string The string to search.
132 * @param length The maximum number of characters to search.
133 * @return The number of characters at the start of the string that are regexp
134 * options.
135 */
136 size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length);
137
138 /**
139 * Returns the number of characters at the start of the string that are binary
140 * digits or underscores. Disallows searching past the given maximum number of
141 * characters.
142 *
143 * If multiple underscores are found in a row or if an underscore is
144 * found at the end of the number, then the invalid pointer is set to the index
145 * of the first invalid underscore.
146 *
147 * @param string The string to search.
148 * @param length The maximum number of characters to search.
149 * @param invalid The pointer to set to the index of the first invalid
150 * underscore.
151 * @return The number of characters at the start of the string that are binary
152 * digits or underscores.
153 */
154 size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
155
156 /**
157 * Returns true if the given character is a whitespace character.
158 *
159 * @param b The character to check.
160 * @return True if the given character is a whitespace character.
161 */
162 bool pm_char_is_whitespace(const uint8_t b);
163
164 /**
165 * Returns true if the given character is an inline whitespace character.
166 *
167 * @param b The character to check.
168 * @return True if the given character is an inline whitespace character.
169 */
170 bool pm_char_is_inline_whitespace(const uint8_t b);
171
172 /**
173 * Returns true if the given character is a binary digit.
174 *
175 * @param b The character to check.
176 * @return True if the given character is a binary digit.
177 */
178 bool pm_char_is_binary_digit(const uint8_t b);
179
180 /**
181 * Returns true if the given character is an octal digit.
182 *
183 * @param b The character to check.
184 * @return True if the given character is an octal digit.
185 */
186 bool pm_char_is_octal_digit(const uint8_t b);
187
188 /**
189 * Returns true if the given character is a decimal digit.
190 *
191 * @param b The character to check.
192 * @return True if the given character is a decimal digit.
193 */
194 bool pm_char_is_decimal_digit(const uint8_t b);
195
196 /**
197 * Returns true if the given character is a hexadecimal digit.
198 *
199 * @param b The character to check.
200 * @return True if the given character is a hexadecimal digit.
201 */
202 bool pm_char_is_hexadecimal_digit(const uint8_t b);
203
204 #endif