summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2009-04-11 23:34:32 +0200
committerSebastien Helleu <flashcode@flashtux.org>2009-04-11 23:34:32 +0200
commita3841b12e40a6a25aeab7bef53663a0e914db381 (patch)
tree79fb9f0baece22fbfdfde3d2bdc7cbe86fdddbbd /src/core
parent741ca8fb6a2a77683210a91d42090b5349eb224d (diff)
downloadweechat-a3841b12e40a6a25aeab7bef53663a0e914db381.zip
Add utf8_charcmp in plugin API, fix bug with utf8_charcasecmp
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-utf8.c35
-rw-r--r--src/core/wee-utf8.h1
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);