]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/cmdpase: pass std::string when using formatter
authorKefu Chai <kchai@redhat.com>
Mon, 10 Feb 2020 04:30:27 +0000 (12:30 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 10 Feb 2020 08:33:56 +0000 (16:33 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/cmdparse.cc

index fae3382394838da98c3ae535c6d279a5c410225a..e3c25d95a4059f6c0725e49f5e2047858c9d78fe 100644 (file)
@@ -139,7 +139,7 @@ dump_cmd_to_json(Formatter *f, uint64_t features, const string& cmd)
     // accumulate descriptor keywords in desckv
     auto desckv = cmddesc_get_args(word);
     // name the individual desc object based on the name key
-    f->open_object_section(string(desckv["name"]).c_str());
+    f->open_object_section(desckv["name"]);
 
     // Compatibility for pre-nautilus clients that don't know about CephBool
     std::string val;
@@ -160,7 +160,7 @@ dump_cmd_to_json(Formatter *f, uint64_t features, const string& cmd)
 
     // dump all the keys including name into the array
     for (auto [key, value] : desckv) {
-      f->dump_string(string(key).c_str(), string(value));
+      f->dump_string(key, value);
     }
     f->close_section(); // attribute object for individual desc
   }
@@ -173,11 +173,11 @@ dump_cmd_and_help_to_json(Formatter *jf,
                          const string& cmdsig,
                          const string& helptext)
 {
-      jf->open_object_section(secname.c_str());
+      jf->open_object_section(secname);
       jf->open_array_section("sig");
       dump_cmd_to_json(jf, features, cmdsig);
       jf->close_section(); // sig array
-      jf->dump_string("help", helptext.c_str());
+      jf->dump_string("help", helptext);
       jf->close_section(); // cmd
 }
 
@@ -191,13 +191,13 @@ dump_cmddesc_to_json(Formatter *jf,
                     const string& perm,
                     uint64_t flags)
 {
-      jf->open_object_section(secname.c_str());
+      jf->open_object_section(secname);
       jf->open_array_section("sig");
       dump_cmd_to_json(jf, features, cmdsig);
       jf->close_section(); // sig array
-      jf->dump_string("help", helptext.c_str());
-      jf->dump_string("module", module.c_str());
-      jf->dump_string("perm", perm.c_str());
+      jf->dump_string("help", helptext);
+      jf->dump_string("module", module);
+      jf->dump_string("perm", perm);
       jf->dump_int("flags", flags);
       jf->close_section(); // cmd
 }
@@ -218,28 +218,28 @@ void cmdmap_dump(const cmdmap_t &cmdmap, Formatter *f)
 
     void operator()(const std::string &operand) const
     {
-      f->dump_string(key.c_str(), operand);
+      f->dump_string(key, operand);
     }
 
     void operator()(const bool &operand) const
     {
-      f->dump_bool(key.c_str(), operand);
+      f->dump_bool(key, operand);
     }
 
     void operator()(const int64_t &operand) const
     {
-      f->dump_int(key.c_str(), operand);
+      f->dump_int(key, operand);
     }
 
     void operator()(const double &operand) const
     {
-      f->dump_float(key.c_str(), operand);
+      f->dump_float(key, operand);
     }
 
     void operator()(const std::vector<std::string> &operand) const
     {
-      f->open_array_section(key.c_str());
-      for (const auto i : operand) {
+      f->open_array_section(key);
+      for (const auto& i : operand) {
         f->dump_string("item", i);
       }
       f->close_section();
@@ -247,7 +247,7 @@ void cmdmap_dump(const cmdmap_t &cmdmap, Formatter *f)
 
     void operator()(const std::vector<int64_t> &operand) const
     {
-      f->open_array_section(key.c_str());
+      f->open_array_section(key);
       for (const auto i : operand) {
         f->dump_int("item", i);
       }
@@ -256,7 +256,7 @@ void cmdmap_dump(const cmdmap_t &cmdmap, Formatter *f)
 
     void operator()(const std::vector<double> &operand) const
     {
-      f->open_array_section(key.c_str());
+      f->open_array_section(key);
       for (const auto i : operand) {
         f->dump_float("item", i);
       }