Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some clang-tidy cleanup #1074

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/im/keyboard/compose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
*/

#include "compose.h"
#include <fcitx-utils/utf8.h>
#include <cassert>
#include <cstddef>
#include <deque>
#include <iterator>
#include <string>
#include <tuple>
#include "fcitx-utils/key.h"
#include "fcitx-utils/keysymgen.h"
#include "fcitx-utils/log.h"
#include "fcitx-utils/utf8.h"
#include "fcitx/inputcontext.h"
#include "fcitx/instance.h"

namespace fcitx {

Expand Down Expand Up @@ -101,7 +112,7 @@ bool ComposeState::typeImpl(KeySym sym, std::string &result) {
// check compose first.
auto composeResult = instance_->processComposeString(inputContext_, sym);
if (!composeResult) {
assert(composeBuffer_.size() > 0);
assert(!composeBuffer_.empty());
if (instance_->isComposing(inputContext_)) {
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/im/keyboard/compose.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#define _FCITX_IM_KEYBOARD_COMPOSE_H_

#include <deque>
#include <fcitx/instance.h>
#include <string>
#include <tuple>
#include "fcitx-utils/key.h"
#include "fcitx/instance.h"

namespace fcitx {
class ComposeState {
Expand Down
9 changes: 7 additions & 2 deletions src/im/keyboard/isocodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

#include "isocodes.h"
#include <cstring>
#include <json-c/json.h>
#include <string>
#include <json-c/json_object.h>
#include <json-c/json_types.h>
#include <json-c/json_util.h>
#include "fcitx-utils/metastring.h"
#include "fcitx-utils/misc.h"

namespace fcitx {

Expand Down Expand Up @@ -112,7 +116,8 @@ class IsoCodes3166Parser
if (!alpha2 || json_object_get_type(alpha2) != json_type_string) {
return;
}
std::string alpha_2_code, name;
std::string alpha_2_code;
std::string name;
name.assign(json_object_get_string(nameObj),
json_object_get_string_len(nameObj));
alpha_2_code.assign(json_object_get_string(alpha2),
Expand Down
2 changes: 1 addition & 1 deletion src/im/keyboard/isocodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "fcitx/misc_p.h"
#include "fcitx-utils/misc_p.h"

namespace fcitx {

Expand Down
58 changes: 44 additions & 14 deletions src/im/keyboard/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,50 @@
*/

#include "keyboard.h"
#include <algorithm>
#include <strings.h>
#include <cstddef>
#include <functional>
#include <iterator>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
#include <fmt/core.h>
#include <fmt/format.h>
#include <xkbcommon/xkbcommon.h>
#include "fcitx-config/iniparser.h"
#include "fcitx-config/rawconfig.h"
#include "fcitx-utils/capabilityflags.h"
#include "fcitx-utils/event.h"
#include "fcitx-utils/i18n.h"
#include "fcitx-utils/key.h"
#include "fcitx-utils/keysym.h"
#include "fcitx-utils/keysymgen.h"
#include "fcitx-utils/macros.h"
#include "fcitx-utils/misc.h"
#include "fcitx-utils/misc_p.h"
#include "fcitx-utils/stringutils.h"
#include "fcitx-utils/textformatflags.h"
#include "fcitx-utils/utf8.h"
#include "fcitx/candidatelist.h"
#include "fcitx/event.h"
#include "fcitx/inputcontext.h"
#include "fcitx/inputcontextmanager.h"
#include "fcitx/inputcontextproperty.h"
#include "fcitx/inputmethodentry.h"
#include "fcitx/inputpanel.h"
#include "fcitx/instance.h"
#include "fcitx/misc_p.h"
#include "fcitx/text.h"
#include "fcitx/userinterface.h"
#include "chardata.h"
#include "config.h"
#include "emoji_public.h"
#include "isocodes.h"
#include "longpress.h"
#include "notifications_public.h"
#include "quickphrase_public.h"
Expand All @@ -30,9 +60,6 @@
#include "xcb_public.h"
#endif

#include <fcitx/inputcontext.h>
#include "emoji_public.h"

const char imNamePrefix[] = "keyboard-";
#define FCITX_KEYBOARD_MAX_BUFFER 20

Expand Down Expand Up @@ -131,7 +158,7 @@ class LongPressCandidateWord : public CandidateWord {
const std::string &str() const { return text_; }

void select(InputContext *inputContext) const override {
auto state = inputContext->propertyFor(engine_->factory());
auto *state = inputContext->propertyFor(engine_->factory());
state->mode_ = CandidateMode::Hint;
// Make sure the candidate is from not from long press mode.
inputContext->inputPanel().setCandidateList(nullptr);
Expand Down Expand Up @@ -358,7 +385,7 @@ static inline bool isValidSym(const Key &key) {
static KeyList FCITX_HYPHEN_APOS = Key::keyListFromString("minus apostrophe");

bool KeyboardEngineState::updateBuffer(std::string_view chr) {
auto *entry = engine_->instance()->inputMethodEntry(inputContext_);
const auto *entry = engine_->instance()->inputMethodEntry(inputContext_);
if (!entry) {
return false;
}
Expand Down Expand Up @@ -472,7 +499,7 @@ bool KeyboardEngine::supportHint(const std::string &language) {
return hasSpell || hasEmoji;
}

void KeyboardEngineState::setPreedit() {
void KeyboardEngineState::setPreedit() const {
const bool useClientPreedit =
inputContext_->capabilityFlags().test(CapabilityFlag::Preedit);
auto preeditText = preeditString();
Expand All @@ -499,7 +526,7 @@ void KeyboardEngineState::setPreedit() {
void KeyboardEngineState::updateCandidate(const InputMethodEntry &entry) {
inputContext_->inputPanel().reset();
std::vector<std::pair<std::string, std::string>> results;
if (auto spell = engine_->spell()) {
if (auto *spell = engine_->spell()) {
results = spell->call<ISpell::hintForDisplay>(
entry.languageCode(), SpellProvider::Default, buffer_.userInput(),
engine_->config().pageSize.value());
Expand Down Expand Up @@ -540,7 +567,7 @@ void KeyboardEngine::resetState(InputContext *inputContext) {
state->reset();
}

void KeyboardEngine::deactivate(const InputMethodEntry &,
void KeyboardEngine::deactivate(const InputMethodEntry & /*entry*/,
InputContextEvent &event) {
auto *inputContext = event.inputContext();
auto *state = inputContext->propertyFor(&factory_);
Expand All @@ -556,7 +583,8 @@ void KeyboardEngine::deactivate(const InputMethodEntry &,
inputContext->updateUserInterface(UserInterfaceComponent::InputPanel);
}

void KeyboardEngine::reset(const InputMethodEntry &, InputContextEvent &event) {
void KeyboardEngine::reset(const InputMethodEntry & /*entry*/,
InputContextEvent &event) {
auto *inputContext = event.inputContext();
auto *state = inputContext->propertyFor(&factory_);
state->reset();
Expand All @@ -565,7 +593,7 @@ void KeyboardEngine::reset(const InputMethodEntry &, InputContextEvent &event) {
inputContext->updateUserInterface(UserInterfaceComponent::InputPanel);
}

void KeyboardEngine::invokeActionImpl(const InputMethodEntry &,
void KeyboardEngine::invokeActionImpl(const InputMethodEntry & /*entry*/,
InvokeActionEvent &event) {
auto *inputContext = event.inputContext();
auto *state = inputContext->propertyFor(&factory_);
Expand Down Expand Up @@ -685,7 +713,7 @@ bool KeyboardEngineState::handleLongPress(const KeyEvent &event) {
event.rawKey().states().test(KeyState::Repeat) &&
*engine_->config().enableLongPress &&
!engine_->isBlockedForLongPress(inputContext->program())) {
if (auto results = findValue(engine_->longPressData(), keystr)) {
if (const auto *results = findValue(engine_->longPressData(), keystr)) {
if (repeatStarted_) {
return true;
}
Expand Down Expand Up @@ -752,7 +780,8 @@ bool KeyboardEngineState::handleSpellModeTrigger(const InputMethodEntry &entry,
return false;
}

bool KeyboardEngineState::handleCandidateSelection(const KeyEvent &event) {
bool KeyboardEngineState::handleCandidateSelection(
const KeyEvent &event) const {
// check if we can select candidate.
auto candList = inputContext_->inputPanel().candidateList();
if (!candList) {
Expand Down Expand Up @@ -821,7 +850,8 @@ std::string KeyboardEngineState::currentSelection() const {
}
}
return buffer_.userInput();
} else if (mode_ == CandidateMode::LongPress) {
}
if (mode_ == CandidateMode::LongPress) {
if (candidateList && candidateList->cursorIndex() >= 0) {
if (const auto *candidate =
dynamic_cast<const LongPressCandidateWord *>(
Expand Down
23 changes: 19 additions & 4 deletions src/im/keyboard/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,32 @@
#ifndef _FCITX_IM_KEYBOARD_KEYBOARD_H_
#define _FCITX_IM_KEYBOARD_KEYBOARD_H_

#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "fcitx-config/configuration.h"
#include "fcitx-config/enum.h"
#include "fcitx-config/iniparser.h"
#include "fcitx-config/option.h"
#include "fcitx-config/rawconfig.h"
#include "fcitx-utils/event.h"
#include "fcitx-utils/handlertable.h"
#include "fcitx-utils/i18n.h"
#include "fcitx-utils/inputbuffer.h"
#include "fcitx-utils/key.h"
#include "fcitx/addonfactory.h"
#include "fcitx/addoninstance.h"
#include "fcitx/addonmanager.h"
#include "fcitx/event.h"
#include "fcitx/inputcontextproperty.h"
#include "fcitx/inputmethodengine.h"
#include "fcitx/instance.h"
#include "compose.h"
#include "isocodes.h"
#include "keyboard_public.h"
#include "longpress.h"
#include "quickphrase_public.h"
Expand Down Expand Up @@ -112,7 +126,7 @@ struct KeyboardEngineState : public InputContextProperty {
bool handleLongPress(const KeyEvent &event);
bool handleSpellModeTrigger(const InputMethodEntry &entry,
const KeyEvent &event);
bool handleCandidateSelection(const KeyEvent &event);
bool handleCandidateSelection(const KeyEvent &event) const;
std::tuple<std::string, bool> handleCompose(const KeyEvent &event);
bool handleBackspace(const InputMethodEntry &entry);

Expand All @@ -125,7 +139,7 @@ struct KeyboardEngineState : public InputContextProperty {

void updateCandidate(const InputMethodEntry &entry);
// Update preedit and send ui update.
void setPreedit();
void setPreedit() const;

// Return true if chr is pushed to buffer.
// Return false if chr will be skipped by buffer, usually this means caller
Expand All @@ -152,7 +166,8 @@ class KeyboardEngine final : public InputMethodEngineV3 {

const Configuration *getSubConfig(const std::string &path) const override;

void setSubConfig(const std::string &, const fcitx::RawConfig &) override;
void setSubConfig(const std::string & /*unused*/,
const fcitx::RawConfig & /*unused*/) override;

void reset(const InputMethodEntry &entry,
InputContextEvent &event) override;
Expand Down
2 changes: 2 additions & 0 deletions src/im/keyboard/keyboard_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define _FCITX_IM_KEYBOARD_KEYBOARD_PUBLIC_H_

#include <functional>
#include <string>
#include <vector>
#include <fcitx/addoninstance.h>

FCITX_ADDON_DECLARE_FUNCTION(
Expand Down
7 changes: 6 additions & 1 deletion src/im/keyboard/longpress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/
#include "longpress.h"
#include <list>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

namespace fcitx {

Expand Down Expand Up @@ -132,7 +137,7 @@ void setupDefaultLongPressConfig(LongPressConfig &config) {
{"$", {"¢", "€", "£", "¥", "₹", "₽", "₺", "₩", "₱", "₿"}},
};
{
auto value = config.entries.mutableValue();
auto *value = config.entries.mutableValue();
for (const auto &[key, candidates] : data) {
LongPressEntryConfig entry;
entry.key.setValue(key);
Expand Down
4 changes: 4 additions & 0 deletions src/im/keyboard/longpress.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#ifndef _FCITX5_IM_KEYBOARD_LONGPRESSDATA_H_
#define _FCITX5_IM_KEYBOARD_LONGPRESSDATA_H_

#include <string>
#include <unordered_map>
#include <vector>
#include "fcitx-config/configuration.h"
#include "fcitx-config/option.h"
#include "fcitx-utils/i18n.h"

namespace fcitx {
Expand Down
23 changes: 15 additions & 8 deletions src/im/keyboard/xkbrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
*/

#include "xkbrules.h"
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <initializer_list>
#include <iterator>
#include <list>
#include <string>
#include <utility>
#include <vector>
#include "fcitx-utils/stringutils.h"
#include "xmlparser.h"

Expand All @@ -34,8 +41,8 @@ struct XkbRulesParseState : public XMLParser {
array.begin());
}

void startElement(const XML_Char *name, const XML_Char **attrs) override {
parseStack_.emplace_back(reinterpret_cast<const char *>(name));
void startElement(const char *name, const char **attrs) override {
parseStack_.emplace_back(std::string(name));
textBuff_.clear();

if (match({"layoutList", "layout", "configItem"})) {
Expand All @@ -46,8 +53,8 @@ struct XkbRulesParseState : public XMLParser {
modelInfos_.emplace_back();
} else if (match({"optionList", "group"})) {
optionGroupInfos_.emplace_back();
int i = 0;
while (attrs && attrs[i * 2] != 0) {
ptrdiff_t i = 0;
while (attrs && attrs[i * 2] != nullptr) {
if (strcmp(reinterpret_cast<const char *>(attrs[i * 2]),
"allowMultipleSelection") == 0) {
optionGroupInfos_.back().exclusive =
Expand All @@ -60,8 +67,8 @@ struct XkbRulesParseState : public XMLParser {
} else if (match({"optionList", "group", "option"})) {
optionGroupInfos_.back().optionInfos.emplace_back();
} else if (match({"xkbConfigRegistry"})) {
int i = 0;
while (attrs && attrs[i * 2] != 0) {
ptrdiff_t i = 0;
while (attrs && attrs[i * 2] != nullptr) {
if (strcmp(reinterpret_cast<const char *>(attrs[i * 2]),
"version") == 0 &&
strlen(reinterpret_cast<const char *>(attrs[i * 2 + 1])) !=
Expand All @@ -72,7 +79,7 @@ struct XkbRulesParseState : public XMLParser {
}
}
}
void endElement(const XML_Char *) override {
void endElement(const char * /*name*/) override {
auto text = stringutils::trimView(textBuff_);
if (!text.empty()) {
if (match({"layoutList", "layout", "configItem", "name"})) {
Expand Down Expand Up @@ -123,7 +130,7 @@ struct XkbRulesParseState : public XMLParser {
textBuff_.clear();
parseStack_.pop_back();
}
void characterData(const XML_Char *ch, int len) override {
void characterData(const char *ch, int len) override {
textBuff_.append(reinterpret_cast<const char *>(ch), len);
}

Expand Down
Loading
Loading