mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
* fix unreachable code warning when <charconv> header is present * update macro name
This commit is contained in:
parent
b5ee8c19df
commit
3d68799d9c
11
peglib.h
11
peglib.h
@ -13,6 +13,9 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#if __has_include(<charconv>)
|
#if __has_include(<charconv>)
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
#define CPPPEGLIB_HAS_CHARCONV true
|
||||||
|
#else
|
||||||
|
#define CPPPEGLIB_HAS_CHARCONV false
|
||||||
#endif
|
#endif
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -340,15 +343,13 @@ inline std::string resolve_escape_sequence(const char *s, size_t n) {
|
|||||||
|
|
||||||
template <typename T> T token_to_number_(std::string_view sv) {
|
template <typename T> T token_to_number_(std::string_view sv) {
|
||||||
T n = 0;
|
T n = 0;
|
||||||
#if __has_include(<charconv>)
|
if constexpr (CPPPEGLIB_HAS_CHARCONV && !std::is_floating_point<T>::value) {
|
||||||
if constexpr (!std::is_floating_point<T>::value) {
|
|
||||||
std::from_chars(sv.data(), sv.data() + sv.size(), n);
|
std::from_chars(sv.data(), sv.data() + sv.size(), n);
|
||||||
return n;
|
} else {
|
||||||
}
|
|
||||||
#endif
|
|
||||||
auto s = std::string(sv);
|
auto s = std::string(sv);
|
||||||
std::istringstream ss(s);
|
std::istringstream ss(s);
|
||||||
ss >> n;
|
ss >> n;
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user