From ca25cc55f6bc2c7b3100da2f7bf18a078a23f55e Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 23 Feb 2025 18:00:44 +0100 Subject: Apply compose sequences to String keys This is mostly useful for characters that do not fit on a single 16-bit char. Shift sequences for 𝕨𝕩𝕗𝕘𝕤 are added for illustration. --- test/juloo.keyboard2/ComposeKeyTest.java | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/juloo.keyboard2/ComposeKeyTest.java b/test/juloo.keyboard2/ComposeKeyTest.java index 3d0b371..a3d1ddb 100644 --- a/test/juloo.keyboard2/ComposeKeyTest.java +++ b/test/juloo.keyboard2/ComposeKeyTest.java @@ -42,22 +42,21 @@ public class ComposeKeyTest assertEquals(apply("ய", state), KeyValue.makeStringKey("௰", KeyValue.FLAG_SMALLER_FONT)); } - KeyValue apply(String seq) throws Exception + @Test + public void stringKeys() throws Exception + { + int state = ComposeKeyData.shift; + assertEquals(apply("𝕨", state), KeyValue.makeStringKey("𝕎")); + assertEquals(apply("𝕩", state), KeyValue.makeStringKey("𝕏")); + } + + KeyValue apply(String seq) { - return apply(seq, ComposeKeyData.compose); + return ComposeKey.apply(ComposeKeyData.compose, seq); } - KeyValue apply(String seq, int state) throws Exception + KeyValue apply(String seq, int state) { - KeyValue r = null; - for (int i = 0; i < seq.length(); i++) - { - r = ComposeKey.apply(state, seq.charAt(i)); - if (r.getKind() == KeyValue.Kind.Compose_pending) - state = r.getPendingCompose(); - else if (i + 1 < seq.length()) - throw new Exception("Sequence too long: " + seq); - } - return r; + return ComposeKey.apply(state, seq); } } -- cgit v1.2.3