xfreopen: new module, from coreutils
[gnulib.git] / lib / uninorm / canonical-decomposition.c
index 9afaead..210b74b 100644 (file)
@@ -29,24 +29,45 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition)
 {
   if (uc >= 0xAC00 && uc < 0xD7A4)
     {
-      /* Hangul syllable.  See Unicode standard, chapter 3,
-        section "Hangul Syllable Decomposition".  */
-      unsigned int t, v, l;
+      /* Hangul syllable.  See Unicode standard, chapter 3, section
+         "Hangul Syllable Decomposition",  See also the clarification at
+        <http://www.unicode.org/versions/Unicode5.1.0/>, section
+        "Clarification of Hangul Jamo Handling".  */
+      unsigned int t;
 
       uc -= 0xAC00;
       t = uc % 28;
-      uc = uc / 28;
-      v = uc % 21;
-      l = uc / 21;
 
-      decomposition[0] = 0x1100 + l;
-      decomposition[1] = 0x1161 + v;
       if (t == 0)
-       return 2;
+       {
+         unsigned int v, l;
+
+         uc = uc / 28;
+         v = uc % 21;
+         l = uc / 21;
+
+         decomposition[0] = 0x1100 + l;
+         decomposition[1] = 0x1161 + v;
+         return 2;
+       }
       else
        {
+#if 1 /* Return the pairwise decomposition, not the full decomposition.  */
+         decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */
+         decomposition[1] = 0x11A7 + t;
+         return 2;
+#else
+         unsigned int v, l;
+
+         uc = uc / 28;
+         v = uc % 21;
+         l = uc / 21;
+
+         decomposition[0] = 0x1100 + l;
+         decomposition[1] = 0x1161 + v;
          decomposition[2] = 0x11A7 + t;
          return 3;
+#endif
        }
     }
   else if (uc < 0x110000)