Skip to content

Commit

Permalink
Consider non-character as valid unicode
Browse files Browse the repository at this point in the history
Fix #1045
  • Loading branch information
wengxt committed May 8, 2024
1 parent a2a66aa commit b343fb5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/lib/fcitx-utils/cutf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
: ((Char) < 0x4000000 ? 5 : 6)))))

#define UNICODE_VALID(Char) \
((Char) < 0x110000 && (((Char) & 0xFFFFF800) != 0xD800) && \
((Char) < 0xFDD0 || (Char) > 0xFDEF) && ((Char) & 0xFFFE) != 0xFFFE)
((Char) < 0x110000 && (((Char) & 0xFFFFF800) != 0xD800))

size_t fcitx_utf8_strlen(const char *s) {
size_t l = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/lib/fcitx-utils/utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
namespace fcitx::utf8 {

bool UCS4IsValid(uint32_t code) {
return ((code) < 0x110000 && (((code) & 0xFFFFF800) != 0xD800) &&
((code) < 0xFDD0 || (code) > 0xFDEF) &&
((code) & 0xFFFE) != 0xFFFE);
return ((code) < 0x110000 && (((code) & 0xFFFFF800) != 0xD800));
}

std::string UCS4ToUTF8(uint32_t code) {
Expand Down
5 changes: 4 additions & 1 deletion test/testutf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ int main() {

FCITX_ASSERT(counter == 7);

FCITX_ASSERT(!fcitx::utf8::UCS4IsValid(0xfdd7));
FCITX_ASSERT(fcitx::utf8::UCS4IsValid(0xfdd7));
FCITX_ASSERT(fcitx::utf8::UCS4IsValid(0xffff));
FCITX_ASSERT(!fcitx::utf8::UCS4IsValid(0x200000));


return 0;
}

0 comments on commit b343fb5

Please sign in to comment.