mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
src: add enum handle for ToStringHelper + formatting
Fixes: https://github.com/nodejs/node/issues/56666 PR-URL: https://github.com/nodejs/node/pull/56829 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
79d0ed77e5
commit
4e9e5a183c
|
|
@ -38,9 +38,11 @@ struct ToStringHelper {
|
|||
|
||||
template <typename T,
|
||||
typename test_for_number = typename std::
|
||||
enable_if<std::is_arithmetic<T>::value, bool>::type,
|
||||
enable_if_t<std::is_arithmetic_v<T> || std::is_enum_v<T>, bool>,
|
||||
typename dummy = bool>
|
||||
static std::string Convert(const T& value) { return std::to_string(value); }
|
||||
static std::string Convert(const T& value) {
|
||||
return std::to_string(value);
|
||||
}
|
||||
static std::string_view Convert(const char* value) {
|
||||
return value != nullptr ? value : "(null)";
|
||||
}
|
||||
|
|
@ -58,8 +60,7 @@ struct ToStringHelper {
|
|||
const char* digits = "0123456789abcdef";
|
||||
do {
|
||||
unsigned digit = v & ((1 << BASE_BITS) - 1);
|
||||
*--ptr =
|
||||
(BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
|
||||
*--ptr = (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
|
||||
} while ((v >>= BASE_BITS) != 0);
|
||||
return ptr;
|
||||
}
|
||||
|
|
@ -139,12 +140,10 @@ std::string COLD_NOINLINE SPrintFImpl( // NOLINT(runtime/string)
|
|||
ret += node::ToUpper(ToBaseString<4>(arg));
|
||||
break;
|
||||
case 'p': {
|
||||
CHECK(std::is_pointer<typename std::remove_reference<Arg>::type>::value);
|
||||
CHECK(std::is_pointer_v<typename std::remove_reference_t<Arg>>);
|
||||
char out[20];
|
||||
int n = snprintf(out,
|
||||
sizeof(out),
|
||||
"%p",
|
||||
*reinterpret_cast<const void* const*>(&arg));
|
||||
int n = snprintf(
|
||||
out, sizeof(out), "%p", *reinterpret_cast<const void* const*>(&arg));
|
||||
CHECK_GE(n, 0);
|
||||
ret += out;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user