JsonValue: Add as_string_or(String)

Return the contained string if the value *is* a string, otherwise it
returns the alternative string passed in the parameter.
This commit is contained in:
Andreas Kling 2019-08-07 22:03:25 +02:00
parent f5ff796970
commit 9889d170b9

View file

@ -63,6 +63,13 @@ public:
template<typename Builder>
void serialize(Builder&) const;
String as_string_or(const String& alternative)
{
if (is_string())
return as_string();
return alternative;
}
String to_string() const
{
if (is_string())