From: P. F. Chimento Date: Wed, 20 Apr 2011 11:57:10 +0000 (+0200) Subject: Implement unicode normalization X-Git-Tag: v0.9~99 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=20853e106ba8bdd3e54a61aea619a70580a77e34;hp=bdb4a6360e2d9fabf6d16f3a87927cfbba5f304a;p=projects%2Fchimara%2Fchimara.git Implement unicode normalization Unicode decomposition and normalization are now implemented. --- diff --git a/libchimara/case.c b/libchimara/case.c index 1b6eed7..5b1a5d7 100644 --- a/libchimara/case.c +++ b/libchimara/case.c @@ -1,5 +1,7 @@ -#include +#include +#include #include "glk.h" +#include "charset.h" /** * glk_char_to_lower: @@ -193,8 +195,24 @@ glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, glui32 numchars) g_return_val_if_fail(buf != NULL && (len > 0 || numchars > 0), 0); g_return_val_if_fail(numchars <= len, 0); - /* TODO: Implement this */ - return numchars; + long outchars; + + /* Normalize the string */ + char *utf8 = convert_ucs4_to_utf8(buf, numchars); + if(!utf8) + return numchars; + char *decomposed = g_utf8_normalize(utf8, -1, G_NORMALIZE_NFD); + g_free(utf8); + gunichar *outbuf = convert_utf8_to_ucs4(decomposed, &outchars); + g_free(decomposed); + if(!outbuf) + return numchars; + + /* Copy the output buffer to the original buffer */ + memcpy(buf, outbuf, MIN(outchars, len) * 4); + g_free(outbuf); + + return outchars; } /** @@ -255,6 +273,22 @@ glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, glui32 numchars) g_return_val_if_fail(buf != NULL && (len > 0 || numchars > 0), 0); g_return_val_if_fail(numchars <= len, 0); - /* TODO: Implement this */ - return numchars; + long outchars; + + /* Normalize the string */ + char *utf8 = convert_ucs4_to_utf8(buf, numchars); + if(!utf8) + return numchars; + char *decomposed = g_utf8_normalize(utf8, -1, G_NORMALIZE_NFC); + g_free(utf8); + gunichar *outbuf = convert_utf8_to_ucs4(decomposed, &outchars); + g_free(decomposed); + if(!outbuf) + return numchars; + + /* Copy the output buffer to the original buffer */ + memcpy(buf, outbuf, MIN(outchars, len) * 4); + g_free(outbuf); + + return outchars; } diff --git a/libchimara/gestalt.c b/libchimara/gestalt.c index eef7748..13193fc 100644 --- a/libchimara/gestalt.c +++ b/libchimara/gestalt.c @@ -115,6 +115,7 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_Graphics: case gestalt_GraphicsTransparency: case gestalt_DateTime: + case gestalt_UnicodeNorm: return 1; /* Capabilities supported if compiled with GStreamer */ @@ -132,7 +133,6 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_LineInputEcho: case gestalt_LineTerminatorKey: case gestalt_LineTerminators: - case gestalt_UnicodeNorm: /* Selector not supported */ default: return 0;