ChatON: Make json_get efficient and flexible wrt its calling

Also explicitly indicate that we are looking at a chain of keys
This commit is contained in:
HanishKVC 2024-05-13 16:04:42 +05:30
parent eb7554ca3b
commit 184ac322e3

View file

@ -313,7 +313,7 @@ public:
#ifdef CHATON_JSON #ifdef CHATON_JSON
template <typename SupportedType> template <typename SupportedType>
inline SupportedType json_get(json &j, std::vector<std::string> keys, const std::string &msgTag) { inline SupportedType json_get(json &j, const std::vector<std::string_view> &keys, const std::string &msgTag) {
json curJ = j; json curJ = j;
std::stringstream skey; std::stringstream skey;
int i = 0; int i = 0;
@ -325,7 +325,7 @@ inline SupportedType json_get(json &j, std::vector<std::string> keys, const std:
curJ = curJ[key]; curJ = curJ[key];
} else { } else {
std::stringstream ss; std::stringstream ss;
ss << "ERRR:ChatON:" << __func__ << ":" << msgTag << ":Key [" << skey.str() << "] is missing"; ss << "ERRR:ChatON:" << __func__ << ":" << msgTag << ":KeyChain [" << skey.str() << "] is missing";
throw std::runtime_error(ss.str()); throw std::runtime_error(ss.str());
} }
} }