This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 232c5a9e04edd56a23b4df214f98dfa62165e294
Author: Adar Dembo <[email protected]>
AuthorDate: Mon Oct 28 21:52:47 2019 -0700

    util: add ToLowerCase string case methods
    
    We already had an implementation in tool_action_fs.cc, and I'm going to need
    to use it in a follow-on patch.
    
    Change-Id: I3d9ddb28175a328dbd23549bee527c33f7a519b8
    Reviewed-on: http://gerrit.cloudera.org:8080/14569
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <[email protected]>
---
 src/kudu/tools/tool_action_fs.cc |  7 +------
 src/kudu/util/string_case.cc     | 24 +++++++++++++++++-------
 src/kudu/util/string_case.h      | 30 +++++++++++++++++++++---------
 3 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/src/kudu/tools/tool_action_fs.cc b/src/kudu/tools/tool_action_fs.cc
index 9dc7e8f..e650c7f 100644
--- a/src/kudu/tools/tool_action_fs.cc
+++ b/src/kudu/tools/tool_action_fs.cc
@@ -50,7 +50,6 @@
 #include "kudu/gutil/gscoped_ptr.h"
 #include "kudu/gutil/map-util.h"
 #include "kudu/gutil/ref_counted.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
 #include "kudu/gutil/strings/human_readable.h"
 #include "kudu/gutil/strings/join.h"
 #include "kudu/gutil/strings/numbers.h"
@@ -74,6 +73,7 @@
 #include "kudu/util/pb_util.h"
 #include "kudu/util/slice.h"
 #include "kudu/util/status.h"
+#include "kudu/util/string_case.h"
 
 DECLARE_bool(force);
 DECLARE_bool(print_meta);
@@ -491,11 +491,6 @@ const char* ToString(FieldGroup group) {
   }
 }
 
-// Transforms an ASCII string to lowercase.
-void ToLowerCase(string* string) {
-  std::transform(string->begin(), string->end(), string->begin(), 
ascii_tolower);
-}
-
 // Parses a field name and returns the corresponding enum variant.
 Status ParseField(string name, Field* field) {
   StripWhiteSpace(&name);
diff --git a/src/kudu/util/string_case.cc b/src/kudu/util/string_case.cc
index 7cf60ab..9d11f13 100644
--- a/src/kudu/util/string_case.cc
+++ b/src/kudu/util/string_case.cc
@@ -17,18 +17,21 @@
 
 #include "kudu/util/string_case.h"
 
+#include <algorithm>
 #include <cctype>
 #include <cstdint>
 #include <ostream>
 
 #include <glog/logging.h>
 
+#include "kudu/gutil/strings/ascii_ctype.h"
+
 namespace kudu {
 
 using std::string;
 
-void SnakeToCamelCase(const std::string &snake_case,
-                      std::string *camel_case) {
+void SnakeToCamelCase(const std::string& snake_case,
+                      std::string* camel_case) {
   DCHECK_NE(camel_case, &snake_case) << "Does not support in-place operation";
   camel_case->clear();
   camel_case->reserve(snake_case.size());
@@ -49,18 +52,25 @@ void SnakeToCamelCase(const std::string &snake_case,
   }
 }
 
-void ToUpperCase(const std::string &string,
-                 std::string *out) {
+void ToUpperCase(const std::string& string,
+                 std::string* out) {
   if (out != &string) {
     *out = string;
   }
 
-  for (char& c : *out) {
-    c = toupper(c);
+  std::transform(out->begin(), out->end(), out->begin(), ascii_toupper);
+}
+
+void ToLowerCase(const std::string& string,
+                 std::string* out) {
+  if (out != &string) {
+    *out = string;
   }
+
+  std::transform(out->begin(), out->end(), out->begin(), ascii_tolower);
 }
 
-void Capitalize(string *word) {
+void Capitalize(string* word) {
   uint32_t size = word->size();
   if (size == 0) {
     return;
diff --git a/src/kudu/util/string_case.h b/src/kudu/util/string_case.h
index 98f5828..a010a2d 100644
--- a/src/kudu/util/string_case.h
+++ b/src/kudu/util/string_case.h
@@ -16,8 +16,8 @@
 // under the License.
 //
 // Utility methods for dealing with string case.
-#ifndef KUDU_UTIL_STRING_CASE_H
-#define KUDU_UTIL_STRING_CASE_H
+
+#pragma once
 
 #include <string>
 
@@ -31,18 +31,30 @@ namespace kudu {
 //
 // This function cannot operate in-place -- i.e. 'camel_case' must not
 // point to 'snake_case'.
-void SnakeToCamelCase(const std::string &snake_case,
-                      std::string *camel_case);
+void SnakeToCamelCase(const std::string& snake_case,
+                      std::string* camel_case);
 
-// Upper-case all of the characters in the given string.
+// Upper-case all of the ASCII characters in the given string.
 // 'string' and 'out' may refer to the same string to replace in-place.
-void ToUpperCase(const std::string &string,
-                 std::string *out);
+void ToUpperCase(const std::string& string,
+                 std::string* out);
+
+inline void ToUpperCase(std::string* s) {
+  ToUpperCase(*s, s);
+}
+
+// Lower-case all of the ASCII characters in the given string.
+// 'string' and 'out' may refer to the same string to replace in-place.
+void ToLowerCase(const std::string& string,
+                 std::string* out);
+
+inline void ToLowerCase(std::string* s) {
+  ToLowerCase(*s, s);
+}
 
 // Capitalizes a string containing a word in place.
 // For example:
 // - 'hiBerNATe' -> 'Hibernate'
-void Capitalize(std::string *word);
+void Capitalize(std::string* word);
 
 } // namespace kudu
-#endif

Reply via email to