[glib] Document,	that the second part of a decompose() wouldn't decompose()
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [glib] Document,	that the second part of a decompose() wouldn't decompose()
- Date: Thu, 14 Jul 2011 20:56:09 +0000 (UTC)
commit 89a5d17d58c795f835642483bfbd9af6cf09f9fe
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Jul 14 16:26:58 2011 -0400
    Document, that the second part of a decompose() wouldn't decompose()
    
    This is not directly documented in Unicode, or I couldn't find it,
    but the test I just added confirms that it is currently the case.
 glib/gunidecomp.c    |    7 +++++++
 glib/tests/unicode.c |   16 ++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/glib/gunidecomp.c b/glib/gunidecomp.c
index 22ca972..dbba10c 100644
--- a/glib/gunidecomp.c
+++ b/glib/gunidecomp.c
@@ -625,6 +625,13 @@ compose_hangul_step (gunichar a,
  * If @ch is not decomposable, * a is set to @ch and * b
  * is set to zero.
  *
+ * Note that the way Unicode decomposition pairs are
+ * defined, it is guaranteed that @b would not decompose
+ * further, but @a may itself decompose.  To get the full
+ * canonical decomposition for @ch, one would need to
+ * recursively call this function on @a.  Or use
+ * g_unicode_canonical_decomposition().
+ *
  * See <ulink url="http://unicode.org/reports/tr15/">UAX#15</ulink>
  * for details.
  *
diff --git a/glib/tests/unicode.c b/glib/tests/unicode.c
index 68533dc..8a43388 100644
--- a/glib/tests/unicode.c
+++ b/glib/tests/unicode.c
@@ -525,6 +525,21 @@ test_canonical_decomposition (void)
   TEST2 (0xCE20, 0x110E, 0x1173);
 }
 
+static void
+test_decompose_tail (void)
+{
+  gunichar ch, a, b, c, d;
+
+  /* Test that whenever a char ch decomposes into a and b, b itself
+   * won't decompose any further. */
+
+  for (ch = 0; ch < 0x110000; ch++)
+    if (g_unichar_decompose (ch, &a, &b))
+      g_assert (!g_unichar_decompose (b, &c, &d));
+    else
+      g_assert (a == ch && b == 0);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -543,6 +558,7 @@ main (int   argc,
   g_test_add_func ("/unicode/compose", test_compose);
   g_test_add_func ("/unicode/decompose", test_decompose);
   g_test_add_func ("/unicode/canonical-decomposition", test_canonical_decomposition);
+  g_test_add_func ("/unicode/decompose-tail", test_decompose_tail);
 
   return g_test_run();
 }
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]