]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/msg_types: remove entity_name_t::parse(const char*...) 40538/head
authorKefu Chai <kchai@redhat.com>
Thu, 1 Apr 2021 04:39:49 +0000 (12:39 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Apr 2021 05:03:43 +0000 (13:03 +0800)
it can be replaced with entity_name_t::parse(string_view)

also refactor entity_name_t::parse(string_view) a little bit, to
embed the logic of `entity_name_t::parse(const char*...)` in it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/msg_types.cc
src/msg/msg_types.h

index 94e307f7a0d687d44d5090213583e5b650029664..b50488bf1a89a43b970bb7158de8d28fbd8f1f1c 100644 (file)
 
 bool entity_name_t::parse(std::string_view s)
 {
-  const char *start = s.data();
-  char *end = nullptr;
-  bool got = parse(start, &end);
-  return got && end == start + s.size();
-}
-
-bool entity_name_t::parse(const char *start, char **end)
-{
-  if (strstr(start, "mon.") == start) {
+  const char* start = s.data();
+  if (s.find("mon.") == 0) {
     _type = TYPE_MON;
     start += 4;
-  } else if (strstr(start, "osd.") == start) {
+  } else if (s.find("osd.") == 0) {
     _type = TYPE_OSD;
     start += 4;
-  } else if (strstr(start, "mds.") == start) {
+  } else if (s.find("mds.") == 0) {
     _type = TYPE_MDS;
     start += 4;
-  } else if (strstr(start, "client.") == start) {
+  } else if (s.find("client.") == 0) {
     _type = TYPE_CLIENT;
     start += 7;
-  } else if (strstr(start, "mgr.") == start) {
+  } else if (s.find("mgr.") == 0) {
     _type = TYPE_MGR;
     start += 4;
   } else {
@@ -40,10 +33,13 @@ bool entity_name_t::parse(const char *start, char **end)
   }
   if (isspace(*start))
     return false;
-  _num = strtoll(start, end, 10);
-  if (*end == NULL || *end == start)
+  char *end = nullptr;
+  _num = strtoll(start, &end, 10);
+  if (end == nullptr || end == start) {
     return false;
-  return true;
+  } else {
+    return end == s.data() + s.size();
+  }
 }
 
 void entity_name_t::dump(ceph::Formatter *f) const
index 84a87bdceac7050c8e17d22f4abce2ea7ef2881d..0974c9a842723794b01727ca93d7f8c2ac40dce0 100644 (file)
@@ -82,7 +82,6 @@ public:
   }
 
   bool parse(std::string_view s);
-  bool parse(const char *start, char **end);
 
   DENC(entity_name_t, v, p) {
     denc(v._type, p);