From 9889d170b93a72cc3a9dedd6208a8693597f3f89 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Aug 2019 22:03:25 +0200 Subject: [PATCH] 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. --- AK/JsonValue.h | 7 +++++++ 1 file changed, 7 insertions(+) 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 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())