mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 14:15:17 +00:00
Add CharToLower and CharToUpper into util.s (#6126)
This commit adds replacement of `::tolower` and `::toupper`. Added CharToLower and CharToUpper routines reduce the number of cast operators that required for correct usage of standard C/C++ `::tolower/toupper` routines.
This commit is contained in:
@@ -29,14 +29,14 @@ std::string MakeSnakeCase(const std::string &in) {
|
||||
std::string s;
|
||||
for (size_t i = 0; i < in.length(); i++) {
|
||||
if (i == 0) {
|
||||
s += static_cast<char>(tolower(in[0]));
|
||||
s += CharToLower(in[0]);
|
||||
} else if (in[i] == '_') {
|
||||
s += '_';
|
||||
} else if (!islower(in[i])) {
|
||||
// Prevent duplicate underscores for Upper_Snake_Case strings
|
||||
// and UPPERCASE strings.
|
||||
if (islower(in[i - 1])) { s += '_'; }
|
||||
s += static_cast<char>(tolower(in[i]));
|
||||
s += CharToLower(in[i]);
|
||||
} else {
|
||||
s += in[i];
|
||||
}
|
||||
@@ -48,7 +48,7 @@ std::string MakeSnakeCase(const std::string &in) {
|
||||
std::string MakeUpper(const std::string &in) {
|
||||
std::string s;
|
||||
for (size_t i = 0; i < in.length(); i++) {
|
||||
s += static_cast<char>(toupper(in[i]));
|
||||
s += CharToUpper(in[i]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user