Skip to content

Commit

Permalink
Fixes CPP coding style.
Browse files Browse the repository at this point in the history
  • Loading branch information
zonble committed Feb 12, 2024
1 parent 92e4660 commit ffc0f61
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(MCBOPOMOFO_LIB_SOURCES
KeyHandler.cpp
LanguageModelLoader.cpp
UTF8Helper.cpp
InputState.cpp
InputMacro.cpp
Log.cpp
DictionaryService.cpp
Expand Down
23 changes: 23 additions & 0 deletions src/ChineseNumbers/ChineseNumbers.cpp
Original file line number Diff line number Diff line change
@@ -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 <cmath>
Expand Down
23 changes: 23 additions & 0 deletions src/ChineseNumbers/ChineseNumbers.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 23 additions & 0 deletions src/ChineseNumbers/ChineseNumbersTest.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
22 changes: 22 additions & 0 deletions src/ChineseNumbers/StringUtils.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
23 changes: 23 additions & 0 deletions src/ChineseNumbers/StringUtils.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 23 additions & 0 deletions src/ChineseNumbers/SuzhouNumbers.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
Expand Down
22 changes: 22 additions & 0 deletions src/ChineseNumbers/SuzhouNumbers.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/ChineseNumbers/SuzhouNumbersTest.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/DictionaryService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<McBopomofo::InputStates::Empty>();
auto empty = std::make_unique<McBopomofo::InputStates::Empty>();
stateCallback(std::move(empty));
}

Expand Down
52 changes: 52 additions & 0 deletions src/InputState.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string(std::string)>& 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
53 changes: 16 additions & 37 deletions src/InputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef SRC_INPUTSTATE_H_
#define SRC_INPUTSTATE_H_

#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
Expand Down Expand Up @@ -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<std::string(std::string)> converter)
: converter(converter) {
for (std::string macro : DateMacros) {
menu.emplace_back(converter(macro));
}
}
explicit SelectingDateMacro(
const std::function<std::string(std::string)>& converter);

std::vector<std::string> menu;
std::function<std::string(std::string)> converter;
};

struct SelectingFeature : InputState {
Expand All @@ -301,27 +280,27 @@ struct SelectingFeature : InputState {
std::function<std::unique_ptr<InputState>(void)> nextState;
};

SelectingFeature(std::function<std::string(std::string)> converter)
: converter(converter) {
features.emplace_back(std::make_unique<Feature>("日期與時間", [this]() {
explicit SelectingFeature(std::function<std::string(std::string)> converter)
: converter(std::move(converter)) {
features.emplace_back("日期與時間", [this]() {
return std::make_unique<SelectingDateMacro>(this->converter);
}));
features.emplace_back(std::make_unique<Feature>("中文數字", []() {
});
features.emplace_back("中文數字", []() {
return std::make_unique<ChineseNumber>("", ChineseNumberStyle::LOWER);
}));
features.emplace_back(std::make_unique<Feature>("大寫數字", []() {
});
features.emplace_back("大寫數字", []() {
return std::make_unique<ChineseNumber>("", ChineseNumberStyle::UPPER);
}));
features.emplace_back(std::make_unique<Feature>("蘇州碼", []() {
});
features.emplace_back("蘇州碼", []() {
return std::make_unique<ChineseNumber>("", ChineseNumberStyle::SUZHOU);
}));
});
}

std::unique_ptr<InputState> nextState(size_t index) {
return features[index]->nextState();
return features[index].nextState();
}

std::vector<std::unique_ptr<Feature>> features;
std::vector<Feature> features;

protected:
std::function<std::string(std::string)> converter;
Expand Down
3 changes: 1 addition & 2 deletions src/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
6 changes: 3 additions & 3 deletions src/McBopomofo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,14 @@ bool McBopomofoEngine::handleCandidateKeyEvent(
}

size_t originalCursor = 0;
auto * choosing = dynamic_cast<InputStates::ChoosingCandidate*>(state_.get());
auto* choosing =
dynamic_cast<InputStates::ChoosingCandidate*>(state_.get());
if (choosing != nullptr) {
originalCursor = choosing->originalCursor;
}

keyHandler_->candidatePanelCancelled(
originalCursor,
[this, context](std::unique_ptr<InputState> next) {
originalCursor, [this, context](std::unique_ptr<InputState> next) {
enterNewState(context, std::move(next));
});
return true;
Expand Down

0 comments on commit ffc0f61

Please # to comment.