Skip to content

Commit

Permalink
feat: check wchar_t size
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed May 17, 2024
1 parent baab5dc commit 22e6271
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions include/parser/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,17 @@ inline std::optional<string_t> parser<string_t, parsing_t, accel_traits>::parse_
}
}
else if constexpr (std::is_same_v<typename string_t::value_type, wchar_t>) {
if (ext_cp <= 0xFFFF) {
result.push_back(static_cast<uint16_t>(ext_cp));
if constexpr (sizeof (wchar_t) == 4) {
result.push_back(static_cast<wchar_t>(ext_cp));
} else if constexpr (sizeof (wchar_t) == 2) {
if (ext_cp <= 0xFFFF) {
result.push_back(static_cast<wchar_t>(ext_cp));
} else {
result.push_back(static_cast<wchar_t>(hi_cp));
result.push_back(static_cast<wchar_t>(lo_cp));
}
} else {
result.push_back(hi_cp);
result.push_back(lo_cp);
static_assert(!sizeof(typename string_t::value_type), "Unsupported wchar");
}
}
else {
Expand Down

0 comments on commit 22e6271

Please sign in to comment.