]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ConfUtils: implement trim helpers using boost 28634/head
authorKefu Chai <kchai@redhat.com>
Wed, 19 Jun 2019 10:07:07 +0000 (18:07 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 25 Jun 2019 07:10:07 +0000 (15:10 +0800)
remove unused trim_whitespace() and its tests. as it is not used anymore

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ConfUtils.cc
src/common/ConfUtils.h
src/test/confutils.cc

index d4d2c262a6d904bef26ccfd174637019d3ea4fc7..96c9f352da9ae4b2390ab9bc5a6889796f160ed5 100644 (file)
@@ -32,6 +32,7 @@ namespace fs = std::experimental::filesystem;
 #endif
 
 #include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/trim_all.hpp>
 #include <boost/spirit/include/qi.hpp>
 #include <boost/spirit/include/phoenix.hpp>
 #include <boost/spirit/include/support_line_pos_iterator.hpp>
@@ -286,58 +287,6 @@ int ConfFile::read(const std::string& section_name,
   return -ENOENT;
 }
 
-void ConfFile::
-trim_whitespace(std::string &str, bool strip_internal)
-{
-  // strip preceding
-  const char *in = str.c_str();
-  while (true) {
-    char c = *in;
-    if ((!c) || (!isspace(c)))
-      break;
-    ++in;
-  }
-  char output[strlen(in) + 1];
-  strcpy(output, in);
-
-  // strip trailing
-  char *o = output + strlen(output);
-  while (true) {
-    if (o == output)
-      break;
-    --o;
-    if (!isspace(*o)) {
-      ++o;
-      *o = '\0';
-      break;
-    }
-  }
-
-  if (!strip_internal) {
-    str.assign(output);
-    return;
-  }
-
-  // strip internal
-  char output2[strlen(output) + 1];
-  char *out2 = output2;
-  bool prev_was_space = false;
-  for (char *u = output; *u; ++u) {
-    char c = *u;
-    if (isspace(c)) {
-      if (!prev_was_space)
-       *out2++ = c;
-      prev_was_space = true;
-    }
-    else {
-      *out2++ = c;
-      prev_was_space = false;
-    }
-  }
-  *out2++ = '\0';
-  str.assign(output2);
-}
-
 /* Normalize a key name.
  *
  * Normalized key names have no leading or trailing whitespace, and all
@@ -345,15 +294,10 @@ trim_whitespace(std::string &str, bool strip_internal)
  * normal form is so that in common/config.cc, we can use a macro to stringify
  * the field names of md_config_t and get a key in normal form.
  */
-std::string ConfFile::
-normalize_key_name(std::string_view key)
+std::string ConfFile::normalize_key_name(std::string_view key)
 {
   std::string k{key};
-  if (k.find_first_of(" \t\r\n\f\v\xa0") == k.npos) {
-    return k;
-  }
-  ConfFile::trim_whitespace(k, true);
-  std::replace(k.begin(), k.end(), ' ', '_');
+  boost::algorithm::trim_fill_if(k, "_", isspace);
   return k;
 }
 
index 2672ccf41a4150ee82255b6448d4d03c8bf20f70..80dd8df866295e1183d24252b504efa6e417e284 100644 (file)
@@ -72,7 +72,6 @@ public:
   int parse_bufferlist(ceph::bufferlist *bl, std::ostream *warnings);
   int read(const std::string& section, std::string_view key,
           std::string &val) const;
-  static void trim_whitespace(std::string &str, bool strip_internal);
   static std::string normalize_key_name(std::string_view key);
 private:
   bool load_from_buffer(std::string_view buf, std::ostream* warning);
index 029dd5dbb43a1f6b09900987c5a7087f0fbc7740..c9411b1827d00c3c34768a84c8237f49cef955eb 100644 (file)
@@ -256,44 +256,6 @@ const char dup_key_config_1[] = "\
         log_file = 3\n\
 ";
 
-TEST(ConfUtils, Whitespace) {
-  std::string test0("");
-  ConfFile::trim_whitespace(test0, false);
-  ASSERT_EQ(test0, "");
-
-  std::string test0a("");
-  ConfFile::trim_whitespace(test0a, true);
-  ASSERT_EQ(test0a, "");
-
-  std::string test0b("          ");
-  ConfFile::trim_whitespace(test0b, false);
-  ASSERT_EQ(test0b, "");
-
-  std::string test0c("          ");
-  ConfFile::trim_whitespace(test0c, true);
-  ASSERT_EQ(test0c, "");
-
-  std::string test1(" abc             ");
-  ConfFile::trim_whitespace(test1, false);
-  ASSERT_EQ(test1, "abc");
-
-  std::string test2(" abc        d     ");
-  ConfFile::trim_whitespace(test2, true);
-  ASSERT_EQ(test2, "abc d");
-
-  std::string test3(" abc        d     ");
-  ConfFile::trim_whitespace(test3, false);
-  ASSERT_EQ(test3, "abc        d");
-
-  std::string test4("abcd");
-  ConfFile::trim_whitespace(test4, false);
-  ASSERT_EQ(test4, "abcd");
-
-  std::string test5("abcd");
-  ConfFile::trim_whitespace(test5, true);
-  ASSERT_EQ(test5, "abcd");
-}
-
 TEST(ConfUtils, ParseFiles0) {
   std::string val;