summaryrefslogtreecommitdiff
path: root/src
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
parent741ca8fb6a2a77683210a91d42090b5349eb224d (diff)
downloadweechat-a3841b12e40a6a25aeab7bef53663a0e914db381.zip
Add utf8_charcmp in plugin API, fix bug with utf8_charcasecmp
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-utf8.c35
-rw-r--r--src/core/wee-utf8.h1
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/weechat-plugin.h3
4 files changed, 39 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);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index adfa72f6c..7fbd320ce 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -382,6 +382,7 @@ plugin_load (const char *filename)
new_plugin->utf8_strlen = &utf8_strlen;
new_plugin->utf8_strnlen = &utf8_strnlen;
new_plugin->utf8_strlen_screen = &utf8_strlen_screen;
+ new_plugin->utf8_charcmp = &utf8_charcmp;
new_plugin->utf8_charcasecmp = &utf8_charcasecmp;
new_plugin->utf8_char_size_screen = &utf8_char_size_screen;
new_plugin->utf8_add_offset = &utf8_add_offset;
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index c2a1129b4..059100482 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -180,6 +180,7 @@ struct t_weechat_plugin
int (*utf8_strlen) (const char *string);
int (*utf8_strnlen) (const char *string, int bytes);
int (*utf8_strlen_screen) (const char *string);
+ int (*utf8_charcmp) (const char *string1, const char *string2);
int (*utf8_charcasecmp) (const char *string1, const char *string2);
int (*utf8_char_size_screen) (const char *string);
char *(*utf8_add_offset) (const char *string, int offset);
@@ -722,6 +723,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->utf8_strnlen(__string, __bytes)
#define weechat_utf8_strlen_screen(__string) \
weechat_plugin->utf8_strlen_screen(__string)
+#define weechat_utf8_charcmp(__string1, __string2) \
+ weechat_plugin->utf8_charcmp(__string1, __string2)
#define weechat_utf8_charcasecmp(__string1, __string2) \
weechat_plugin->utf8_charcasecmp(__string1, __string2)
#define weechat_utf8_char_size_screen(__string) \