ds 0.10.0
A C library to safely yet efficiently work with UTF-8–encoded, growable dynamic strings.
char.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef DS_CHAR_H
4#define DS_CHAR_H 1
5
6//! @file ds/char.h
7//! @author Avinash Maddikonda (svasssakavi@gmail.com)
8//! @brief Declaration of the @ref ds_char_t "char" type, related constants and
9//! functions.
10//! @since 0.3.0
11//! @date 2023-07-26
12
13#include <limits.h>
14#include <stdbool.h>
15
16#include "ds/usize.h"
17
18#ifdef __cplusplus
19extern "C"
20{
21#endif /* __cplusplus */
22
23 /// @brief A character type.
24 ///
25 /// The @ref ds_char_t "char" type represents a single character.
26 ///
27 /// More specifically, since ‘character’ isn’t a well-defined concept in
28 /// Unicode, @ref ds_char_t "char" will be a ‘Unicode scalar value’ in the
29 /// future, when UTF-8 validation is fully supported.
30 typedef char ds_char_t;
31
32 /// @brief A function pointer type for @ref ds_char_t "char" predicate
33 /// functions that return `true` or `false` depending on the passed @ref
34 /// ds_char_t "char" argument.
35 ///
36 /// Expected function signature:
37 ///
38 /// ```c
39 /// bool predicate(ds_char_t);
40 /// ```
41 ///
42 /// ### Examples
43 ///
44 /// Basic usage:
45 ///
46 /// ```c
47 /// ds_usize_t
48 /// count_only_allowed (ds_cstr_t const cstr, ds_usize_t const size,
49 /// ds_predicate_char_t const is_allowed)
50 /// {
51 /// ds_usize_t count = DS_USIZE_MIN;
52 /// for (ds_usize_t i = DS_USIZE_MIN; i < size; i++)
53 /// {
54 /// if (is_allowed (cstr[i]))
55 /// {
56 /// count++;
57 /// }
58 /// }
59 /// return count;
60 /// }
61 ///
62 /// assert (count_only_allowed ("a1b2c3", 6, ds_char_is_ascii_digit) == 3);
63 /// ```
64 typedef bool (*ds_predicate_char_t) (ds_char_t);
65
66 /// @brief Makes a copy of @p self in its ASCII upper case equivalent.
67 ///
68 /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters
69 /// are unchanged.
70 ///
71 /// @param self The value to convert.
72 /// @return The ASCII upper case equivalent of @p self.
73 ///
74 /// ### Examples
75 ///
76 /// Basic usage:
77 ///
78 /// ```c
79 /// ds_char_t const ascii = 'a';
80 /// ds_char_t const non_ascii = '❤';
81 ///
82 /// assert ('A' == ds_char_to_ascii_uppercase (ascii));
83 /// assert ('❤' == ds_char_to_ascii_uppercase (non_ascii));
84 /// ```
86
87 /// @brief Makes a copy of @p self in its ASCII lower case equivalent.
88 ///
89 /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters
90 /// are unchanged.
91 ///
92 /// @param self The value to convert.
93 /// @return The ASCII lower case equivalent of @p self.
94 ///
95 /// ### Examples
96 ///
97 /// Basic usage:
98 ///
99 /// ```c
100 /// ds_char_t const ascii = 'A';
101 /// ds_char_t const non_ascii = '❤';
102 ///
103 /// assert ('a' == ds_char_to_ascii_lowercase (ascii));
104 /// assert ('❤' == ds_char_to_ascii_lowercase (non_ascii));
105 /// ```
107
108 /// @brief Checks that @p self and @p other are an ASCII case-insensitive
109 /// match.
110 ///
111 /// Equivalent to:
112 ///
113 /// ```c
114 /// ds_char_to_ascii_lowercase (self) == ds_char_to_ascii_lowercase (other);
115 /// ```
116 ///
117 /// @param self The first value to compare.
118 /// @param other The second value to compare.
119 /// @return `true` if @p self and @p other are an ASCII case-insensitive
120 /// match, and `false` otherwise.
121 ///
122 /// ### Examples
123 ///
124 /// Basic usage:
125 ///
126 /// ```c
127 /// ds_char_t const upper_a = 'A';
128 /// ds_char_t const lower_a = 'a';
129 /// ds_char_t const lower_z = 'z';
130 ///
131 /// assert (ds_char_eq_ignore_ascii_case (upper_a, lower_a));
132 /// assert (ds_char_eq_ignore_ascii_case (upper_a, upper_a));
133 /// assert (!ds_char_eq_ignore_ascii_case (upper_a, lower_z));
134 /// ```
135 extern bool ds_char_eq_ignore_ascii_case (ds_char_t self, ds_char_t other);
136
137 /// @brief Checks if @p self is an ASCII alphabetic character:
138 ///
139 /// - U+0041 'A' ..= U+005A 'Z', or
140 /// - U+0061 'a' ..= U+007A 'z'.
141 ///
142 /// @param self The value to check.
143 /// @return `true` if @p self is an ASCII alphabetic character, `false`
144 /// otherwise.
145 ///
146 /// ### Examples
147 ///
148 /// Basic usage:
149 ///
150 /// ```c
151 /// ds_char_t const uppercase_a = 'A';
152 /// ds_char_t const uppercase_g = 'G';
153 /// ds_char_t const a = 'a';
154 /// ds_char_t const g = 'g';
155 /// ds_char_t const zero = '0';
156 /// ds_char_t const percent = '%';
157 /// ds_char_t const space = ' ';
158 /// ds_char_t const lf = DS_CHAR_LF;
159 /// ds_char_t const esc = DS_CHAR_ESC;
160 ///
161 /// assert (ds_char_is_ascii_alphabetic (uppercase_a));
162 /// assert (ds_char_is_ascii_alphabetic (uppercase_g));
163 /// assert (ds_char_is_ascii_alphabetic (a));
164 /// assert (ds_char_is_ascii_alphabetic (g));
165 /// assert (!ds_char_is_ascii_alphabetic (zero));
166 /// assert (!ds_char_is_ascii_alphabetic (percent));
167 /// assert (!ds_char_is_ascii_alphabetic (space));
168 /// assert (!ds_char_is_ascii_alphabetic (lf));
169 /// assert (!ds_char_is_ascii_alphabetic (esc));
170 /// ```
171 extern bool ds_char_is_ascii_alphabetic (ds_char_t self);
172
173 /// @brief Checks if @p self is an ASCII uppercase character:
174 ///
175 /// - U+0041 'A' ..= U+005A 'Z'.
176 ///
177 /// @param self The value to check.
178 /// @return `true` if @p self is an ASCII uppercase character, `false`
179 /// otherwise.
180 ///
181 /// ### Examples
182 ///
183 /// Basic usage:
184 ///
185 /// ```c
186 /// ds_char_t const uppercase_a = 'A';
187 /// ds_char_t const uppercase_g = 'G';
188 /// ds_char_t const a = 'a';
189 /// ds_char_t const g = 'g';
190 /// ds_char_t const zero = '0';
191 /// ds_char_t const percent = '%';
192 /// ds_char_t const space = ' ';
193 /// ds_char_t const lf = DS_CHAR_LF;
194 /// ds_char_t const esc = DS_CHAR_ESC;
195 ///
196 /// assert (ds_char_is_ascii_uppercase (uppercase_a));
197 /// assert (ds_char_is_ascii_uppercase (uppercase_g));
198 /// assert (!ds_char_is_ascii_uppercase (a));
199 /// assert (!ds_char_is_ascii_uppercase (g));
200 /// assert (!ds_char_is_ascii_uppercase (zero));
201 /// assert (!ds_char_is_ascii_uppercase (percent));
202 /// assert (!ds_char_is_ascii_uppercase (space));
203 /// assert (!ds_char_is_ascii_uppercase (lf));
204 /// assert (!ds_char_is_ascii_uppercase (esc));
205 /// ```
206 extern bool ds_char_is_ascii_uppercase (ds_char_t self);
207
208 /// @brief Checks if @p self is an ASCII lowercase character:
209 ///
210 /// - U+0061 'a' ..= U+007A 'z'.
211 ///
212 /// @param self The value to check.
213 /// @return `true` if @p self is an ASCII lowercase character, `false`
214 /// otherwise.
215 ///
216 /// ### Examples
217 ///
218 /// Basic usage:
219 ///
220 /// ```c
221 /// ds_char_t const uppercase_a = 'A';
222 /// ds_char_t const uppercase_g = 'G';
223 /// ds_char_t const a = 'a';
224 /// ds_char_t const g = 'g';
225 /// ds_char_t const zero = '0';
226 /// ds_char_t const percent = '%';
227 /// ds_char_t const space = ' ';
228 /// ds_char_t const lf = DS_CHAR_LF;
229 /// ds_char_t const esc = DS_CHAR_ESC;
230 ///
231 /// assert (!ds_char_is_ascii_lowercase (uppercase_a));
232 /// assert (!ds_char_is_ascii_lowercase (uppercase_g));
233 /// assert (ds_char_is_ascii_lowercase (a));
234 /// assert (ds_char_is_ascii_lowercase (g));
235 /// assert (!ds_char_is_ascii_lowercase (zero));
236 /// assert (!ds_char_is_ascii_lowercase (percent));
237 /// assert (!ds_char_is_ascii_lowercase (space));
238 /// assert (!ds_char_is_ascii_lowercase (lf));
239 /// assert (!ds_char_is_ascii_lowercase (esc));
240 /// ```
241 extern bool ds_char_is_ascii_lowercase (ds_char_t self);
242
243 /// @brief Checks if @p self is an ASCII alphanumeric character:
244 ///
245 /// - U+0041 'A' ..= U+005A 'Z', or
246 /// - U+0061 'a' ..= U+007A 'z', or
247 /// - U+0030 '0' ..= U+0039 '9'.
248 ///
249 /// @param self The value to check.
250 /// @return `true` if @p self is an ASCII alphanumeric character, `false`
251 /// otherwise.
252 ///
253 /// ### Examples
254 ///
255 /// Basic usage:
256 ///
257 /// ```c
258 /// ds_char_t const uppercase_a = 'A';
259 /// ds_char_t const uppercase_g = 'G';
260 /// ds_char_t const a = 'a';
261 /// ds_char_t const g = 'g';
262 /// ds_char_t const zero = '0';
263 /// ds_char_t const percent = '%';
264 /// ds_char_t const space = ' ';
265 /// ds_char_t const lf = DS_CHAR_LF;
266 /// ds_char_t const esc = DS_CHAR_ESC;
267 ///
268 /// assert (ds_char_is_ascii_alphanumeric (uppercase_a));
269 /// assert (ds_char_is_ascii_alphanumeric (uppercase_g));
270 /// assert (ds_char_is_ascii_alphanumeric (a));
271 /// assert (ds_char_is_ascii_alphanumeric (g));
272 /// assert (ds_char_is_ascii_alphanumeric (zero));
273 /// assert (!ds_char_is_ascii_alphanumeric (percent));
274 /// assert (!ds_char_is_ascii_alphanumeric (space));
275 /// assert (!ds_char_is_ascii_alphanumeric (lf));
276 /// assert (!ds_char_is_ascii_alphanumeric (esc));
277 /// ```
278 extern bool ds_char_is_ascii_alphanumeric (ds_char_t self);
279
280 /// @brief Checks if @p self is an ASCII decimal digit:
281 ///
282 /// - U+0030 '0' ..= U+0039 '9'.
283 ///
284 /// @param self The value to check.
285 /// @return `true` if @p self is an ASCII decimal digit, and `false`
286 /// otherwise.
287 ///
288 /// ### Examples
289 ///
290 /// Basic usage:
291 ///
292 /// ```c
293 /// ds_char_t const uppercase_a = 'A';
294 /// ds_char_t const uppercase_g = 'G';
295 /// ds_char_t const a = 'a';
296 /// ds_char_t const g = 'g';
297 /// ds_char_t const zero = '0';
298 /// ds_char_t const percent = '%';
299 /// ds_char_t const space = ' ';
300 /// ds_char_t const lf = DS_CHAR_LF;
301 /// ds_char_t const esc = DS_CHAR_ESC;
302 ///
303 /// assert (!ds_char_is_ascii_digit (uppercase_a));
304 /// assert (!ds_char_is_ascii_digit (uppercase_g));
305 /// assert (!ds_char_is_ascii_digit (a));
306 /// assert (!ds_char_is_ascii_digit (g));
307 /// assert (ds_char_is_ascii_digit (zero));
308 /// assert (!ds_char_is_ascii_digit (percent));
309 /// assert (!ds_char_is_ascii_digit (space));
310 /// assert (!ds_char_is_ascii_digit (lf));
311 /// assert (!ds_char_is_ascii_digit (esc));
312 /// ```
313 extern bool ds_char_is_ascii_digit (ds_char_t self);
314
315 /// @brief Checks if @p self is an ASCII octal digit:
316 ///
317 /// - U+0030 '0' ..= U+0037 '7'.
318 ///
319 /// @param self The value to check.
320 /// @return `true` if @p self is an ASCII octal digit, and `false` otherwise.
321 ///
322 /// ### Examples
323 ///
324 /// Basic usage:
325 ///
326 /// ```c
327 /// ds_char_t const uppercase_a = 'A';
328 /// ds_char_t const a = 'a';
329 /// ds_char_t const zero = '0';
330 /// ds_char_t const seven = '7';
331 /// ds_char_t const nine = '9';
332 /// ds_char_t const percent = '%';
333 /// ds_char_t const lf = DS_CHAR_LF;
334 ///
335 /// assert (!ds_char_is_ascii_octdigit (uppercase_a));
336 /// assert (!ds_char_is_ascii_octdigit (a));
337 /// assert (ds_char_is_ascii_octdigit (zero));
338 /// assert (ds_char_is_ascii_octdigit (seven));
339 /// assert (!ds_char_is_ascii_octdigit (nine));
340 /// assert (!ds_char_is_ascii_octdigit (percent));
341 /// assert (!ds_char_is_ascii_octdigit (lf));
342 /// ```
343 extern bool ds_char_is_ascii_octdigit (ds_char_t self);
344
345 /// @brief Checks if @p self is an ASCII hexadecimal digit:
346 ///
347 /// - U+0030 '0' ..= U+0039 '9', or
348 /// - U+0041 'A' ..= U+0046 'F', or
349 /// - U+0061 'a' ..= U+0066 'f'.
350 ///
351 /// @param self The value to check.
352 /// @return `true` if @p self is an ASCII hexadecimal digit, `false`
353 /// otherwise.
354 ///
355 /// ### Examples
356 ///
357 /// Basic usage:
358 ///
359 /// ```c
360 /// ds_char_t const uppercase_a = 'A';
361 /// ds_char_t const uppercase_g = 'G';
362 /// ds_char_t const a = 'a';
363 /// ds_char_t const g = 'g';
364 /// ds_char_t const zero = '0';
365 /// ds_char_t const percent = '%';
366 /// ds_char_t const space = ' ';
367 /// ds_char_t const lf = DS_CHAR_LF;
368 /// ds_char_t const esc = DS_CHAR_ESC;
369 ///
370 /// assert (ds_char_is_ascii_hexdigit (uppercase_a));
371 /// assert (!ds_char_is_ascii_hexdigit (uppercase_g));
372 /// assert (ds_char_is_ascii_hexdigit (a));
373 /// assert (!ds_char_is_ascii_hexdigit (g));
374 /// assert (ds_char_is_ascii_hexdigit (zero));
375 /// assert (!ds_char_is_ascii_hexdigit (percent));
376 /// assert (!ds_char_is_ascii_hexdigit (space));
377 /// assert (!ds_char_is_ascii_hexdigit (lf));
378 /// assert (!ds_char_is_ascii_hexdigit (esc));
379 /// ```
380 extern bool ds_char_is_ascii_hexdigit (ds_char_t self);
381
382 /// @brief Checks if @p self is an ASCII punctuation character:
383 ///
384 /// - U+0021 ..= U+002F ```! " # $ % & ' ( ) * + , - . /```, or
385 /// - U+003A ..= U+0040 ```: ; < = > ? @```, or
386 /// - U+005B ..= U+0060 ```[ \ ] ^ _ ` ```, or
387 /// - U+007B ..= U+007E ```{ | } ~```
388 ///
389 /// @param self The value to check.
390 /// @return `true` if @p self is an ASCII punctuation character, `false`
391 /// otherwise.
392 ///
393 /// ### Examples
394 ///
395 /// Basic usage:
396 ///
397 /// ```c
398 /// ds_char_t const uppercase_a = 'A';
399 /// ds_char_t const uppercase_g = 'G';
400 /// ds_char_t const a = 'a';
401 /// ds_char_t const g = 'g';
402 /// ds_char_t const zero = '0';
403 /// ds_char_t const percent = '%';
404 /// ds_char_t const space = ' ';
405 /// ds_char_t const lf = DS_CHAR_LF;
406 /// ds_char_t const esc = DS_CHAR_ESC;
407 ///
408 /// assert (!ds_char_is_ascii_punctuation (uppercase_a));
409 /// assert (!ds_char_is_ascii_punctuation (uppercase_g));
410 /// assert (!ds_char_is_ascii_punctuation (a));
411 /// assert (!ds_char_is_ascii_punctuation (g));
412 /// assert (!ds_char_is_ascii_punctuation (zero));
413 /// assert (ds_char_is_ascii_punctuation (percent));
414 /// assert (!ds_char_is_ascii_punctuation (space));
415 /// assert (!ds_char_is_ascii_punctuation (lf));
416 /// assert (!ds_char_is_ascii_punctuation (esc));
417 /// ```
418 extern bool ds_char_is_ascii_punctuation (ds_char_t self);
419
420 /// @brief Checks if @p self is an ASCII graphic character:
421 ///
422 /// - U+0021 '!' ..= U+007E '~'.
423 ///
424 /// @param self The value to check.
425 /// @return `true` if @p self is an ASCII graphic character, `false`
426 /// otherwise.
427 ///
428 /// ### Examples
429 ///
430 /// Basic usage:
431 ///
432 /// ```c
433 /// ds_char_t const uppercase_a = 'A';
434 /// ds_char_t const uppercase_g = 'G';
435 /// ds_char_t const a = 'a';
436 /// ds_char_t const g = 'g';
437 /// ds_char_t const zero = '0';
438 /// ds_char_t const percent = '%';
439 /// ds_char_t const space = ' ';
440 /// ds_char_t const lf = DS_CHAR_LF;
441 /// ds_char_t const esc = DS_CHAR_ESC;
442 ///
443 /// assert (ds_char_is_ascii_graphic (uppercase_a));
444 /// assert (ds_char_is_ascii_graphic (uppercase_g));
445 /// assert (ds_char_is_ascii_graphic (a));
446 /// assert (ds_char_is_ascii_graphic (g));
447 /// assert (ds_char_is_ascii_graphic (zero));
448 /// assert (ds_char_is_ascii_graphic (percent));
449 /// assert (!ds_char_is_ascii_graphic (space));
450 /// assert (!ds_char_is_ascii_graphic (lf));
451 /// assert (!ds_char_is_ascii_graphic (esc));
452 /// ```
453 extern bool ds_char_is_ascii_graphic (ds_char_t self);
454
455 /// @brief Checks if @p self is an ASCII whitespace character:
456 ///
457 /// - U+0020 SPACE,
458 /// - U+0009 HORIZONTAL TAB,
459 /// - U+000A LINE FEED,
460 /// - U+000C FORM FEED, or
461 /// - U+000D CARRIAGE RETURN.
462 ///
463 /// `ds` uses the WhatWG Infra Standard's [definition of ASCII
464 /// whitespace][infra-aw]. There are several other definitions in wide use.
465 /// For instance, [the POSIX locale][pct] includes U+000B VERTICAL TAB as
466 /// well as all the above characters, but—from the very same
467 /// specification—[the default rule for "field splitting" in the Bourne
468 /// shell][bfs] considers *only* SPACE, HORIZONTAL TAB, and LINE FEED as
469 /// whitespace.
470 ///
471 /// If you are writing a program that will process an existing file format,
472 /// check what that format's definition of whitespace is before using this
473 /// function.
474 ///
475 /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace
476 /// [pct]:
477 /// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01
478 /// [bfs]:
479 /// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
480 ///
481 /// @param self The value to check.
482 /// @return `true` if @p self is an ASCII whitespace character, `false`
483 /// otherwise.
484 ///
485 /// ### Examples
486 ///
487 /// Basic usage:
488 ///
489 /// ```c
490 /// ds_char_t const uppercase_a = 'A';
491 /// ds_char_t const uppercase_g = 'G';
492 /// ds_char_t const a = 'a';
493 /// ds_char_t const g = 'g';
494 /// ds_char_t const zero = '0';
495 /// ds_char_t const percent = '%';
496 /// ds_char_t const space = ' ';
497 /// ds_char_t const lf = DS_CHAR_LF;
498 /// ds_char_t const esc = DS_CHAR_ESC;
499 ///
500 /// assert (!ds_char_is_ascii_whitespace (uppercase_a));
501 /// assert (!ds_char_is_ascii_whitespace (uppercase_g));
502 /// assert (!ds_char_is_ascii_whitespace (a));
503 /// assert (!ds_char_is_ascii_whitespace (g));
504 /// assert (!ds_char_is_ascii_whitespace (zero));
505 /// assert (!ds_char_is_ascii_whitespace (percent));
506 /// assert (ds_char_is_ascii_whitespace (space));
507 /// assert (ds_char_is_ascii_whitespace (lf));
508 /// assert (!ds_char_is_ascii_whitespace (esc));
509 /// ```
510 extern bool ds_char_is_ascii_whitespace (ds_char_t self);
511
512 /// @brief Checks if @p self is an ASCII control character:
513 ///
514 /// - U+0000 @ref DS_CHAR_NUL "NUL" ..= U+001F UNIT SEPARATOR, or U+007F
515 /// DELETE.
516 ///
517 /// Note that most ASCII whitespace characters are control characters, but
518 /// SPACE is not.
519 ///
520 /// @param self The value to check.
521 /// @return `true` if @p self is an ASCII control character, `false`
522 /// otherwise.
523 ///
524 /// ### Examples
525 ///
526 /// Basic usage:
527 ///
528 /// ```c
529 /// ds_char_t const uppercase_a = 'A';
530 /// ds_char_t const uppercase_g = 'G';
531 /// ds_char_t const a = 'a';
532 /// ds_char_t const g = 'g';
533 /// ds_char_t const zero = '0';
534 /// ds_char_t const percent = '%';
535 /// ds_char_t const space = ' ';
536 /// ds_char_t const lf = DS_CHAR_LF;
537 /// ds_char_t const esc = DS_CHAR_ESC;
538 ///
539 /// assert (!ds_char_is_ascii_control (uppercase_a));
540 /// assert (!ds_char_is_ascii_control (uppercase_g));
541 /// assert (!ds_char_is_ascii_control (a));
542 /// assert (!ds_char_is_ascii_control (g));
543 /// assert (!ds_char_is_ascii_control (zero));
544 /// assert (!ds_char_is_ascii_control (percent));
545 /// assert (!ds_char_is_ascii_control (space));
546 /// assert (ds_char_is_ascii_control (lf));
547 /// assert (ds_char_is_ascii_control (esc));
548 /// ```
549 extern bool ds_char_is_ascii_control (ds_char_t self);
550
551/// @brief The size of @ref ds_char_t "char" in bytes.
552///
553/// ### Examples
554///
555/// Basic usage:
556///
557/// ```c
558/// assert (DS_CHAR_BYTES == 1);
559/// ```
560#define DS_CHAR_BYTES ((ds_usize_t)sizeof (ds_char_t))
561
562/// @brief The smallest value that can be represented by @ref ds_char_t "char".
563///
564/// ### Examples
565///
566/// Basic usage:
567///
568/// ```c
569/// assert (DS_CHAR_MIN == CHAR_MIN);
570/// ```
571#define DS_CHAR_MIN ((ds_char_t)CHAR_MIN)
572
573/// @brief The largest value that can be represented by @ref ds_char_t "char".
574///
575/// ### Examples
576///
577/// Basic usage:
578///
579/// ```c
580/// assert (DS_CHAR_MAX == CHAR_MAX);
581/// ```
582#define DS_CHAR_MAX ((ds_char_t)CHAR_MAX)
583
584/// @brief The null character.
585///
586/// ### Examples
587///
588/// Basic usage:
589///
590/// ```c
591/// assert (DS_CHAR_NUL == '\0');
592/// ```
593#define DS_CHAR_NUL ((ds_char_t)0x00)
594
595/// @brief The bell character.
596///
597/// ### Examples
598///
599/// Basic usage:
600///
601/// ```c
602/// assert (DS_CHAR_BEL == '\x07');
603/// ```
604#define DS_CHAR_BEL ((ds_char_t)0x07)
605
606/// @brief The backspace character.
607///
608/// ### Examples
609///
610/// Basic usage:
611///
612/// ```c
613/// assert (DS_CHAR_BS == '\b');
614/// ```
615#define DS_CHAR_BS ((ds_char_t)0x08)
616
617/// @brief The horizontal-tab character.
618///
619/// ### Examples
620///
621/// Basic usage:
622///
623/// ```c
624/// assert (DS_CHAR_HT == '\t');
625/// ```
626#define DS_CHAR_HT ((ds_char_t)0x09)
627
628/// @brief The line-feed character.
629///
630/// ### Examples
631///
632/// Basic usage:
633///
634/// ```c
635/// assert (DS_CHAR_LF == '\n');
636/// ```
637#define DS_CHAR_LF ((ds_char_t)0x0A)
638
639/// @brief The vertical-tab character.
640///
641/// ### Examples
642///
643/// Basic usage:
644///
645/// ```c
646/// assert (DS_CHAR_VT == '\v');
647/// ```
648#define DS_CHAR_VT ((ds_char_t)0x0B)
649
650/// @brief The form-feed character.
651///
652/// ### Examples
653///
654/// Basic usage:
655///
656/// ```c
657/// assert (DS_CHAR_FF == '\f');
658/// ```
659#define DS_CHAR_FF ((ds_char_t)0x0C)
660
661/// @brief The carriage-return character.
662///
663/// ### Examples
664///
665/// Basic usage:
666///
667/// ```c
668/// assert (DS_CHAR_CR == '\r');
669/// ```
670#define DS_CHAR_CR ((ds_char_t)0x0D)
671
672/// @brief The escape character.
673///
674/// ### Examples
675///
676/// Basic usage:
677///
678/// ```c
679/// assert (DS_CHAR_ESC == '\x1B');
680/// ```
681#define DS_CHAR_ESC ((ds_char_t)0x1B)
682
683/// @brief The unit-separator character.
684///
685/// ### Examples
686///
687/// Basic usage:
688///
689/// ```c
690/// assert (DS_CHAR_US == '\x1F');
691/// ```
692#define DS_CHAR_US ((ds_char_t)0x1F)
693
694/// @brief The delete character.
695///
696/// ### Examples
697///
698/// Basic usage:
699///
700/// ```c
701/// assert (DS_CHAR_DEL == '\x7F');
702/// ```
703#define DS_CHAR_DEL ((ds_char_t)0x7F)
704
705/// @brief @ref ds_char_t "char" notation. Can be used in `scanf` to parse and
706/// read @ref ds_char_t "char" values.
707///
708/// @warning It is strongly advised to use
709/// [`fgets`](https://en.cppreference.com/w/c/io/fgets "fgets -
710/// cppreference.com") instead of `scanf` to read input.
711///
712/// ### Examples
713///
714/// Basic usage:
715///
716/// ```c
717/// ds_char_t x;
718/// scanf ("%" DS_SCN_CHAR, &x);
719/// ```
720#define DS_SCN_CHAR "c"
721
722/// @brief @ref ds_char_t "char" notation. Can be used in `printf` to format
723/// and write @ref ds_char_t "char" values.
724///
725/// ### Examples
726///
727/// Basic usage:
728///
729/// ```c
730/// ds_char_t const x = DS_CHAR_MAX;
731/// printf ("%" DS_PRI_CHAR, x);
732/// ```
733#define DS_PRI_CHAR "c"
734
735#ifdef __cplusplus
736}
737#endif /* __cplusplus */
738
739#endif /* DS_CHAR_H */
bool ds_char_is_ascii_hexdigit(ds_char_t self)
Checks if self is an ASCII hexadecimal digit:
Definition: char.c:90
bool ds_char_is_ascii_control(ds_char_t self)
Checks if self is an ASCII control character:
Definition: char.c:120
char ds_char_t
A character type.
Definition: char.h:30
bool(* ds_predicate_char_t)(ds_char_t)
A function pointer type for char predicate functions that return true or false depending on the passe...
Definition: char.h:64
bool ds_char_is_ascii_digit(ds_char_t self)
Checks if self is an ASCII decimal digit:
Definition: char.c:78
bool ds_char_is_ascii_uppercase(ds_char_t self)
Checks if self is an ASCII uppercase character:
Definition: char.c:60
ds_char_t ds_char_to_ascii_lowercase(ds_char_t self)
Makes a copy of self in its ASCII lower case equivalent.
Definition: char.c:38
bool ds_char_eq_ignore_ascii_case(ds_char_t self, ds_char_t other)
Checks that self and other are an ASCII case-insensitive match.
Definition: char.c:46
bool ds_char_is_ascii_lowercase(ds_char_t self)
Checks if self is an ASCII lowercase character:
Definition: char.c:66
bool ds_char_is_ascii_alphanumeric(ds_char_t self)
Checks if self is an ASCII alphanumeric character:
Definition: char.c:72
bool ds_char_is_ascii_punctuation(ds_char_t self)
Checks if self is an ASCII punctuation character:
Definition: char.c:98
bool ds_char_is_ascii_alphabetic(ds_char_t self)
Checks if self is an ASCII alphabetic character:
Definition: char.c:53
ds_char_t ds_char_to_ascii_uppercase(ds_char_t self)
Makes a copy of self in its ASCII upper case equivalent.
Definition: char.c:30
bool ds_char_is_ascii_graphic(ds_char_t self)
Checks if self is an ASCII graphic character:
Definition: char.c:107
bool ds_char_is_ascii_whitespace(ds_char_t self)
Checks if self is an ASCII whitespace character:
Definition: char.c:113
bool ds_char_is_ascii_octdigit(ds_char_t self)
Checks if self is an ASCII octal digit:
Definition: char.c:84
Declaration of the usize type, related constants and functions.