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

Support char8_t on C++20 #289

Merged
merged 1 commit into from
Nov 23, 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int main() {
std::cerr << "parsing failure\n";
return EXIT_FAILURE;
}
std::cout << "parsed the number "<< i << std::endl;
std::cout << "parsed the number " << i << std::endl;

std::string binstr = "1001111000011001110110111001001010110100111000110001100";

Expand All @@ -158,7 +158,7 @@ int main() {
std::cerr << "parsing failure\n";
return EXIT_FAILURE;
}
std::cout << "parsed the number "<< i << std::endl;
std::cout << "parsed the number " << i << std::endl;

std::string hexstr = "4f0cedc95a718c";

Expand All @@ -167,7 +167,7 @@ int main() {
std::cerr << "parsing failure\n";
return EXIT_FAILURE;
}
std::cout << "parsed the number "<< i << std::endl;
std::cout << "parsed the number " << i << std::endl;
return EXIT_SUCCESS;
}
```
Expand Down
17 changes: 16 additions & 1 deletion include/fast_float/float_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ struct is_supported_char_type
: std::integral_constant<bool, std::is_same<UC, char>::value ||
std::is_same<UC, wchar_t>::value ||
std::is_same<UC, char16_t>::value ||
std::is_same<UC, char32_t>::value> {};
std::is_same<UC, char32_t>::value
#ifdef __cpp_char8_t
|| std::is_same<UC, char8_t>::value
#endif
> {
};

// Compares two ASCII strings in a case insensitive manner.
template <typename UC>
Expand Down Expand Up @@ -748,6 +753,11 @@ template <> constexpr char16_t const *str_const_nan<char16_t>() {
template <> constexpr char32_t const *str_const_nan<char32_t>() {
return U"nan";
}
#ifdef __cpp_char8_t
template <> constexpr char8_t const *str_const_nan<char8_t>() {
return u8"nan";
}
#endif

template <typename UC> constexpr UC const *str_const_inf();
template <> constexpr char const *str_const_inf<char>() { return "infinity"; }
Expand All @@ -760,6 +770,11 @@ template <> constexpr char16_t const *str_const_inf<char16_t>() {
template <> constexpr char32_t const *str_const_inf<char32_t>() {
return U"infinity";
}
#ifdef __cpp_char8_t
template <> constexpr char8_t const *str_const_inf<char8_t>() {
return u8"infinity";
}
#endif

template <typename = void> struct int_luts {
static constexpr uint8_t chdigit[] = {
Expand Down