diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-utf8.c | 35 | ||||
-rw-r--r-- | src/core/wee-utf8.h | 1 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index bae3693fe..73ecf1d72 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -371,6 +371,39 @@ utf8_strlen_screen (const char *string) } /* + * utf8_charcmp: compare two utf8 chars (case sensitive) + */ + +int +utf8_charcmp (const char *string1, const char *string2) +{ + int length1, length2, i, diff; + + if (!string1 || !string2) + return (string1) ? 1 : ((string2) ? -1 : 0); + + length1 = utf8_char_size (string1); + length2 = utf8_char_size (string2); + + i = 0; + while ((i < length1) && (i < length2)) + { + diff = (int)((unsigned char) string1[i]) - (int)((unsigned char) string2[i]); + if (diff != 0) + return diff; + i++; + } + /* string1 == string2 ? */ + if ((i == length1) && (i == length2)) + return 0; + /* string1 < string2 ? */ + if (i == length1) + return 1; + /* string1 > string2 */ + return -1; +} + +/* * utf8_charcasecmp: compare two utf8 chars (case is ignored) */ @@ -401,7 +434,7 @@ utf8_charcasecmp (const char *string1, const char *string2) i = 1; while ((i < length1) && (i < length2)) { - diff = (int)((unsigned char) string1[0]) - (int)((unsigned char) string2[0]); + diff = (int)((unsigned char) string1[i]) - (int)((unsigned char) string2[i]); if (diff != 0) return diff; i++; diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h index d6fc8f927..bf79b71ae 100644 --- a/src/core/wee-utf8.h +++ b/src/core/wee-utf8.h @@ -43,6 +43,7 @@ extern int utf8_char_size (const char *string); extern int utf8_strlen (const char *string); extern int utf8_strnlen (const char *string, int bytes); extern int utf8_strlen_screen (const char *string); +extern int utf8_charcmp (const char *string1, const char *string2); extern int utf8_charcasecmp (const char *string1, const char *string2); extern int utf8_char_size_screen (const char *string); extern char *utf8_add_offset (const char *string, int offset); |