mirror of
https://github.com/fltk/fltk.git
synced 2026-05-19 20:27:04 +08:00
Fixed fl_utf_strncasecmp etc.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9639 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
CHANGES IN FLTK 1.3.2
|
||||
|
||||
- Fixed utf_strncasecmp and utf_strcasecmp
|
||||
- Moved all inline constructors into source file to avoid bad DLLs
|
||||
- Fixed Fl_Widget::copy_label() and Fl_Window::copy_label() when
|
||||
called with the old label() (STR #2836)
|
||||
|
||||
+30
-63
@@ -178,79 +178,46 @@ fl_utf_nb_char(
|
||||
return nbc;
|
||||
}
|
||||
|
||||
/*
|
||||
* compare only the first n bytes
|
||||
* return 0 if the strings are equal;
|
||||
* return 1 if s1 is greater than s2
|
||||
* return -1 if s1 is less than s2
|
||||
*/
|
||||
/**
|
||||
UTF-8 aware strncasecmp - converts to lower case Unicode and tests.
|
||||
|
||||
\todo Correct the incorrect logic where length of strings tested
|
||||
\todo Clarify whether n means number of bytes, or characters.
|
||||
/**
|
||||
UTF-8 aware strncasecmp - converts to lower case Unicode and tests.
|
||||
|
||||
\param s1, s2 the utf8 strings to compare
|
||||
\param n the maximum number of utf8 characters to compare
|
||||
\return 0 if the strings are equal
|
||||
\return >0 if s1 is greater than s2
|
||||
\return <0 if s1 is less than s2
|
||||
*/
|
||||
int fl_utf_strncasecmp(const char *s1, const char *s2, int n)
|
||||
{
|
||||
int i;
|
||||
int s1_l;
|
||||
int s2_l;
|
||||
char *e1, *e2; // string end pointers
|
||||
|
||||
s1_l = 0;
|
||||
while (s1_l < n && s1[s1_l]) s1_l++;
|
||||
s2_l = 0;
|
||||
while (s2_l < n && s2[s2_l]) s2_l++;
|
||||
|
||||
if (s1_l < s2_l) {
|
||||
return -1;
|
||||
} else if (s1_l > s2_l) {
|
||||
return 1;
|
||||
}
|
||||
e1 = (char *)&s1[s1_l]; // last char to test
|
||||
e2 = (char *)&s2[s2_l];
|
||||
for (i = 0; i < n;) {
|
||||
int l1, l2;
|
||||
unsigned int u1, u2;
|
||||
int res;
|
||||
|
||||
// l1 = fl_utf2ucs((unsigned char*)s1 + i, n - i, &u1);
|
||||
u1 = fl_utf8decode(s1 + i, e1, &l1);
|
||||
// l2 = fl_utf2ucs((unsigned char*)s2 + i, n - i, &u2);
|
||||
u2 = fl_utf8decode(s2 + i, e2, &l2);
|
||||
if (l1 - l2 != 0) return l1 - l2;
|
||||
res = XUtf8Tolower(u1) - XUtf8Tolower(u2);
|
||||
if (res != 0) return res;
|
||||
if (l1 < 1) {
|
||||
i += 1;
|
||||
} else {
|
||||
i += l1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int l1, l2;
|
||||
unsigned int u1, u2;
|
||||
|
||||
if (*s1==0 && *s2==0) return 0; // all compared equal, return 0
|
||||
|
||||
u1 = fl_utf8decode(s1, 0, &l1);
|
||||
u2 = fl_utf8decode(s2, 0, &l2);
|
||||
int res = XUtf8Tolower(u1) - XUtf8Tolower(u2);
|
||||
if (res) return res;
|
||||
s1 += l1;
|
||||
s2 += l2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* return 0 if the strings are equal;
|
||||
* return 1 if s1 is greater than s2
|
||||
* return -1 if s1 is less than s2
|
||||
*/
|
||||
/**
|
||||
UTF-8 aware strcasecmp - converts to Unicode and tests.
|
||||
|
||||
\todo Correct the incorrect logic where length of strings tested
|
||||
/**
|
||||
UTF-8 aware strcasecmp - converts to Unicode and tests.
|
||||
|
||||
\return 0 if the strings are equal
|
||||
\return 1 if s1 is greater than s2
|
||||
\return -1 if s1 is less than s2
|
||||
*/
|
||||
int fl_utf_strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
int s1_l = (int) strlen(s1);
|
||||
int s2_l = (int) strlen(s2);
|
||||
|
||||
if (s1_l < s2_l) {
|
||||
return -1;
|
||||
} else if (s1_l > s2_l) {
|
||||
return 1;
|
||||
}
|
||||
return fl_utf_strncasecmp(s1, s2, s1_l);
|
||||
return fl_utf_strncasecmp(s1, s2, 0x7fffffff);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user