From 3deb2b3970cb344d0c615e9d41a5fe7f3baf1417 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 18 Jan 2026 21:36:56 +0100 Subject: fixed auto-completion of Unicode file names * teco_string_diff() could return a number of bytes in the middle of an Unicode sequence. It now also requires Unicode strings. * Added a missing Unicode-validity check when replacing command lines (`{` and `}`). teco_cmdline_insert() should really be refactored, though (FIXME). * Added test case --- src/string-utils.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/string-utils.c') diff --git a/src/string-utils.c b/src/string-utils.c index e9dd148..d98b6b0 100644 --- a/src/string-utils.c +++ b/src/string-utils.c @@ -87,8 +87,10 @@ teco_string_get_coord(const gchar *str, gsize off, guint *pos, guint *line, guin } /** - * Get the length of the prefix common to two strings. - * Works with UTF-8 and single-byte encodings. + * Get the length of the prefix common to two UTF-8 strings. + * + * The UTF-8 strings must be validated, which should be the case + * for help labels and short Q-Register names. * * @param a Left string. * @param b Right string. @@ -103,8 +105,8 @@ teco_string_diff(teco_string_t a, const gchar *b, gsize b_len) gsize len = 0; while (len < a.len && len < b_len && - a.data[len] == b[len]) - len++; + g_utf8_get_char(a.data+len) == g_utf8_get_char(b+len)) + len = g_utf8_next_char(b+len) - b; return len; } -- cgit v1.2.3