From 8a6b4a7fd4f864b9bb5546eb475e523f3b527752 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 12 Oct 2022 19:21:35 -0500 Subject: [PATCH] =?UTF-8?q?feat(core):=20ldml:=20Use=20new=20UTF-16=20to?= =?UTF-8?q?=20UTF-32=20function=20=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - also a test case with a 🙀 key on the tiny keyboard For #7418 --- core/src/ldml/ldml_processor.cpp | 26 +++++++++++++---- .../unit/ldml/keyboards/k_002_tinyu32.xml | 28 +++++++++++++++++++ core/tests/unit/ldml/keyboards/meson.build | 3 +- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 core/tests/unit/ldml/keyboards/k_002_tinyu32.xml diff --git a/core/src/ldml/ldml_processor.cpp b/core/src/ldml/ldml_processor.cpp index 148a32eba3..5554261328 100644 --- a/core/src/ldml/ldml_processor.cpp +++ b/core/src/ldml/ldml_processor.cpp @@ -168,8 +168,22 @@ ldml_processor::process_event( switch (vk) { case KM_KBP_VKEY_BKSP: - state->context().pop_back(); - state->actions().push_backspace(KM_KBP_BT_UNKNOWN); // Assuming we don't know the character + { + KMX_DWORD last_char = 0UL; // Assuming we don't know the character + // attempt to get the last char + auto end = state->context().rbegin(); + if(end != state->context().rend()) { + if((*end).type == KM_KBP_CT_CHAR) { + last_char = (*end).character; + } + } + if (last_char == 0UL) { + state->actions().push_backspace(KM_KBP_BT_UNKNOWN); + } else { + state->actions().push_backspace(KM_KBP_BT_CHAR, last_char); + } + state->context().pop_back(); + } break; default: // Look up the key @@ -179,10 +193,10 @@ ldml_processor::process_event( state->actions().commit(); // finish up and return KM_KBP_STATUS_OK; // Nothing to do- no key } - for(size_t i=0; icontext().push_character(str[i]); - state->actions().push_character(str[i]); + const std::u32string str32 = kmx::u16string_to_u32string(str); + for(size_t i=0; icontext().push_character(str32[i]); + state->actions().push_character(str32[i]); } } state->actions().commit(); diff --git a/core/tests/unit/ldml/keyboards/k_002_tinyu32.xml b/core/tests/unit/ldml/keyboards/k_002_tinyu32.xml new file mode 100644 index 0000000000..1055041696 --- /dev/null +++ b/core/tests/unit/ldml/keyboards/k_002_tinyu32.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/tests/unit/ldml/keyboards/meson.build b/core/tests/unit/ldml/keyboards/meson.build index f833e2a4be..0d3d0af956 100644 --- a/core/tests/unit/ldml/keyboards/meson.build +++ b/core/tests/unit/ldml/keyboards/meson.build @@ -7,7 +7,8 @@ tests = [ # disabling 000 until we have updates to core or to the keyboard so that it passes # 'k_000_null_keyboard', - 'k_001_tiny' + 'k_001_tiny', + 'k_002_tinyu32', ] # Setup kmc