From 5ec1c2422ceac0afc07d26f1d955b93717c1163a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 21 Oct 2024 17:10:01 +0100 Subject: [PATCH] gunidecomp: Add some explanatory comments to g_utf8_normalize() Just to make it a bit easier for people to understand the logic in the implementation in future, because it took me a while. Signed-off-by: Philip Withnall --- glib/gunidecomp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/gunidecomp.c b/glib/gunidecomp.c index 0e8fbde64..67e6531be 100644 --- a/glib/gunidecomp.c +++ b/glib/gunidecomp.c @@ -359,6 +359,8 @@ _g_utf8_normalize_wc (const gchar *str, gboolean do_compose = (mode == G_NORMALIZE_NFC || mode == G_NORMALIZE_NFKC); + /* Do a first pass to work out the length of the normalised string so we can + * allocate a buffer. */ n_wc = 0; p = str; while ((max_len < 0 || p < str + max_len) && *p) @@ -409,8 +411,10 @@ _g_utf8_normalize_wc (const gchar *str, p = next; } + /* Allocate the buffer for the result. */ wc_buffer = g_new (gunichar, n_wc + 1); + /* Do another pass to fill the buffer with the normalised string. */ last_start = 0; n_wc = 0; p = str;