diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-02-01 23:37:05 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-02-02 09:02:00 -0500 |
commit | 9142aa0f51fc33b7b17c1553e9978eb702efb6a2 (patch) | |
tree | e76b0aafbbecacf1743a7ed1407816f8a1a4bbfd | |
parent | af9a578d68c2c19de22893fc6d491656a665dfca (diff) | |
download | gtk+-9142aa0f51fc33b7b17c1553e9978eb702efb6a2.tar.gz |
composetable: Prepare for multi character values
Make it possible for gtk_compose_table_check to return
a string instead of just a single Unicode character.
Currently, we only ever return strings holding a single
character, still.
-rw-r--r-- | gtk/gtkcomposetable.c | 12 | ||||
-rw-r--r-- | gtk/gtkcomposetable.h | 2 | ||||
-rw-r--r-- | testsuite/gtk/composetable.c | 27 |
3 files changed, 25 insertions, 16 deletions
diff --git a/gtk/gtkcomposetable.c b/gtk/gtkcomposetable.c index 033155840d..ba7a201ea6 100644 --- a/gtk/gtkcomposetable.c +++ b/gtk/gtkcomposetable.c @@ -880,7 +880,7 @@ compare_seq (const void *key, const void *value) * @n_compose: number of non-zero key vals in @compose_buffer * @compose_finish: (out): return location for whether there may be longer matches * @compose_match: (out): return location for whether there is a match - * @output_value: (out): return location for the match value + * @output: (out) (caller-allocates): return location for the match values * * Looks for matches for a key sequence in @table. * @@ -892,14 +892,15 @@ gtk_compose_table_check (const GtkComposeTable *table, int n_compose, gboolean *compose_finish, gboolean *compose_match, - gunichar *output_value) + GString *output) { int row_stride = table->max_seq_len + 2; guint16 *seq; *compose_finish = FALSE; *compose_match = FALSE; - *output_value = 0; + + g_string_set_size (output, 0); /* Will never match, if the sequence in the compose buffer is longer * than the sequences in the table. Further, compare_seq (key, val) @@ -932,8 +933,11 @@ gtk_compose_table_check (const GtkComposeTable *table, seq[n_compose] == 0) /* complete sequence */ { guint16 *next_seq; + gunichar value; + + value = 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1]; + g_string_append_unichar (output, value); - *output_value = 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1]; *compose_match = TRUE; /* We found a tentative match. See if there are any longer diff --git a/gtk/gtkcomposetable.h b/gtk/gtkcomposetable.h index 2b31f3678f..88fb3c032f 100644 --- a/gtk/gtkcomposetable.h +++ b/gtk/gtkcomposetable.h @@ -55,7 +55,7 @@ gboolean gtk_compose_table_check (const GtkComposeTable *table int n_compose, gboolean *compose_finish, gboolean *compose_match, - gunichar *output_value); + GString *output); gboolean gtk_compose_table_compact_check (const GtkComposeTableCompact *table, const guint16 *compose_buffer, diff --git a/testsuite/gtk/composetable.c b/testsuite/gtk/composetable.c index 26659bf9f9..0d0644932f 100644 --- a/testsuite/gtk/composetable.c +++ b/testsuite/gtk/composetable.c @@ -94,7 +94,9 @@ compose_table_match (void) char *file; guint16 buffer[8] = { 0, }; gboolean finish, match, ret; - gunichar ch; + GString *output; + + output = g_string_new (""); file = g_build_filename (g_test_get_dir (G_TEST_DIST), "compose", "match", NULL); @@ -106,50 +108,53 @@ compose_table_match (void) buffer[0] = GDK_KEY_Multi_key; buffer[1] = 0; - ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, &ch); + ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, output); g_assert_true (ret); g_assert_false (finish); g_assert_false (match); - g_assert_true (ch == 0); + g_assert_true (output->len == 0); buffer[0] = GDK_KEY_a; buffer[1] = 0; - ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, &ch); + ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, output); g_assert_false (ret); g_assert_false (finish); g_assert_false (match); - g_assert_true (ch == 0); + g_assert_true (output->len == 0); buffer[0] = GDK_KEY_Multi_key; buffer[1] = GDK_KEY_s; buffer[2] = GDK_KEY_e; - ret = gtk_compose_table_check (table, buffer, 3, &finish, &match, &ch); + ret = gtk_compose_table_check (table, buffer, 3, &finish, &match, output); g_assert_true (ret); g_assert_false (finish); g_assert_false (match); - g_assert_true (ch == 0); + g_assert_true (output->len == 0); buffer[0] = GDK_KEY_Multi_key; buffer[1] = GDK_KEY_s; buffer[2] = GDK_KEY_e; buffer[3] = GDK_KEY_q; - ret = gtk_compose_table_check (table, buffer, 4, &finish, &match, &ch); + ret = gtk_compose_table_check (table, buffer, 4, &finish, &match, output); g_assert_true (ret); g_assert_false (finish); g_assert_true (match); - g_assert_true (ch == '!'); + g_assert_cmpstr (output->str, ==, "!"); + + g_string_set_size (output, 0); buffer[0] = GDK_KEY_Multi_key; buffer[1] = GDK_KEY_s; buffer[2] = GDK_KEY_e; buffer[3] = GDK_KEY_q; buffer[4] = GDK_KEY_u; - ret = gtk_compose_table_check (table, buffer, 5, &finish, &match, &ch); + ret = gtk_compose_table_check (table, buffer, 5, &finish, &match, output); g_assert_true (ret); g_assert_true (finish); g_assert_true (match); - g_assert_true (ch == '?'); + g_assert_cmpstr (output->str, ==, "?"); + g_string_free (output, TRUE); g_free (file); } |