Skip to content

Commit

Permalink
fix: libcxx 19 removes std::char_traits<uint32_t> (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Weng Xuetian <[email protected]>
  • Loading branch information
eagleoflqj and wengxt authored Jan 17, 2025
1 parent ce5a418 commit f1fe6bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ std::string ustringToUTF8(const UString &ustr) {
return result;
}

UString ucsToUString(const ucschar *str) {
UString result;
while (*str) {
result += *str++;
}
return result;
}

std::string subUTF8String(const std::string &str, int p1, int p2) {
int limit;
int pos;
Expand Down Expand Up @@ -163,7 +171,7 @@ class HangulState : public InputContextProperty {

const auto *hic_preedit = hangul_ic_get_preedit_string(context_.get());
UString preedit = preedit_;
preedit.append(UString(hic_preedit));
preedit.append(ucsToUString(hic_preedit));
if (!preedit.empty()) {
auto utf8 = ustringToUTF8(preedit);
if (*engine_->config().wordCommit || *engine_->config().hanjaMode) {
Expand Down Expand Up @@ -395,10 +403,8 @@ class HangulState : public InputContextProperty {
const ucschar *hic_preedit;

hic_preedit = hangul_ic_get_preedit_string(context_.get());
if (hic_preedit != nullptr && hic_preedit[0] != 0) {
preedit_.append(UString(str));
} else {
preedit_.append(UString(str));
preedit_.append(ucsToUString(str));
if (hic_preedit == nullptr || hic_preedit[0] == 0) {
if (!preedit_.empty()) {
auto commit = ustringToUTF8(preedit_);
if (!commit.empty()) {
Expand All @@ -409,7 +415,7 @@ class HangulState : public InputContextProperty {
}
} else {
if (str != nullptr && str[0] != 0) {
auto commit = ustringToUTF8(str);
auto commit = ustringToUTF8(ucsToUString(str));
if (!commit.empty()) {
ic_->commitString(commit);
}
Expand Down Expand Up @@ -447,7 +453,7 @@ class HangulState : public InputContextProperty {

const auto *str = hangul_ic_flush(context_.get());

preedit_ += str;
preedit_ += ucsToUString(str);

if (preedit_.empty()) {
return;
Expand All @@ -470,7 +476,7 @@ class HangulState : public InputContextProperty {
std::string pre1 = ustringToUTF8(preedit_);
std::string pre2;
if (hic_preedit) {
pre2 = ustringToUTF8(hic_preedit);
pre2 = ustringToUTF8(ucsToUString(hic_preedit));
}

if (!pre1.empty() || !pre2.empty()) {
Expand Down Expand Up @@ -534,7 +540,7 @@ class HangulState : public InputContextProperty {

key_len = fcitx::utf8::length(std::string(key));
preedit_len = preedit_.size();
hic_preedit_len = UString(hic_preedit).size();
hic_preedit_len = ucsToUString(hic_preedit).size();

bool surrounding = false;
if (lastLookupMethod_ == LookupMethod::LOOKUP_METHOD_PREFIX) {
Expand Down
4 changes: 3 additions & 1 deletion src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ enum class LookupMethod : uint8_t {

class HangulState;

using UString = std::basic_string<uint32_t>;
using UString = std::basic_string<char32_t>;

UString ucsToUString(const ucschar *c);

class HangulEngine : public InputMethodEngine {
public:
Expand Down

0 comments on commit f1fe6bb

Please sign in to comment.