Skip to content

Commit

Permalink
make uppercase detection Unicode-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker committed Aug 15, 2017
1 parent ddd692b commit b8685fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/tig/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Strings.
*/

bool string_contains_uppercase(const char *search);

#define prefixcmp(str1, str2) \
strncmp(str1, str2, STRING_SIZE(str2))

Expand Down
12 changes: 1 addition & 11 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,14 @@ 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)
{
int regex_err;
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) {
Expand Down
26 changes: 26 additions & 0 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit b8685fc

Please sign in to comment.