msg/msg_types: remove entity_name_t::parse(const char*...)

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>
This commit is contained in:
Kefu Chai 2021-04-01 12:39:49 +08:00
parent 56c7679f13
commit 8c6b9e45c9
2 changed files with 12 additions and 17 deletions

View File

@ -12,27 +12,20 @@
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

View 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);