]> arthur.barton.de Git - netatalk.git/commitdiff
search of surrogate pair
authorHAT <hat@fa2.so-net.ne.jp>
Sat, 31 Dec 2011 06:43:28 +0000 (15:43 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Sat, 31 Dec 2011 06:43:28 +0000 (15:43 +0900)
NEWS
libatalk/unicode/util_unistr.c

diff --git a/NEWS b/NEWS
index 8cdd6881acff2b71da4aa1b4357b3de3f6c2936f..6d8fcd9365b81163894d21cfe23452615918e201 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,7 @@ Changes in 2.2.2
        files
 * FIX: Fix compilation error when AppleTalk support is disabled
 * FIX: Portability fixes
+* FIX: search of surrogate pair
 
 Changes in 2.2.1
 ================
index 3aa7036bf81358e0ca4267f7edd357b27d24c11e..f878c8c08015e685974b081d4b199e84e3a73d71 100644 (file)
@@ -250,7 +250,7 @@ ucs2_t *strstr_w(const ucs2_t *s, const ucs2_t *ins)
 /*******************************************************************
 wide strcasestr()
 ********************************************************************/
-/* */
+/* surrogate pair support */
 
 ucs2_t *strcasestr_w(const ucs2_t *s, const ucs2_t *ins)
 {
@@ -261,9 +261,22 @@ 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;
 }
@@ -359,6 +372,8 @@ ucs2_t *strdup_w(const ucs2_t *src)
 /*******************************************************************
 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)
 {
@@ -378,7 +393,9 @@ 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;
@@ -395,7 +412,7 @@ ucs2_t *strncat_w(ucs2_t *dest, const ucs2_t *src, const size_t max)
        return dest;
 }
 
-
+/* no problem of surrogate pair */
 ucs2_t *strcat_w(ucs2_t *dest, const ucs2_t *src)
 {
        size_t start;