Skip to content

Commit e610cd9

Browse files
committed
Cleanup clang-tidy issues
1 parent 675107b commit e610cd9

File tree

3 files changed

+64
-26
lines changed

3 files changed

+64
-26
lines changed

src/bamboo.cpp

+48-25
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@
66
*/
77

88
#include "bamboo.h"
9+
#include "bambooconfig.h"
10+
#include <algorithm>
11+
#include <cstdint>
12+
#include <cstdlib>
913
#include <fcitx-config/iniparser.h>
14+
#include <fcitx-config/rawconfig.h>
15+
#include <fcitx-utils/capabilityflags.h>
1016
#include <fcitx-utils/charutils.h>
17+
#include <fcitx-utils/i18n.h>
1118
#include <fcitx-utils/keysymgen.h>
19+
#include <fcitx-utils/log.h>
20+
#include <fcitx-utils/macros.h>
21+
#include <fcitx-utils/misc.h>
1222
#include <fcitx-utils/standardpath.h>
23+
#include <fcitx-utils/stringutils.h>
1324
#include <fcitx-utils/textformatflags.h>
1425
#include <fcitx-utils/utf8.h>
26+
#include <fcitx/action.h>
27+
#include <fcitx/addoninstance.h>
28+
#include <fcitx/event.h>
1529
#include <fcitx/inputcontext.h>
1630
#include <fcitx/inputcontextmanager.h>
31+
#include <fcitx/inputmethodentry.h>
1732
#include <fcitx/inputpanel.h>
1833
#include <fcitx/menu.h>
1934
#include <fcitx/statusarea.h>
35+
#include <fcitx/text.h>
2036
#include <fcitx/userinterface.h>
2137
#include <fcitx/userinterfacemanager.h>
2238
#include <fcntl.h>
39+
#include <memory>
2340
#include <optional>
2441
#include <stdexcept>
42+
#include <string>
43+
#include <string_view>
44+
#include <utility>
45+
#include <vector>
2546

2647
namespace fcitx {
2748

@@ -32,6 +53,8 @@ constexpr std::string_view InputMethodActionPrefix = "bamboo-input-method-";
3253
constexpr std::string_view CharsetActionPrefix = "bamboo-charset-";
3354
const std::string CustomKeymapFile = "conf/bamboo-custom-keymap.conf";
3455

56+
FCITX_DEFINE_LOG_CATEGORY(bamboo, "bamboo");
57+
3558
std::string macroFile(std::string_view imName) {
3659
return stringutils::concat("conf/bamboo-macro-", imName, ".conf");
3760
}
@@ -48,9 +71,18 @@ uintptr_t newMacroTable(const BambooMacroTable &macroTable) {
4871
return NewMacroTable(charArray.data());
4972
}
5073

74+
std::vector<std::string> convertToStringList(char **array) {
75+
std::vector<std::string> result;
76+
for (int i = 0; array[i]; i++) {
77+
result.push_back(array[i]);
78+
free(array[i]);
79+
}
80+
free(array);
81+
return result;
82+
}
83+
5184
} // namespace
5285

53-
FCITX_DEFINE_LOG_CATEGORY(bamboo, "bamboo");
5486
#define FCITX_BAMBOO_DEBUG() FCITX_LOGC(bamboo, Debug)
5587

