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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user