MCPcopy Create free account
hub / github.com/ceph/ceph / get_json_str_map

Function get_json_str_map

src/common/str_map.cc:29–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27using namespace std;
28
29int get_json_str_map(
30 const string &str,
31 ostream &ss,
32 str_map_t *str_map,
33 bool fallback_to_plain)
34{
35 json_spirit::mValue json;
36 try {
37 // try json parsing first
38
39 json_spirit::read_or_throw(str, json);
40
41 if (json.type() != json_spirit::obj_type) {
42 ss << str << " must be a JSON object but is of type "
43 << json.type() << " instead";
44 return -EINVAL;
45 }
46
47 json_spirit::mObject o = json.get_obj();
48
49 for (map<string, json_spirit::mValue>::iterator i = o.begin();
50 i != o.end();
51 ++i) {
52 (*str_map)[i->first] = i->second.get_str();
53 }
54 } catch (json_spirit::Error_position &e) {
55 if (fallback_to_plain) {
56 // fallback to key=value format
57 get_str_map(str, str_map, "\t\n ");
58 } else {
59 return -EINVAL;
60 }
61 }
62 return 0;
63}
64
65static std::string_view trim(std::string_view str)
66{

Callers 5

layers_parseMethod · 0.85
TESTFunction · 0.85
initMethod · 0.85
prepare_command_implMethod · 0.85

Calls 6

get_str_mapFunction · 0.85
typeMethod · 0.45
get_objMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
get_strMethod · 0.45

Tested by 1

TESTFunction · 0.68