From ceace016cd02824709bd0da1c13c6c1e56f690f5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 16 Feb 2021 17:06:16 -0500 Subject: mon/ConfigMap: factor out parse_key helper Signed-off-by: Sage Weil --- src/mon/ConfigMap.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/mon/ConfigMap.cc') diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc index 7fb13841df4..763b8ce9b17 100644 --- a/src/mon/ConfigMap.cc +++ b/src/mon/ConfigMap.cc @@ -233,6 +233,23 @@ bool ConfigMap::parse_mask( return true; } +void ConfigMap::parse_key( + const std::string& key, + std::string *name, + std::string *who) +{ + auto last_slash = key.rfind('/'); + if (last_slash == std::string::npos) { + *name = key; + } else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) { + *name = key.substr(mgrpos + 1); + *who = key.substr(0, mgrpos); + } else { + *name = key.substr(last_slash + 1); + *who = key.substr(0, last_slash); + } +} + // -------------- -- cgit v1.2.3