ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c)
{
while (*s != 0) {
-/* LOG(log_debug, logtype_default, "Comparing %X to %X (%X - %X)", c, *s, toupper_w(c), toupper_w(*s));*/
- if (toupper_w(c) == toupper_w(*s)) return (ucs2_t *)s;
+ if (tolower_w(c) == tolower_w(*s)) return (ucs2_t *)s;
s++;
}
if (c == *s) return (ucs2_t *)s;
{
if (*s == 0) return NULL;
while (s[1] != 0) {
- if (toupper_sp(c_sp) == toupper_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s;
+ if (tolower_sp(c_sp) == tolower_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s;
s++;
}
/*******************************************************************
wide strcasestr()
********************************************************************/
-/* */
+/* surrogate pair support */
ucs2_t *strcasestr_w(const ucs2_t *s, const ucs2_t *ins)
{
slen = strlen_w(s);
inslen = strlen_w(ins);
r = (ucs2_t *)s;
- while ((r = strcasechr_w(r, *ins))) {
- if (strncasecmp_w(r, ins, inslen) == 0) return r;
- r++;
+
+ if ((0xD800 <= *ins) && (*ins < 0xDC00)) {
+ if ((0xDC00 <= ins[1]) && (ins[1] < 0xE000)) {
+ u_int32_t ins_sp = (u_int32_t)*ins << 16 | (u_int32_t)ins[1];
+ while ((r = strcasechr_sp(r, ins_sp))) {
+ if (strncasecmp_w(r, ins, inslen) == 0) return r;
+ r++;
+ }
+ } else {
+ return NULL; /* illegal sequence */
+ }
+ } else {
+ while ((r = strcasechr_w(r, *ins))) {
+ if (strncasecmp_w(r, ins, inslen) == 0) return r;
+ r++;
+ }
}
return NULL;
}
/*******************************************************************
copy a string with max len
********************************************************************/
+/* This function is not used. */
+/* NOTE: not check isolation of surrogate pair */
ucs2_t *strncpy_w(ucs2_t *dest, const ucs2_t *src, const size_t max)
{
/*******************************************************************
append a string of len bytes and add a terminator
********************************************************************/
+/* These functions are not used. */
+/* NOTE: not check isolation of surrogate pair */
ucs2_t *strncat_w(ucs2_t *dest, const ucs2_t *src, const size_t max)
{
size_t start;
return dest;
}
-
+/* no problem of surrogate pair */
ucs2_t *strcat_w(ucs2_t *dest, const ucs2_t *src)
{
size_t start;