[gtk/wip/compose-parser: 8/9] composetable: Allow removing sequences




commit d8c51b42858101e4b72e895e37b3e91147be4778
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 7 16:09:11 2021 -0400

    composetable: Allow removing sequences
    
    Interpret an empty string as value in the Compose
    file to mean: Remove this sequence.
    
    Tests included.

 gtk/gtkcomposetable.c          | 16 +++++++++++++++-
 testsuite/gtk/compose/include  |  3 ++-
 testsuite/gtk/compose/included |  1 +
 3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcomposetable.c b/gtk/gtkcomposetable.c
index 449d63e340..e32f11f3d5 100644
--- a/gtk/gtkcomposetable.c
+++ b/gtk/gtkcomposetable.c
@@ -481,6 +481,10 @@ parser_read_file (GtkComposeParser *parser,
   g_free (contents);
 }
 
+/* Remove sequences that can be handled algorithmically,
+ * sequences with non-BMP keys, and sequences that produce
+ * empty strings.
+ */
 static void
 parser_remove_duplicates (GtkComposeParser *parser)
 {
@@ -498,6 +502,12 @@ parser_remove_duplicates (GtkComposeParser *parser)
       char buf[8] = { 0, };
       gboolean remove_sequence = FALSE;
 
+      if (value[0] == '\0')
+        {
+          remove_sequence = TRUE;
+          goto next;
+        }
+
       for (i = 0; i < MAX_COMPOSE_LEN + 1; i++)
         keysyms[i] = 0;
 
@@ -510,7 +520,10 @@ parser_remove_duplicates (GtkComposeParser *parser)
             break;
 
           if (codepoint > 0xffff)
-            remove_sequence = TRUE;
+            {
+              remove_sequence = TRUE;
+              goto next;
+            }
 
           n_compose++;
         }
@@ -522,6 +535,7 @@ parser_remove_duplicates (GtkComposeParser *parser)
             remove_sequence = TRUE;
         }
 
+next:
       if (remove_sequence)
         g_hash_table_iter_remove (&iter);
     }
diff --git a/testsuite/gtk/compose/include b/testsuite/gtk/compose/include
index 10abadf446..f69d7a79e7 100644
--- a/testsuite/gtk/compose/include
+++ b/testsuite/gtk/compose/include
@@ -1,3 +1,4 @@
 include "testsuite/gtk/compose/included"   # see if this works
 
-<Multi_key> <s> <s> <s> : "!"
+<Multi_key> <s> <s> <s> : "!" # replace this entry
+<Multi_key> <a> <a> <a> : ""  # remove this entry
diff --git a/testsuite/gtk/compose/included b/testsuite/gtk/compose/included
index d5d3a68adc..77162b6563 100644
--- a/testsuite/gtk/compose/included
+++ b/testsuite/gtk/compose/included
@@ -1 +1,2 @@
 <Multi_key> <s> <s> <s> : "XO"
+<Multi_key> <a> <a> <a> : "Aaah!"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]