From b8685fc5df2e8691ea6073b0bbdcf32a6833f90e Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 12 Aug 2017 09:09:37 -0400 Subject: [PATCH] make uppercase detection Unicode-aware --- include/tig/string.h | 2 ++ src/search.c | 12 +----------- src/string.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/tig/string.h b/include/tig/string.h index 08cece548..509082bc9 100644 --- a/include/tig/string.h +++ b/include/tig/string.h @@ -21,6 +21,8 @@ * Strings. */ +bool string_contains_uppercase(const char *search); + #define prefixcmp(str1, str2) \ strncmp(str1, str2, STRING_SIZE(str2)) diff --git a/src/search.c b/src/search.c index fa9797be1..f3375abe4 100644 --- a/src/search.c +++ b/src/search.c @@ -57,16 +57,6 @@ find_matches(struct view *view) static enum status_code find_next_match(struct view *view, enum request request); -static bool contains_uppercase(const char *search) -{ - const char *c = search; - for (; *c != '\0'; ++c) { - if (isupper(*c)) - return true; - } - return false; -} - static enum status_code setup_and_find_next(struct view *view, enum request request) { @@ -74,7 +64,7 @@ setup_and_find_next(struct view *view, enum request request) int regex_flags = opt_ignore_case == IGNORE_CASE_YES ? REG_ICASE : 0; if (opt_ignore_case == IGNORE_CASE_SMART_CASE - && !contains_uppercase(view->env->search)) + && !string_contains_uppercase(view->env->search)) regex_flags |= REG_ICASE; if (view->regex) { diff --git a/src/string.c b/src/string.c index 1ef352d91..a4d5b04f3 100644 --- a/src/string.c +++ b/src/string.c @@ -19,6 +19,32 @@ * Strings. */ +#ifdef HAVE_ICU +bool string_contains_uppercase(const char *search) +{ + int32_t i; + int32_t len = strlen(search); + UChar32 c; + + for(i = 0; i < len;) { + U8_NEXT(search, i, len, c); + if (u_isUUppercase(c)) + return true; + } + return false; +} +#else +bool string_contains_uppercase(const char *search) +{ + const char *c = search; + for (; *c != '\0'; ++c) { + if (isupper(*c)) + return true; + } + return false; +} +#endif + bool string_isnumber(const char *str) {