[strings] fix lowercasing in string_utils.c

This commit is contained in:
Al
2017-01-01 20:08:32 -05:00
parent a78937f265
commit 4ad3a52fe1
2 changed files with 13 additions and 6 deletions

View File

@@ -206,15 +206,22 @@ char *utf8_case(const char *s, casing_option_t casing, utf8proc_option_t options
} else if (casing == UTF8_UPPER) { } else if (casing == UTF8_UPPER) {
norm = utf8proc_toupper(uc); norm = utf8proc_toupper(uc);
} }
buffer[i] = norm;
} }
result = utf8proc_reencode(buffer, result, options); result = utf8proc_reencode(buffer, result, options);
if (result < 0) {
free(buffer);
return NULL;
}
utf8proc_int32_t *newptr; utf8proc_int32_t *newptr = (utf8proc_int32_t *) realloc(buffer, (size_t)result+1);
newptr = (utf8proc_int32_t *) realloc(buffer, (size_t)result+1); if (newptr != NULL) {
if (newptr) buffer = newptr; buffer = newptr;
} else {
free(buffer); free(buffer);
return NULL;
}
return (char *)buffer; return (char *)buffer;
} }

View File

@@ -41,7 +41,7 @@ Utilities for manipulating strings in C.
#define UTF8PROC_OPTIONS_STRIP_ACCENTS UTF8PROC_OPTIONS_BASE | UTF8PROC_DECOMPOSE | UTF8PROC_STRIPMARK #define UTF8PROC_OPTIONS_STRIP_ACCENTS UTF8PROC_OPTIONS_BASE | UTF8PROC_DECOMPOSE | UTF8PROC_STRIPMARK
// Lowercase // Lowercase
#define UTF8PROC_OPTIONS_LOWERCASE UTF8PROC_OPTIONS_BASE | UTF8PROC_CASEFOLD #define UTF8PROC_OPTIONS_CASE_FOLD UTF8PROC_OPTIONS_BASE | UTF8PROC_CASEFOLD
// ASCII string methods // ASCII string methods