Extract post formats via regex.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bd7952e901
commit
c192f352f0
@ -121,23 +121,23 @@ vector<string> Instance::get_post_formats() noexcept
|
|||||||
return _post_formats;
|
return _post_formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr string_view searchstring{R"("postFormats":[)"};
|
const regex re_allformats(R"("postFormats"\s*:\s*\[([^\]]+)\])");
|
||||||
auto pos{answer.body.find(searchstring)};
|
smatch match;
|
||||||
if (pos == string::npos)
|
if (!regex_search(answer.body, match, re_allformats))
|
||||||
{
|
{
|
||||||
debuglog << "Couldn't find metadata.postFormats.\n";
|
debuglog << "Couldn't find metadata.postFormats.\n";
|
||||||
_post_formats = {default_value};
|
_post_formats = {default_value};
|
||||||
return _post_formats;
|
return _post_formats;
|
||||||
}
|
}
|
||||||
pos += searchstring.size();
|
string allformats{match[1].str()};
|
||||||
auto endpos{answer.body.find("],", pos)};
|
debuglog << "Found postFormats: " << allformats << '\n';
|
||||||
string formats{answer.body.substr(pos, endpos - pos)};
|
|
||||||
debuglog << "Extracted postFormats: " << formats << '\n';
|
|
||||||
|
|
||||||
while ((pos = formats.find('"', 1)) != string::npos)
|
const regex re_format(R"(\s*"([^"]+)\"\s*,?)");
|
||||||
|
|
||||||
|
while (regex_search(allformats, match, re_format))
|
||||||
{
|
{
|
||||||
_post_formats.push_back(formats.substr(1, pos - 1));
|
_post_formats.push_back(match[1].str());
|
||||||
formats.erase(0, pos + 2); // 2 is the length of: ",
|
allformats = match.suffix();
|
||||||
debuglog << "Found postFormat: " << _post_formats.back() << '\n';
|
debuglog << "Found postFormat: " << _post_formats.back() << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user