diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-15 11:33:45 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-15 11:33:45 +0200 |
commit | 9679cd4fbf94da890ad33edca2956c5d5d1189d3 (patch) | |
tree | aaf65940b222027861e454ba67d061e86a0b727f /src | |
parent | 433f5e86fa6900247b7a5667adc42059a3e76545 (diff) | |
download | weechat-9679cd4fbf94da890ad33edca2956c5d5d1189d3.zip |
Fix compilation problem on FreeBSD: replace call to wcscasecmp() by towlower()
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-string.c | 42 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 53 | ||||
-rw-r--r-- | src/core/wee-utf8.h | 1 |
3 files changed, 49 insertions, 47 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 2bf09bc3a..9a438f456 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -550,53 +550,13 @@ string_convert_hex_chars (const char *string) } /* - * string_get_wide_char: get wide char from string (first char) - */ - -wint_t -string_get_wide_char (const char *string) -{ - int char_size; - wint_t result; - - if (!string || !string[0]) - return WEOF; - - char_size = utf8_char_size (string); - switch (char_size) - { - case 1: - result = (wint_t)string[0]; - break; - case 2: - result = ((wint_t)((unsigned char)string[0])) << 8 - | ((wint_t)((unsigned char)string[1])); - break; - case 3: - result = ((wint_t)((unsigned char)string[0])) << 16 - | ((wint_t)((unsigned char)string[1])) << 8 - | ((wint_t)((unsigned char)string[2])); - break; - case 4: - result = ((wint_t)((unsigned char)string[0])) << 24 - | ((wint_t)((unsigned char)string[1])) << 16 - | ((wint_t)((unsigned char)string[2])) << 8 - | ((wint_t)((unsigned char)string[3])); - break; - default: - result = WEOF; - } - return result; -} - -/* * string_is_word_char: return 1 if given character is a "word character" */ int string_is_word_char (const char *string) { - wint_t c = string_get_wide_char (string); + wint_t c = utf8_wide_char (string); if (c == WEOF) return 0; diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 17f6c20c6..33255fbaf 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -25,6 +25,7 @@ #include <stdlib.h> #include <string.h> +#include <wctype.h> #include "weechat.h" #include "wee-utf8.h" @@ -281,6 +282,46 @@ utf8_char_int (const char *string) } /* + * utf8_wide_char: get wide char from string (first char) + */ + +wint_t +utf8_wide_char (const char *string) +{ + int char_size; + wint_t result; + + if (!string || !string[0]) + return WEOF; + + char_size = utf8_char_size (string); + switch (char_size) + { + case 1: + result = (wint_t)string[0]; + break; + case 2: + result = ((wint_t)((unsigned char)string[0])) << 8 + | ((wint_t)((unsigned char)string[1])); + break; + case 3: + result = ((wint_t)((unsigned char)string[0])) << 16 + | ((wint_t)((unsigned char)string[1])) << 8 + | ((wint_t)((unsigned char)string[2])); + break; + case 4: + result = ((wint_t)((unsigned char)string[0])) << 24 + | ((wint_t)((unsigned char)string[1])) << 16 + | ((wint_t)((unsigned char)string[2])) << 8 + | ((wint_t)((unsigned char)string[3])); + break; + default: + result = WEOF; + } + return result; +} + +/* * utf8_char_size: return UTF-8 char size (in bytes) */ @@ -410,18 +451,18 @@ utf8_charcmp (const char *string1, const char *string2) int utf8_charcasecmp (const char *string1, const char *string2) { - wchar_t wstring1[2], wstring2[2]; + wint_t wchar1, wchar2; if (!string1 || !string2) return (string1) ? 1 : ((string2) ? -1 : 0); - memset (wstring1, 0, sizeof (wstring1)); - memset (wstring2, 0, sizeof (wstring2)); + wchar1 = utf8_wide_char (string1); + wchar1 = towlower (wchar1); - mbstowcs (wstring1, string1, 1); - mbstowcs (wstring2, string2, 1); + wchar2 = utf8_wide_char (string2); + wchar2 = towlower (wchar2); - return wcscasecmp (wstring1, wstring2); + return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1); } /* diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h index bf79b71ae..df6ef1c46 100644 --- a/src/core/wee-utf8.h +++ b/src/core/wee-utf8.h @@ -39,6 +39,7 @@ extern void utf8_normalize (const char *string, char replacement); extern char *utf8_prev_char (const char *string_start, const char *string); extern char *utf8_next_char (const char *string); extern int utf8_char_int (const char *string); +extern wint_t utf8_wide_char (const char *string); extern int utf8_char_size (const char *string); extern int utf8_strlen (const char *string); extern int utf8_strnlen (const char *string, int bytes); |