From ffc0f61dd50b31697961c929d473b038719b5c12 Mon Sep 17 00:00:00 2001 From: zonble Date: Tue, 13 Feb 2024 00:05:00 +0800 Subject: [PATCH] Fixes CPP coding style. --- src/CMakeLists.txt | 1 + src/ChineseNumbers/ChineseNumbers.cpp | 23 ++++++++++ src/ChineseNumbers/ChineseNumbers.h | 23 ++++++++++ src/ChineseNumbers/ChineseNumbersTest.cpp | 23 ++++++++++ src/ChineseNumbers/StringUtils.cpp | 22 ++++++++++ src/ChineseNumbers/StringUtils.h | 23 ++++++++++ src/ChineseNumbers/SuzhouNumbers.cpp | 23 ++++++++++ src/ChineseNumbers/SuzhouNumbers.h | 22 ++++++++++ src/ChineseNumbers/SuzhouNumbersTest.cpp | 22 ++++++++++ src/DictionaryService.cpp | 2 +- src/InputState.cpp | 52 ++++++++++++++++++++++ src/InputState.h | 53 +++++++---------------- src/Key.h | 3 +- src/McBopomofo.cpp | 6 +-- 14 files changed, 255 insertions(+), 43 deletions(-) create mode 100644 src/InputState.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20502d4..cee052f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ set(MCBOPOMOFO_LIB_SOURCES KeyHandler.cpp LanguageModelLoader.cpp UTF8Helper.cpp + InputState.cpp InputMacro.cpp Log.cpp DictionaryService.cpp diff --git a/src/ChineseNumbers/ChineseNumbers.cpp b/src/ChineseNumbers/ChineseNumbers.cpp index e113c79..94d4a00 100644 --- a/src/ChineseNumbers/ChineseNumbers.cpp +++ b/src/ChineseNumbers/ChineseNumbers.cpp @@ -1,3 +1,26 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #include "ChineseNumbers.h" #include diff --git a/src/ChineseNumbers/ChineseNumbers.h b/src/ChineseNumbers/ChineseNumbers.h index a397427..c1c9d20 100644 --- a/src/ChineseNumbers/ChineseNumbers.h +++ b/src/ChineseNumbers/ChineseNumbers.h @@ -1,3 +1,26 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #ifndef FCITX5_MCBOPOMOFO_CHINESENUMBER_H #define FCITX5_MCBOPOMOFO_CHINESENUMBER_H diff --git a/src/ChineseNumbers/ChineseNumbersTest.cpp b/src/ChineseNumbers/ChineseNumbersTest.cpp index 19c0e95..bb701a2 100644 --- a/src/ChineseNumbers/ChineseNumbersTest.cpp +++ b/src/ChineseNumbers/ChineseNumbersTest.cpp @@ -1,3 +1,26 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #include "ChineseNumbers.h" #include "gtest/gtest.h" diff --git a/src/ChineseNumbers/StringUtils.cpp b/src/ChineseNumbers/StringUtils.cpp index 916e6b9..0c8f568 100644 --- a/src/ChineseNumbers/StringUtils.cpp +++ b/src/ChineseNumbers/StringUtils.cpp @@ -1,3 +1,25 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. #include "StringUtils.h" diff --git a/src/ChineseNumbers/StringUtils.h b/src/ChineseNumbers/StringUtils.h index c9ace10..5e61b54 100644 --- a/src/ChineseNumbers/StringUtils.h +++ b/src/ChineseNumbers/StringUtils.h @@ -1,3 +1,26 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #ifndef FCITX5_MCBOPOMOFO_STRINGUTILS_H #define FCITX5_MCBOPOMOFO_STRINGUTILS_H diff --git a/src/ChineseNumbers/SuzhouNumbers.cpp b/src/ChineseNumbers/SuzhouNumbers.cpp index 35d9ca5..a556c3d 100644 --- a/src/ChineseNumbers/SuzhouNumbers.cpp +++ b/src/ChineseNumbers/SuzhouNumbers.cpp @@ -1,3 +1,26 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #include "SuzhouNumbers.h" #include diff --git a/src/ChineseNumbers/SuzhouNumbers.h b/src/ChineseNumbers/SuzhouNumbers.h index deb5a9a..4312d73 100644 --- a/src/ChineseNumbers/SuzhouNumbers.h +++ b/src/ChineseNumbers/SuzhouNumbers.h @@ -1,3 +1,25 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. #ifndef FCITX5_MCBOPOMOFO_SUZHOUNUMBERS_H #define FCITX5_MCBOPOMOFO_SUZHOUNUMBERS_H diff --git a/src/ChineseNumbers/SuzhouNumbersTest.cpp b/src/ChineseNumbers/SuzhouNumbersTest.cpp index 80d7f9d..d80c408 100644 --- a/src/ChineseNumbers/SuzhouNumbersTest.cpp +++ b/src/ChineseNumbers/SuzhouNumbersTest.cpp @@ -1,3 +1,25 @@ +// Copyright (c) 2023 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. #include "SuzhouNumbers.h" #include "gtest/gtest.h" diff --git a/src/DictionaryService.cpp b/src/DictionaryService.cpp index 33cf3f4..e55d105 100644 --- a/src/DictionaryService.cpp +++ b/src/DictionaryService.cpp @@ -74,7 +74,7 @@ class HttpBasedDictionaryService : public McBopomofo::DictionaryService { fcitx::startProcess({"xdg-open", url}); // Since the input method launches a web browser, we just // change the state to close the candidate window. - auto empty = std::make_unique(); + auto empty = std::make_unique(); stateCallback(std::move(empty)); } diff --git a/src/InputState.cpp b/src/InputState.cpp new file mode 100644 index 0000000..d7d400e --- /dev/null +++ b/src/InputState.cpp @@ -0,0 +1,52 @@ +// Copyright (c) 2022 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +#include "InputState.h" + +namespace McBopomofo { + +InputStates::SelectingDateMacro::SelectingDateMacro( + const std::function& converter) { + std::string DateMacros[] = {"MACRO@DATE_TODAY_SHORT", + "MACRO@DATE_TODAY_MEDIUM", + "MACRO@DATE_TODAY_MEDIUM_ROC", + "MACRO@DATE_TODAY_MEDIUM_CHINESE", + "MACRO@DATE_TODAY_MEDIUM_JAPANESE", + "MACRO@THIS_YEAR_PLAIN", + "MACRO@THIS_YEAR_PLAIN_WITH_ERA", + "MACRO@THIS_YEAR_ROC", + "MACRO@THIS_YEAR_JAPANESE", + "MACRO@DATE_TODAY_WEEKDAY_SHORT", + "MACRO@DATE_TODAY_WEEKDAY", + "MACRO@DATE_TODAY2_WEEKDAY", + "MACRO@DATE_TODAY_WEEKDAY_JAPANESE", + "MACRO@TIME_NOW_SHORT", + "MACRO@TIME_NOW_MEDIUM", + "MACRO@THIS_YEAR_GANZHI", + "MACRO@THIS_YEAR_CHINESE_ZODIAC"}; + for (const std::string& macro : DateMacros) { + menu.emplace_back(converter(macro)); + } +} + +} // namespace McBopomofo \ No newline at end of file diff --git a/src/InputState.h b/src/InputState.h index fcf5e61..ae07989 100644 --- a/src/InputState.h +++ b/src/InputState.h @@ -24,6 +24,8 @@ #ifndef SRC_INPUTSTATE_H_ #define SRC_INPUTSTATE_H_ +#include +#include #include #include #include @@ -262,34 +264,11 @@ struct ChineseNumber : InputState { ChineseNumberStyle style; }; -static std::string DateMacros[] = {"MACRO@DATE_TODAY_SHORT", - "MACRO@DATE_TODAY_MEDIUM", - "MACRO@DATE_TODAY_MEDIUM_ROC", - "MACRO@DATE_TODAY_MEDIUM_CHINESE", - "MACRO@DATE_TODAY_MEDIUM_JAPANESE", - "MACRO@THIS_YEAR_PLAIN", - "MACRO@THIS_YEAR_PLAIN_WITH_ERA", - "MACRO@THIS_YEAR_ROC", - "MACRO@THIS_YEAR_JAPANESE", - "MACRO@DATE_TODAY_WEEKDAY_SHORT", - "MACRO@DATE_TODAY_WEEKDAY", - "MACRO@DATE_TODAY2_WEEKDAY", - "MACRO@DATE_TODAY_WEEKDAY_JAPANESE", - "MACRO@TIME_NOW_SHORT", - "MACRO@TIME_NOW_MEDIUM", - "MACRO@THIS_YEAR_GANZHI", - "MACRO@THIS_YEAR_CHINESE_ZODIAC"}; - struct SelectingDateMacro : InputState { - SelectingDateMacro(std::function converter) - : converter(converter) { - for (std::string macro : DateMacros) { - menu.emplace_back(converter(macro)); - } - } + explicit SelectingDateMacro( + const std::function& converter); std::vector menu; - std::function converter; }; struct SelectingFeature : InputState { @@ -301,27 +280,27 @@ struct SelectingFeature : InputState { std::function(void)> nextState; }; - SelectingFeature(std::function converter) - : converter(converter) { - features.emplace_back(std::make_unique("日期與時間", [this]() { + explicit SelectingFeature(std::function converter) + : converter(std::move(converter)) { + features.emplace_back("日期與時間", [this]() { return std::make_unique(this->converter); - })); - features.emplace_back(std::make_unique("中文數字", []() { + }); + features.emplace_back("中文數字", []() { return std::make_unique("", ChineseNumberStyle::LOWER); - })); - features.emplace_back(std::make_unique("大寫數字", []() { + }); + features.emplace_back("大寫數字", []() { return std::make_unique("", ChineseNumberStyle::UPPER); - })); - features.emplace_back(std::make_unique("蘇州碼", []() { + }); + features.emplace_back("蘇州碼", []() { return std::make_unique("", ChineseNumberStyle::SUZHOU); - })); + }); } std::unique_ptr nextState(size_t index) { - return features[index]->nextState(); + return features[index].nextState(); } - std::vector> features; + std::vector features; protected: std::function converter; diff --git a/src/Key.h b/src/Key.h index 7747d33..431b5d4 100644 --- a/src/Key.h +++ b/src/Key.h @@ -65,8 +65,7 @@ struct Key { static Key namedKey(KeyName name, bool shiftPressed = false, bool ctrlPressed = false) { return Key(0, name, shiftPressed, ctrlPressed); - } -; + }; // Regardless of the shift state. bool isCursorKeys() { return name == KeyName::LEFT || name == KeyName::RIGHT || diff --git a/src/McBopomofo.cpp b/src/McBopomofo.cpp index 2b4b479..0e3e00d 100644 --- a/src/McBopomofo.cpp +++ b/src/McBopomofo.cpp @@ -742,14 +742,14 @@ bool McBopomofoEngine::handleCandidateKeyEvent( } size_t originalCursor = 0; - auto * choosing = dynamic_cast(state_.get()); + auto* choosing = + dynamic_cast(state_.get()); if (choosing != nullptr) { originalCursor = choosing->originalCursor; } keyHandler_->candidatePanelCancelled( - originalCursor, - [this, context](std::unique_ptr next) { + originalCursor, [this, context](std::unique_ptr next) { enterNewState(context, std::move(next)); }); return true;