diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-01-30 22:41:29 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-01 09:54:32 +0100 |
commit | 0e3408d4d603ab3d1945818ed5875eaf5b4c6b4b (patch) | |
tree | 3307b52d0d48a1092c6205e53d3daf963b330d33 /Userland/Libraries/LibKeyboard | |
parent | d9e7e13fb23f1d904c439ded253c2be14f82c86b (diff) | |
download | serenity-0e3408d4d603ab3d1945818ed5875eaf5b4c6b4b.zip |
LibKeyboard: Don't assert on failure
Diffstat (limited to 'Userland/Libraries/LibKeyboard')
-rw-r--r-- | Userland/Libraries/LibKeyboard/CharacterMap.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibKeyboard/CharacterMap.h | 2 |
2 files changed, 10 insertions, 12 deletions
diff --git a/Userland/Libraries/LibKeyboard/CharacterMap.cpp b/Userland/Libraries/LibKeyboard/CharacterMap.cpp index 3ea6604df2..059c6da20f 100644 --- a/Userland/Libraries/LibKeyboard/CharacterMap.cpp +++ b/Userland/Libraries/LibKeyboard/CharacterMap.cpp @@ -27,24 +27,22 @@ #include "CharacterMap.h" #include <AK/StringBuilder.h> #include <Kernel/API/Syscall.h> -#ifndef KERNEL -# include <LibKeyboard/CharacterMapFile.h> -#endif +#include <LibKeyboard/CharacterMapFile.h> namespace Keyboard { -CharacterMap::CharacterMap(const String& map_name) +#ifndef KERNEL +// The Kernel explicitly and exclusively links only this file into it. +// Thus, we cannot even include a reference to the symbol `CharacterMapFile::load_from_file`. +Optional<CharacterMap> CharacterMap::load_from_file(const String& map_name) { -#ifdef KERNEL - m_character_map_data = default_character_map; -#else auto result = CharacterMapFile::load_from_file(map_name); - ASSERT(result.has_value()); + if (!result.has_value()) + return {}; - m_character_map_data = result.value(); -#endif - m_character_map_name = map_name; + return CharacterMap(map_name, result.value()); } +#endif CharacterMap::CharacterMap(const String& map_name, const CharacterMapData& map_data) : m_character_map_data(map_data) diff --git a/Userland/Libraries/LibKeyboard/CharacterMap.h b/Userland/Libraries/LibKeyboard/CharacterMap.h index 848b32a7fa..5a45c34fdb 100644 --- a/Userland/Libraries/LibKeyboard/CharacterMap.h +++ b/Userland/Libraries/LibKeyboard/CharacterMap.h @@ -39,8 +39,8 @@ namespace Keyboard { class CharacterMap { public: - CharacterMap(const String& map_name); CharacterMap(const String& map_name, const CharacterMapData& map_data); + static Optional<CharacterMap> load_from_file(const String& file_name); #ifndef KERNEL int set_system_map(); |