sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 2ef3b978a054511b316073c2f05efb777dfcca20
родитељ f46fa9dce6c1e331b19825dac3c1b3fb7c2a7ae3
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Mon, 16 Sep 2024 18:39:39 +0200

util.c(u32_strchr,u32_is_word_boundary): Avoid wide string literals

Diffstat:
Mutil.c | 25++++++++++++++++++-------
измењених датотека: 1, додавања: 18(+), брисања: 7(-)

diff --git a/util.c b/util.c @@ -12,6 +12,11 @@ #include "termbox.h" #include "util.h" +/* Whitespace definition for determining word boundaries */ +#define B_WS " \v\t" +/* Full word boundary delimiter definition */ +#define B_FULL " \v\t()[]{},.;:/\\" + size_t u8_string_to_unicode(uint32_t* us, const char* s, const size_t max) { @@ -81,7 +86,7 @@ uint32_t* u32_memccpy(uint32_t* dst, const uint32_t* src, uint32_t c, size_t len) { size_t copied = 0; - assert ((dst != NULL) && (src != NULL)); + assert((dst != NULL) && (src != NULL)); while ((*dst++ = *src++) != c && copied < len) copied++; if (copied == len) @@ -98,7 +103,7 @@ u32_u8_memccpy(uint32_t* dst, const char* src, uint32_t c, size_t len) size_t copied = 0; int u8_len; - assert ((dst != NULL) && (src != NULL)); + assert((dst != NULL) && (src != NULL)); do { if (!*psrc) @@ -206,16 +211,22 @@ u32_strchr(const uint32_t* haystack, const uint32_t needle) int is_word_boundary(const char ch, const int strictly_whitespace) { - return strictly_whitespace ? strchr(" \v\t", ch) != NULL - : strchr(" \v\t()[]{},.;:/\\", ch) != NULL; + return strictly_whitespace ? strchr(B_WS, ch) != NULL + : strchr(B_FULL, ch) != NULL; } int u32_is_word_boundary(const uint32_t ch, const int strictly_whitespace) { - return strictly_whitespace - ? u32_strchr((uint32_t*)L" \v\t", ch) != NULL - : u32_strchr((uint32_t*)L" \v\t()[]{},.;:/\\", ch) != NULL; + static uint32_t uws[sizeof(B_WS) + 1]; + static uint32_t ufull[sizeof(B_FULL) + 1]; + if (!*uws) + { + (void)u8_string_to_unicode(uws, B_WS, sizeof(B_WS)); + (void)u8_string_to_unicode(ufull, B_FULL, sizeof(B_FULL)); + } + return strictly_whitespace ? u32_strchr(uws, ch) != NULL + : u32_strchr(ufull, ch) != NULL; } int