UTF-8 rune (Unicode code point) methods. More...
|
Data Structures | |
| struct | sys_rune_tokenize_t |
| Tokenizer state, grouping a stream into maximal runs of same-class runes. More... | |
Macros | |
| #define | RUNE_ERROR ((rune_t)0xFFFD) |
| Sentinel value for a malformed UTF-8 sequence. More... | |
Typedefs | |
| typedef struct sys_rune_tokenize_t | sys_rune_tokenize_t |
| Tokenizer state, grouping a stream into maximal runs of same-class runes. More... | |
Enumerations | |
| enum | sys_rune_class_t { sys_rune_other = 0, sys_rune_space, sys_rune_digit, sys_rune_alpha, sys_rune_punct, sys_rune_symbol, sys_rune_control } |
| Classification of a rune, or of a maximal run of same-class runes. More... | |
Functions | |
| const char * | sys_rune_next (const char *str, rune_t *rune) |
| Decode the next UTF-8 rune from a string. More... | |
| size_t | sys_rune_count (const char *str) |
| Count the runes in a UTF-8 string. More... | |
| bool | sys_rune_valid (const char *str) |
| Check whether a string is well-formed UTF-8. More... | |
| static bool | sys_rune_is_digit (rune_t r) |
| Reports whether r is a decimal digit. | |
| static bool | sys_rune_is_space (rune_t r) |
| Reports whether r is a space character (space, \t, \n, \v, \f, \r, U+0085 NEL, or U+00A0 NBSP). | |
| static bool | sys_rune_is_upper (rune_t r) |
| Reports whether r is an uppercase letter. | |
| static bool | sys_rune_is_lower (rune_t r) |
| Reports whether r is a lowercase letter. | |
| static bool | sys_rune_is_alpha (rune_t r) |
| Reports whether r is a letter. | |
| static rune_t | sys_rune_to_upper (rune_t r) |
| Converts r to its uppercase form, if it has one. More... | |
| static rune_t | sys_rune_to_lower (rune_t r) |
| Converts r to its lowercase form, if it has one. More... | |
| static bool | sys_rune_is_punct (rune_t r) |
| Reports whether r is a punctuation character. More... | |
| static bool | sys_rune_is_symbol (rune_t r) |
| Reports whether r is a symbol character (math, currency, or modifier symbols). More... | |
| static bool | sys_rune_is_control (rune_t r) |
| Reports whether r is a control character. | |
| sys_rune_class_t | sys_rune_isa (rune_t r) |
| Classify a single rune. More... | |
| sys_rune_tokenize_t | sys_rune_tokenize_init (sys_iostream_t *stream) |
| Initialize a tokenizer over a stream. More... | |
| bool | sys_rune_tokenize_next (sys_rune_tokenize_t *it) |
| Advance to the next maximal run of same-class runes. More... | |
| size_t | sys_rune_tokenize_token (sys_rune_tokenize_t *it, char *buf, size_t cap) |
| Read the current token's text. More... | |
UTF-8 rune (Unicode code point) methods.
| #define RUNE_ERROR ((rune_t)0xFFFD) |
Sentinel value for a malformed UTF-8 sequence.
This is the Unicode replacement character (U+FFFD), returned in rune when the bytes at the current position do not form a valid UTF-8 sequence. The returned pointer still advances (past the offending byte), so iteration can continue.
| typedef struct sys_rune_tokenize_t sys_rune_tokenize_t |
Tokenizer state, grouping a stream into maximal runs of same-class runes.
Reads from the sys_iostream_t given to sys_rune_tokenize_init(). Records only where the current token starts and how long it is - the tokenizer itself never allocates or limits a token's length (whether that holds for the stream as a whole depends on its backend). Use sys_rune_tokenize_token() to read its actual text.
| enum sys_rune_class_t |
Classification of a rune, or of a maximal run of same-class runes.
| Enumerator | |
|---|---|
| sys_rune_other | unclassified - also covers RUNE_ERROR |
| sys_rune_space | |
| sys_rune_digit | |
| sys_rune_alpha | |
| sys_rune_punct | |
| sys_rune_symbol | |
| sys_rune_control | |
Definition at line 303 of file rune.h.
| size_t sys_rune_count | ( | const char * | str | ) |
Count the runes in a UTF-8 string.
| str | Pointer to a null-terminated UTF-8 string, or NULL. |
str is NULL or empty. Use sys_rune_valid() to check well-formedness.
|
inlinestatic |
Reports whether r is a punctuation character.
Follows Unicode's Punctuation category, not the C locale's broader ispunct() - math/currency/modifier symbols are sys_rune_is_symbol() instead.
Definition at line 202 of file rune.h.
|
inlinestatic |
Reports whether r is a symbol character (math, currency, or modifier symbols).
The complement of sys_rune_is_punct() within the printable ASCII/Latin-1 range - together they partition it.
Definition at line 246 of file rune.h.
| sys_rune_class_t sys_rune_isa | ( | rune_t | r | ) |
Classify a single rune.
| r | The rune to classify. |
| const char* sys_rune_next | ( | const char * | str, |
| rune_t * | rune | ||
| ) |
Decode the next UTF-8 rune from a string.
| str | Pointer to a null-terminated UTF-8 string. |
| rune | Pointer to store the decoded rune. Set to RUNE_ERROR on a malformed sequence, or 0 if the string is exhausted. |
str for the next call), or NULL once the string is exhausted. On a malformed sequence, the pointer still advances - by exactly one byte - so a decode loop can keep going after an error. Converts r to its lowercase form, if it has one.
| r | The rune to convert. |
Converts r to its uppercase form, if it has one.
| r | The rune to convert. |
| sys_rune_tokenize_t sys_rune_tokenize_init | ( | sys_iostream_t * | stream | ) |
Initialize a tokenizer over a stream.
| stream | The stream to read runes from, or NULL. |
| bool sys_rune_tokenize_next | ( | sys_rune_tokenize_t * | it | ) |
Advance to the next maximal run of same-class runes.
| it | Pointer to the tokenizer state. |
| size_t sys_rune_tokenize_token | ( | sys_rune_tokenize_t * | it, |
| char * | buf, | ||
| size_t | cap | ||
| ) |
Read the current token's text.
| it | The tokenizer, positioned at a token by a prior successful sys_rune_tokenize_next() call. |
| buf | Destination buffer. |
| cap | Capacity of buf. |
| bool sys_rune_valid | ( | const char * | str | ) |
Check whether a string is well-formed UTF-8.
| str | Pointer to a null-terminated UTF-8 string, or NULL. |
str is NULL or empty; false if any malformed sequence is found.