diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 22:03:25 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-07 22:03:25 +0200 |
commit | 9889d170b93a72cc3a9dedd6208a8693597f3f89 (patch) | |
tree | 1869bce853a630073b5d04aa2010af48c4af0cd4 /AK | |
parent | f5ff79697024eb5641d046f7a5a4897aa832d134 (diff) | |
download | serenity-9889d170b93a72cc3a9dedd6208a8693597f3f89.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/JsonValue.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 1c31a46dd9..59415fdac8 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -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()) |