|
16 | 16 | #include <fcitx-utils/charutils.h> |
17 | 17 | #include <fcitx-utils/key.h> |
18 | 18 | #include <fcitx-utils/keysym.h> |
| 19 | +#include <fcitx-utils/stringutils.h> |
19 | 20 | #include <fcitx-utils/utf8.h> |
20 | 21 | #include <fcitx/event.h> |
21 | 22 | #include <fcitx/inputmethodmanager.h> |
22 | 23 | #include <fcitx/instance.h> |
23 | 24 | #include <string> |
| 25 | +#include <string_view> |
24 | 26 | #include <vector> |
25 | 27 |
|
26 | 28 | Key2KanaConvertor::Key2KanaConvertor(AnthyState &anthy, |
@@ -150,9 +152,9 @@ bool CheckLayout(fcitx::Instance *instance) { |
150 | 152 | return layout == "jp" || layout.starts_with("jp-"); |
151 | 153 | } |
152 | 154 |
|
153 | | -bool Key2KanaConvertor::append(const std::string &str, std::string &result, |
| 155 | +bool Key2KanaConvertor::append(std::string_view str, std::string &result, |
154 | 156 | std::string &pending) { |
155 | | - std::string matching_str = pending_ + str; |
| 157 | + std::string matching_str = fcitx::stringutils::concat(pending_, str); |
156 | 158 | Key2KanaRule exact_match; |
157 | 159 | bool has_partial_match = false; |
158 | 160 | bool retval = false; |
@@ -293,19 +295,18 @@ void Key2KanaConvertor::resetPending(const std::string & /*result*/, |
293 | 295 | const std::string &raw) { |
294 | 296 | lastKey_ = fcitx::Key(); |
295 | 297 |
|
296 | | - for (unsigned int i = 0; i < fcitx::utf8::length(raw); i++) { |
| 298 | + for (auto chr : fcitx::utf8::MakeUTF8StringViewRange(raw)) { |
297 | 299 | std::string res; |
298 | 300 | std::string pend; |
299 | | - append(util::utf8_string_substr(raw, i, 1), res, pend); |
| 301 | + append(chr, res, pend); |
300 | 302 | } |
301 | 303 | } |
302 | 304 |
|
303 | | -bool Key2KanaConvertor::processPseudoAsciiMode(const std::string &wstr) { |
304 | | - for (unsigned int i = 0; i < wstr.length(); i++) { |
305 | | - if (fcitx::charutils::isupper(wstr[i]) || |
306 | | - fcitx::charutils::isspace(wstr[i])) { |
| 305 | +bool Key2KanaConvertor::processPseudoAsciiMode(std::string_view wstr) { |
| 306 | + for (auto chr : wstr) { |
| 307 | + if (fcitx::charutils::isupper(chr) || fcitx::charutils::isspace(chr)) { |
307 | 308 | isInPseudoAsciiMode_ = true; |
308 | | - } else if (wstr[i] & 0x80) { |
| 309 | + } else if (chr & 0x80) { |
309 | 310 | isInPseudoAsciiMode_ = false; |
310 | 311 | } |
311 | 312 | } |
|
0 commit comments