/* Copyright: © SIL International. Description: This is an implementation of the LDML keyboard spec 3.0. Create Date: 5 Aug 2023 Authors: Marc Durdin (MD) */ #include "ldml/ldml_processor.hpp" #include "state.hpp" namespace { constexpr km_kbp_attr const engine_attrs = { 256, KM_KBP_LIB_CURRENT, KM_KBP_LIB_AGE, KM_KBP_LIB_REVISION, KM_KBP_TECH_LDML, "SIL International" }; } namespace km { namespace kbp { ldml_processor::ldml_processor(void *data, size_t len) : abstract_processor( /* TODO: keyboard_attributes(path.stem(), u"3.145", path.parent(), { option{KM_KBP_OPT_KEYBOARD, u"__test_point", u"not tiggered"}, }) */), _options({ /* TODO: {u"\x01__test_point", u"not tiggered"}, {u"\x02hello", u"-"} */ }) { // TODO: load the file from the buffer (KMXPlus format) } char16_t const * ldml_processor::lookup_option(km_kbp_option_scope scope, std::u16string const & key) const { auto i = _options.find(char16_t(scope) + key); return i != _options.end() ? i->second.c_str() : nullptr; } option ldml_processor::update_option(km_kbp_option_scope scope, std::u16string const & key, std::u16string const & value) { auto i = _options.find(char16_t(scope) + key); if (i == _options.end()) return option(); i->second = value; persisted_store()[key] = value; return option(scope, key, i->second); } km_kbp_status ldml_processor::process_queued_actions( km_kbp_state *state ) { assert(state); if (!state) return KM_KBP_STATUS_INVALID_ARGUMENT; // TODO Implement return KM_KBP_STATUS_OK; } bool ldml_processor::queue_action( km_kbp_state * state, km_kbp_action_item const* action_item ) { assert(state); assert(action_item); if ((!state) || (!action_item)) return false; return false; } km_kbp_status ldml_processor::process_event( km_kbp_state *state, km_kbp_virtual_key vk, uint16_t modifier_state, uint8_t is_key_down ) { assert(state); if (!state) return KM_KBP_STATUS_INVALID_ARGUMENT; if (!is_key_down) { // TODO: Implement caps lock handling return KM_KBP_STATUS_OK; } try { // At the start of every process_event always clear the action_items state->actions().clear(); 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 break; } state->actions().commit(); } catch (std::bad_alloc &) { state->actions().clear(); return KM_KBP_STATUS_NO_MEM; } return KM_KBP_STATUS_OK; } km_kbp_attr const & ldml_processor::attributes() const { return engine_attrs; } km_kbp_keyboard_key * ldml_processor::get_key_list() const { km_kbp_keyboard_key* key_list = new km_kbp_keyboard_key(KM_KBP_KEYBOARD_KEY_LIST_END); return key_list; } km_kbp_keyboard_imx * ldml_processor::get_imx_list() const { km_kbp_keyboard_imx* imx_list = new km_kbp_keyboard_imx(KM_KBP_KEYBOARD_IMX_END); return imx_list; } km_kbp_context_item * ldml_processor::get_intermediate_context() { km_kbp_context_item *citems = new km_kbp_context_item(KM_KBP_CONTEXT_ITEM_END); return citems; } km_kbp_status ldml_processor::validate() const { return KM_KBP_STATUS_OK; } } // namespace kbp } // namespace km