Skip to content

Commit dcfb182

Browse files
RaisinTenrichardlau
authored andcommitted
src: refactor to use locale functions
This makes the code more readable. Signed-off-by: Darshan Sen <raisinten@gmail.com> PR-URL: #39014 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 797bd73 commit dcfb182

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/inspector/node_string.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ String StringViewToUtf8(v8_inspector::StringView view) {
7171

7272
String fromDouble(double d) {
7373
std::ostringstream stream;
74-
stream.imbue(std::locale("C")); // Ignore locale
74+
stream.imbue(std::locale::classic()); // Ignore current locale
7575
stream << d;
7676
return stream.str();
7777
}
7878

7979
double toDouble(const char* buffer, size_t length, bool* ok) {
8080
std::istringstream stream(std::string(buffer, length));
81-
stream.imbue(std::locale("C")); // Ignore locale
81+
stream.imbue(std::locale::classic()); // Ignore current locale
8282
double d;
8383
stream >> d;
8484
*ok = !stream.fail();

src/tracing/traced_value.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::string DoubleToCString(double v) {
9494
default:
9595
// This is a far less sophisticated version than the one used inside v8.
9696
std::ostringstream stream;
97-
stream.imbue(std::locale("C")); // Ignore locale
97+
stream.imbue(std::locale::classic()); // Ignore current locale
9898
stream << v;
9999
return stream.str();
100100
}

src/util-inl.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <cmath>
2828
#include <cstring>
29+
#include <locale>
2930
#include "util.h"
3031

3132
// These are defined by <sys/byteorder.h> or <netinet/in.h> on some systems.
@@ -274,7 +275,7 @@ void SwapBytes64(char* data, size_t nbytes) {
274275
}
275276

276277
char ToLower(char c) {
277-
return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c;
278+
return std::tolower(c, std::locale::classic());
278279
}
279280

280281
std::string ToLower(const std::string& in) {
@@ -285,7 +286,7 @@ std::string ToLower(const std::string& in) {
285286
}
286287

287288
char ToUpper(char c) {
288-
return c >= 'a' && c <= 'z' ? (c - 'a') + 'A' : c;
289+
return std::toupper(c, std::locale::classic());
289290
}
290291

291292
std::string ToUpper(const std::string& in) {

0 commit comments

Comments
 (0)