diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-04-19 22:51:33 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-04-19 22:53:35 -0400 |
commit | da61efabb1b28c5500824a560c960a720a628de0 (patch) | |
tree | 618127733dd0a2923536f52b920671723e6471db /string32.c | |
parent | 61cd687d858b7a3811a168393f6b698c24cfff17 (diff) |
markdown highlighting
Diffstat (limited to 'string32.c')
-rw-r--r-- | string32.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -148,6 +148,25 @@ size_t str32_remove_all_instances_of_char(String32 *s, char32_t c) { return ndeleted; } +// returns the length of the longest prefix of `s` containing only +// ASCII characters in the C-string `charset`. +size_t str32_ascii_spn(String32 s, char const *charset) { + for (u32 i = 0; i < s.len; ++i) { + if (s.str[i] >= 128) + return i; // non-ASCII character in s, so that can't be in charset. + bool found = false; + for (char const *p = charset; *p; ++p) { + assert((char32_t)*p < 128); + if ((char32_t)*p == s.str[i]) { + found = true; + break; + } + } + if (!found) return i; + } + return s.len; +} + bool is32_space(char32_t c) { return c <= WINT_MAX && iswspace((wint_t)c); } |