From 3ac7c35656649b1d1fcf2ccaa670b854809d4cd8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 6 Dec 2011 18:30:43 +0000 Subject: [PATCH] =?utf8?q?Bug=20665685=20=E2=80=94=20Add=20a=20#define=20f?= =?utf8?q?or=20the=20max=20length=20of=20a=20Unicode=20decomposition?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add G_UNICHAR_MAX_DECOMPOSITION_LEN for the maximum length of the decomposition of a single Unicode character. Closes: bgo#665685 --- glib/gunicode.h | 12 ++++++++++++ glib/gunidecomp.c | 4 ++-- glib/guniprop.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/glib/gunicode.h b/glib/gunicode.h index 213b38f..f89c07c 100644 --- a/glib/gunicode.h +++ b/glib/gunicode.h @@ -551,6 +551,18 @@ gsize g_unichar_fully_decompose (gunichar ch, gunichar *result, gsize result_len); +/** + * G_UNICHAR_MAX_COMPAT_DECOMPOSITION_LEN: + * + * The maximum length (in codepoints) of a compatibility or canonical + * decomposition of a single Unicode character. + * + * This is as defined by Unicode 6.1. + * + * Since: 2.31.3 + */ +#define G_UNICHAR_MAX_DECOMPOSITION_LEN 18 /* codepoints */ + /* Compute canonical ordering of a string in-place. This rearranges decomposed characters in the string according to their combining classes. See the Unicode manual for more information. */ diff --git a/glib/gunidecomp.c b/glib/gunidecomp.c index 6cbc2df..090b42d 100644 --- a/glib/gunidecomp.c +++ b/glib/gunidecomp.c @@ -700,8 +700,8 @@ g_unichar_compose (gunichar a, * currently all decompositions are of length at most 4, but * this may change in the future (very unlikely though). * At any rate, Unicode does guarantee that a buffer of length - * 18 is always enough for both compatibility and canonical - * decompositions, so that is the size recommended. + * %G_UNICHAR_MAX_DECOMPOSITION_LEN is always enough for both compatibility and + * canonical decompositions, so that is the size recommended. * * See UAX#15 * for details. diff --git a/glib/guniprop.c b/glib/guniprop.c index 8b139ae..5b818e3 100644 --- a/glib/guniprop.c +++ b/glib/guniprop.c @@ -855,9 +855,9 @@ real_toupper (const gchar *str, * which could simplify this considerably. */ gsize decomp_len, i; - gunichar decomp[18]; + gunichar decomp[G_UNICHAR_MAX_DECOMPOSITION_LEN]; - decomp_len = g_unichar_fully_decompose (c, FALSE, decomp, 18); + decomp_len = g_unichar_fully_decompose (c, FALSE, decomp, G_N_ELEMENTS (decomp)); for (i=0; i < decomp_len; i++) { if (decomp[i] != 0x307 /* COMBINING DOT ABOVE */) -- 2.7.4