5688
class BambooState final : public InputContextProperty {
@@ -117,7 +149,8 @@ class BambooState final : public InputContextProperty {
117149

118150
if (keyEvent.key().checkKeyList(*engine_->config().restoreKeyStroke)) {
119151
EngineSetRestoreKeyStroke(bambooEngine_.handle());
120-
return keyEvent.filterAndAccept();
152+
keyEvent.filterAndAccept();
153+
return;
121154
}
122155

123156
if (EngineProcessKeyEvent(bambooEngine_.handle(),
@@ -189,16 +222,6 @@ class BambooState final : public InputContextProperty {
189222
CGoObject bambooEngine_;
190223
};
191224

192-
std::vector<std::string> convertToStringList(char **array) {
193-
std::vector<std::string> result;
194-
for (int i = 0; array[i]; i++) {
195-
result.push_back(array[i]);
196-
free(array[i]);
197-
}
198-
free(array);
199-
return result;
200-
}
201-
202225
BambooEngine::BambooEngine(Instance *instance)
203226
: instance_(instance), factory_([this](InputContext &ic) {
204227
return new BambooState(this, &ic);
@@ -233,7 +256,7 @@ BambooEngine::BambooEngine(Instance *instance)
233256
inputMethodAction_->setMenu(inputMethodMenu_.get());
234257
for (const auto &imName : imNames_) {
235258
inputMethodSubAction_.emplace_back(std::make_unique<SimpleAction>());
236-
auto action = inputMethodSubAction_.back().get();
259+
auto *action = inputMethodSubAction_.back().get();
237260
action->setShortText(imName);
238261
action->setCheckable(true);
239262
uiManager.registerAction(
@@ -262,7 +285,7 @@ BambooEngine::BambooEngine(Instance *instance)
262285
auto charsets = convertToStringList(GetCharsetNames());
263286
for (const auto &charset : charsets) {
264287
charsetSubAction_.emplace_back(std::make_unique<SimpleAction>());
265-
auto action = charsetSubAction_.back().get();
288+
auto *action = charsetSubAction_.back().get();
266289
action->setShortText(charset);
267290
action->setCheckable(true);
268291
connections_.emplace_back(action->connect<SimpleAction::Activated>(
@@ -324,13 +347,13 @@ void BambooEngine::reloadConfig() {
324347
const Configuration *BambooEngine::getSubConfig(const std::string &path) const {
325348
if (path == "custom_keymap") {
326349
return &customKeymap_;
327-
} else if (stringutils::startsWith(path, MacroPrefix)) {
350+
}
351+
if (stringutils::startsWith(path, MacroPrefix)) {
328352
const auto imName = path.substr(MacroPrefix.size());
329353
if (auto iter = macroTables_.find(imName); iter != macroTables_.end()) {
330354
return &iter->second;
331-
} else {
332-
return nullptr;
333355
}
356+
return nullptr;
334357
}
335358
return nullptr;
336359
}
@@ -367,8 +390,8 @@ void BambooEngine::setSubConfig(const std::string &path,
367390
}
368391
}
369392

370-
std::string BambooEngine::subMode(const fcitx::InputMethodEntry &,
371-
fcitx::InputContext &) {
393+
std::string BambooEngine::subMode(const fcitx::InputMethodEntry & /*entry*/,
394+
fcitx::InputContext & /*inputContext*/) {
372395
return *config_.inputMethod;
373396
}
374397

@@ -392,7 +415,7 @@ void BambooEngine::activate(const InputMethodEntry &entry,
392415
void BambooEngine::deactivate(const InputMethodEntry &entry,
393416
InputContextEvent &event) {
394417
FCITX_UNUSED(entry);
395-
auto state = event.inputContext()->propertyFor(&factory_);
418+
auto *state = event.inputContext()->propertyFor(&factory_);
396419
if (event.type() != EventType::InputContextFocusOut) {
397420
state->commitBuffer();
398421
} else {
@@ -402,15 +425,15 @@ void BambooEngine::deactivate(const InputMethodEntry &entry,
402425

403426
void BambooEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &keyEvent) {
404427
FCITX_UNUSED(entry);
405-
auto state = keyEvent.inputContext()->propertyFor(&factory_);
428+
auto *state = keyEvent.inputContext()->propertyFor(&factory_);
406429

407430
state->keyEvent(keyEvent);
408431
}
409432

410433
void BambooEngine::reset(const InputMethodEntry &entry,
411434
InputContextEvent &event) {
412435
FCITX_UNUSED(entry);
413-
auto state = event.inputContext()->propertyFor(&factory_);
436+
auto *state = event.inputContext()->propertyFor(&factory_);
414437
state->reset();
415438
}
416439

@@ -421,7 +444,7 @@ void BambooEngine::refreshEngine() {
421444
}
422445

423446
instance_->inputContextManager().foreach([this](InputContext *ic) {
424-
auto state = ic->propertyFor(&factory_);
447+
auto *state = ic->propertyFor(&factory_);
425448
state->setEngine();
426449
if (ic->hasFocus()) {
427450
state->reset();
@@ -435,7 +458,7 @@ void BambooEngine::refreshOption() {
435458
return;
436459
}
437460
instance_->inputContextManager().foreach([this](InputContext *ic) {
438-
auto state = ic->propertyFor(&factory_);
461+
auto *state = ic->propertyFor(&factory_);
439462
state->setOption();
440463
if (ic->hasFocus()) {
441464
state->reset();
@@ -487,4 +510,4 @@ void BambooEngine::updateCharsetAction(InputContext *ic) {
487510

488511
} // namespace fcitx
489512

490-
FCITX_ADDON_FACTORY(fcitx::BambooFactory)
513+
FCITX_ADDON_FACTORY_V2(bamboo, fcitx::BambooFactory)

src/bamboo.h

+9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@
99

1010
#include "bamboo-core.h"
1111
#include "bambooconfig.h"
12+
#include <cstdint>
1213
#include <fcitx-config/iniparser.h>
14+
#include <fcitx-config/rawconfig.h>
1315
#include <fcitx-utils/i18n.h>
16+
#include <fcitx-utils/signals.h>
1417
#include <fcitx/action.h>
1518
#include <fcitx/addonfactory.h>
19+
#include <fcitx/addoninstance.h>
1620
#include <fcitx/addonmanager.h>
21+
#include <fcitx/event.h>
1722
#include <fcitx/inputcontextproperty.h>
1823
#include <fcitx/inputmethodengine.h>
1924
#include <fcitx/instance.h>
25+
#include <memory>
26+
#include <optional>
2027
#include <string>
28+
#include <unordered_map>
29+
#include <vector>
2130

2231
namespace fcitx {
2332

src/bambooconfig.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
#ifndef _FCITX5_BAMBOO_BAMBOOCONFIG_H_
88
#define _FCITX5_BAMBOO_BAMBOOCONFIG_H_
99

10+
#include <algorithm>
11+
#include <cstddef>
1012
#include <fcitx-config/configuration.h>
1113
#include <fcitx-config/option.h>
14+
#include <fcitx-config/rawconfig.h>
1215
#include <fcitx-utils/i18n.h>
1316
#include <fcitx-utils/stringutils.h>
17+
#include <string>
18+
#include <utility>
19+
#include <vector>
1420

1521
namespace fcitx {
1622

@@ -60,7 +66,7 @@ struct InputMethodConstrain {
6066
}
6167
return std::find(list.begin(), list.end(), name) != list.end();
6268
}
63-
void dumpDescription(RawConfig &) const {}
69+
void dumpDescription(RawConfig & /*unused*/) const {}
6470

6571
protected:
6672
const InputMethodOption *option_;

0 commit comments

Comments
 (0)