diff options
| author | Jules Aguillon | 2024-05-29 15:02:08 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2024-05-29 15:02:08 +0200 |
| commit | 39b3f50aa31df9786e4a10a27633137a4369f6ae (patch) | |
| tree | 96f08b316d5774e06914395d55330e05e442b652 /srcs/juloo.keyboard2/ComposeKey.java | |
| parent | f7f1d85f80c9112192385b4b5294a5544ca009f3 (diff) | |
| download | unexpected-keyboard-39b3f50aa31df9786e4a10a27633137a4369f6ae.tar.gz unexpected-keyboard-39b3f50aa31df9786e4a10a27633137a4369f6ae.zip | |
Allow compose sequence ending with more symbols
Change the compose state machine definition to allow final states that
are wider than 16-bits.
This increases the number of sequences that can be used from
en_US_UTF_8_Compose.pre from 2013 to 2043 (of 3201).
Diffstat (limited to 'srcs/juloo.keyboard2/ComposeKey.java')
| -rw-r--r-- | srcs/juloo.keyboard2/ComposeKey.java | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/srcs/juloo.keyboard2/ComposeKey.java b/srcs/juloo.keyboard2/ComposeKey.java index ef5a7f2..328bb83 100644 --- a/srcs/juloo.keyboard2/ComposeKey.java +++ b/srcs/juloo.keyboard2/ComposeKey.java @@ -27,31 +27,48 @@ public final class ComposeKey } /** Apply the pending compose sequence to char [c]. */ - static KeyValue apply(int state, char c) + static KeyValue apply(int prev, char c) { char[] states = ComposeKeyData.states; char[] edges = ComposeKeyData.edges; - int length = edges[state]; - int next = Arrays.binarySearch(states, state + 1, state + length, c); + int prev_length = edges[prev]; + int next = Arrays.binarySearch(states, prev + 1, prev + prev_length, c); if (next < 0) return null; next = edges[next]; - // The next state is the end of a sequence, show the result. - if (edges[next] == 1) - return KeyValue.makeCharKey(states[next]); - return KeyValue.makeComposePending(String.valueOf(c), next, 0); + char next_header = states[next]; + if (next_header == 0) // Enter a new intermediate state. + return KeyValue.makeComposePending(String.valueOf(c), next, 0); + else if (next_header > 0) // Character final state. + return KeyValue.makeCharKey(next_header); + else // next_header is < 0, string final state. + { + int next_length = edges[next]; + return KeyValue.makeStringKey( + new String(states, next + 1, next + next_length)); + } } - /** The [states] array represents the different states and their transition. - A state occupies one or several cells of the array: - - The first cell is the result of the compose sequence if the state is of - size 1, unspecified otherwise. - - The remaining cells are the transitions, sorted alphabetically. + /** The state machine is comprised of two arrays. + + The [states] array represents the different states and the associated + transitions: + - The first cell is the header cell, [states[s]]. + - If the header is equal to [0], + The remaining cells are the transitions characters, sorted + alphabetically. + - If the header is positive, + This is a final state, [states[s]] is the result of the sequence. + In this case, [edges[s]] must be equal to [1]. + - If the header is equal to [-1], + This is a final state, the remaining cells represent the result string + which starts at index [s + 1] and has a length of [edges[s] - 1]. The [edges] array represents the transition state corresponding to each accepted inputs. - Id [states[i]] is the first cell of a state, [edges[i]] is the number of - cells occupied by the state [i]. - If [states[i]] is a transition, [edges[i]] is the index of the state to - jump into. */ + - If [states[s]] is a header cell, [edges[s]] is the number of cells + occupied by the state [s], including the header cell. + - If [states[s]] is a transition, [edges[s]] is the index of the state to + jump into. + - If [states[s]] is a part of a final state, [edges[s]] is not used. */ } |
