diff --git a/core/src/ldml/ldml_processor.cpp b/core/src/ldml/ldml_processor.cpp index fcadda629c..4e42c3acea 100644 --- a/core/src/ldml/ldml_processor.cpp +++ b/core/src/ldml/ldml_processor.cpp @@ -348,8 +348,7 @@ km_core_attr const & ldml_processor::attributes() const { } km_core_keyboard_key * ldml_processor::get_key_list() const { - km_core_keyboard_key* key_list = new km_core_keyboard_key(KM_CORE_KEYBOARD_KEY_LIST_END); - return key_list; + return keys.get_key_list(); } km_core_keyboard_imx * ldml_processor::get_imx_list() const { diff --git a/core/src/ldml/ldml_vkeys.cpp b/core/src/ldml/ldml_vkeys.cpp index f79f82141f..5ab5082b73 100644 --- a/core/src/ldml/ldml_vkeys.cpp +++ b/core/src/ldml/ldml_vkeys.cpp @@ -22,6 +22,22 @@ vkeys::add(km_core_virtual_key vk, km_core_ldml_modifier_state modifier_state, s const vkey_id id(vk, modifier_state); // assign the string vkey_to_string[id] = output; + if (!output.empty()) { + // empty string = gap key, etc. + all_vkeys.insert(id); + } +} + +km_core_keyboard_key * +vkeys::get_key_list() const { + km_core_keyboard_key *list = new km_core_keyboard_key[all_vkeys.size() + 1]; + std::size_t n = 0; + for (const auto &k : all_vkeys) { + list[n ].key = k.first; + list[n++].modifier_flag = k.second; + } + list[n++] = KM_CORE_KEYBOARD_KEY_LIST_END; + return list; } static const uint16_t BOTH_ALT = LALTFLAG | RALTFLAG; diff --git a/core/src/ldml/ldml_vkeys.hpp b/core/src/ldml/ldml_vkeys.hpp index 6a54d77065..916d805e2c 100644 --- a/core/src/ldml/ldml_vkeys.hpp +++ b/core/src/ldml/ldml_vkeys.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "keyman_core.h" @@ -37,6 +38,7 @@ typedef std::pair vkey_id; class vkeys { private: std::map vkey_to_string; + std::set all_vkeys; public: vkeys(); @@ -53,6 +55,11 @@ public: std::u16string lookup(km_core_virtual_key vk, uint16_t modifier_state, bool &found) const; + /** + * For implementing ldml_processor::get_key_list() + */ + km_core_keyboard_key* get_key_list() const; + private: /** * Non-recursive internal lookup of a specific ID diff --git a/core/tests/unit/ldml/ldml.cpp b/core/tests/unit/ldml/ldml.cpp index 86d98658d6..daf9dd7d1d 100644 --- a/core/tests/unit/ldml/ldml.cpp +++ b/core/tests/unit/ldml/ldml.cpp @@ -294,8 +294,9 @@ verify_key_list(const km_core_keyboard_key *actual_list, const std::u16string &e std::set actual, expected; std::string expected_str = convert(expected_list); // convert actual list - while (actual_list != nullptr && actual_list->key != 0 && actual_list->modifier_flag != 0) { - actual.emplace(actual_list->key, (uint16_t)actual_list->modifier_flag); + while (actual_list != nullptr && !(actual_list->key == 0 && actual_list->modifier_flag == 0)) { + km::tests::key_event k(actual_list->key, (uint16_t)actual_list->modifier_flag); + actual.insert(k); actual_list++; // advance pointer } // parse expected_str @@ -420,6 +421,7 @@ run_test(const km::core::path &source, const km::core::path &compiled, km::tests } else { std::cout << " .. matches." << std::endl; } + delete [] actual_list; } break; case km::tests::LDML_ACTION_FAIL: { // test requested failure