]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/vfs/vfs_utfconv.c
xnu-2422.1.72.tar.gz
[apple/xnu.git] / bsd / vfs / vfs_utfconv.c
index 948076da93e0f8ffd5c1123322b8e534706a350a..f785b0d8c017f3f1534e795cdb25978a8897011e 100644 (file)
@@ -80,7 +80,7 @@
  * Similar to __CFUniCharIsNonBaseCharacter except that
  * unicode_combinable also includes Hangul Jamo characters.
  */
-static inline int
+int
 unicode_combinable(u_int16_t character)
 {
        const u_int8_t *bitmap = __CFUniCharCombiningBitmap;
@@ -105,7 +105,7 @@ unicode_combinable(u_int16_t character)
  *
  * Similar to __CFUniCharIsDecomposableCharacter.
  */
-static inline int
+int
 unicode_decomposeable(u_int16_t character) {
        const u_int8_t *bitmap = __CFUniCharDecomposableBitmap;
        u_int8_t value;
@@ -591,6 +591,12 @@ escape:
                if ((ucsp + 2) >= bufend)
                        goto toolong;
 
+               /* Make a previous combining sequence canonical. */
+               if (combcharcnt > 1) {
+                       priortysort(ucsp - combcharcnt, combcharcnt);
+               }
+               combcharcnt = 0;
+               
                ucs_ch = '%';
                *ucsp++ = swapbytes ? OSSwapInt16(ucs_ch) : (u_int16_t)ucs_ch;
                ucs_ch =  hexdigits[byte >> 4];
@@ -1018,7 +1024,7 @@ priortysort(u_int16_t* characters, int count)
        u_int32_t p1, p2;
        u_int16_t *ch1, *ch2;
        u_int16_t *end;
-       int changes = 1;
+       int changes = 0;
 
        end = characters + count;
        do {
@@ -1029,13 +1035,22 @@ priortysort(u_int16_t* characters, int count)
                while (ch2 < end) {
                        p1 = p2;
                        p2 = get_combining_class(*ch2);
-                       if (p1 > p2) {
+                       if (p1 > p2 && p2 != 0) {
                                u_int32_t tmp;
 
                                tmp = *ch1;
                                *ch1 = *ch2;
                                *ch2 = tmp;
                                changes = 1;
+                               
+                               /*
+                                * Make sure that p2 contains the combining class for the
+                                * character now stored at *ch2.  This isn't required for
+                                * correctness, but it will be more efficient if a character
+                                * with a large combining class has to "bubble past" several
+                                * characters with lower combining classes.
+                                */
+                               p2 = p1;
                        }
                        ++ch1;
                        ++ch2;