poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 0fbf8799eef35bd6cf8eb4b71150681853269620
родитељ d09df483f3ce8a2a461f1a485e60b27beec12fc3
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Wed, 22 Jun 2022 17:01:32 +0200

Fix word boundary detection, add const to declarations

Signed-off-by: Страхиња Радић <contact@strahinja.org>

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

diff --git a/util.c b/util.c @@ -219,10 +219,10 @@ u32_strlen(const uint32_t* s) return len; } -uint32_t* -u32_strstr(uint32_t* haystack, const uint32_t* needle) +const uint32_t* +u32_strstr(const uint32_t* haystack, const uint32_t* needle) { - uint32_t* ph = haystack; + const uint32_t* ph = haystack; while (*ph) { if (u32_starts_with(ph, needle)) @@ -232,10 +232,10 @@ u32_strstr(uint32_t* haystack, const uint32_t* needle) return NULL; } -uint32_t* -u32_strchr(uint32_t* haystack, const uint32_t needle) +const uint32_t* +u32_strchr(const uint32_t* haystack, const uint32_t needle) { - uint32_t* ph = haystack; + const uint32_t* ph = haystack; while (*ph) { if (*ph == needle) @@ -406,15 +406,14 @@ u32_next_line(const uint32_t* s, const uint32_t** next_line, return result; } -int -u32_is_word_boundary(const uint32_t ch, const int strictly_whitespace) +const int +is_word_boundary(const char 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; + return strictly_whitespace ? strchr(" \v\t", ch) != NULL + : strchr(" \v\t()[]{},.;:/\\", ch) != NULL; } -int +const int starts_with(const char* s, const char* with) { while (*s && *s == *with) @@ -427,7 +426,7 @@ starts_with(const char* s, const char* with) return *with == 0; } -int +const int u32_starts_with(const uint32_t* s, const uint32_t* with) { while (*s && *s == *with) diff --git a/util.h b/util.h @@ -26,6 +26,8 @@ enum { #define MAXPATH 1024 /* maximum chars for UTF-8 representations of Unicode chars, per Unicode char */ #define UTF8REPMAX 6 +#define u32_is_word_boundary(ch, strictly_whitespace) \ + (is_word_boundary((char)(ch), strictly_whitespace)) size_t u8_string_to_unicode(uint32_t* us, const char* s, const size_t max); size_t unicode_string_to_u8(char* s, const uint32_t* us, const size_t max); @@ -36,8 +38,8 @@ size_t u32_count_strings(const uint32_t* haystack, const uint32_t* needle); size_t u32_encode_tabs(uint32_t* s, size_t max); size_t u32_decode_tabs(uint32_t* s, size_t max); size_t u32_strlen(const uint32_t* s); -uint32_t* u32_strstr(uint32_t* haystack, const uint32_t* needle); -uint32_t* u32_strchr(uint32_t* haystack, const uint32_t needle); +const uint32_t* u32_strstr(const uint32_t* haystack, const uint32_t* needle); +const uint32_t* u32_strchr(const uint32_t* haystack, const uint32_t needle); size_t u32_strcpy(uint32_t* to, const uint32_t* from); size_t u32_strncpy(uint32_t* to, const uint32_t* from, size_t max); size_t u32_strncat(uint32_t* to, const uint32_t* from, size_t max); @@ -47,8 +49,8 @@ size_t u32_lines_in_string(const uint32_t* s, const int include_eol, const size_t wrap); size_t u32_next_line(const uint32_t* s, const uint32_t** sptr, const int include_eol, const size_t wrap); -int u32_is_word_boundary(const uint32_t ch, const int strictly_whitespace); -int starts_with(const char* s, const char* with); -int u32_starts_with(const uint32_t* s, const uint32_t* with); +const int is_word_boundary(const char ch, const int strictly_whitespace); +const int starts_with(const char* s, const char* with); +const int u32_starts_with(const uint32_t* s, const uint32_t* with); const char* u8_basename(const char* path); void poe_log(const char* msg, ...);