From 28ebc960f6136c9cdb071c9fdd73ebe9da1b5ad8 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 12 Jun 2021 19:42:04 +0530 Subject: [PATCH] src: refactor to use locale functions This makes the code more readable. Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/39014 Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau Reviewed-By: James M Snell --- src/inspector/node_string.cc | 4 ++-- src/tracing/traced_value.cc | 2 +- src/util-inl.h | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/inspector/node_string.cc b/src/inspector/node_string.cc index 0d403c66f0197b..4cb8b573cc1312 100644 --- a/src/inspector/node_string.cc +++ b/src/inspector/node_string.cc @@ -71,14 +71,14 @@ String StringViewToUtf8(v8_inspector::StringView view) { String fromDouble(double d) { std::ostringstream stream; - stream.imbue(std::locale("C")); // Ignore locale + stream.imbue(std::locale::classic()); // Ignore current locale stream << d; return stream.str(); } double toDouble(const char* buffer, size_t length, bool* ok) { std::istringstream stream(std::string(buffer, length)); - stream.imbue(std::locale("C")); // Ignore locale + stream.imbue(std::locale::classic()); // Ignore current locale double d; stream >> d; *ok = !stream.fail(); diff --git a/src/tracing/traced_value.cc b/src/tracing/traced_value.cc index dfc11658e7e4e3..662b0357a19305 100644 --- a/src/tracing/traced_value.cc +++ b/src/tracing/traced_value.cc @@ -94,7 +94,7 @@ std::string DoubleToCString(double v) { default: // This is a far less sophisticated version than the one used inside v8. std::ostringstream stream; - stream.imbue(std::locale("C")); // Ignore locale + stream.imbue(std::locale::classic()); // Ignore current locale stream << v; return stream.str(); } diff --git a/src/util-inl.h b/src/util-inl.h index 00a9f836e46a40..517da707170586 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -26,6 +26,7 @@ #include #include +#include #include "util.h" // These are defined by or on some systems. @@ -274,7 +275,7 @@ void SwapBytes64(char* data, size_t nbytes) { } char ToLower(char c) { - return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c; + return std::tolower(c, std::locale::classic()); } std::string ToLower(const std::string& in) { @@ -285,7 +286,7 @@ std::string ToLower(const std::string& in) { } char ToUpper(char c) { - return c >= 'a' && c <= 'z' ? (c - 'a') + 'A' : c; + return std::toupper(c, std::locale::classic()); } std::string ToUpper(const std::string& in) {