From 732d0374be1a746c9bd28655cd1cd586b1677f90 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 13 May 2018 19:24:50 +0200 Subject: [PATCH] Simplify optional member reading in HighlightPhrase setting deserialization --- .../highlights/highlightphrase.hpp | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/controllers/highlights/highlightphrase.hpp b/src/controllers/highlights/highlightphrase.hpp index 2d7161b16..7346295d3 100644 --- a/src/controllers/highlights/highlightphrase.hpp +++ b/src/controllers/highlights/highlightphrase.hpp @@ -1,5 +1,6 @@ #pragma once +#include "util/rapidjson-helpers.hpp" #include "util/serialize-custom.hpp" #include @@ -101,36 +102,14 @@ struct Deserialize { } QString _pattern; - if (value.HasMember("pattern")) { - const rapidjson::Value &key = value["pattern"]; - if (key.IsString()) { - _pattern = key.GetString(); - } - } - bool _alert = true; - if (value.HasMember("alert")) { - const rapidjson::Value &alert = value["alert"]; - if (alert.IsBool()) { - _alert = alert.GetBool(); - } - } - bool _sound = false; - if (value.HasMember("sound")) { - const rapidjson::Value &sound = value["sound"]; - if (sound.IsBool()) { - _sound = sound.GetBool(); - } - } - bool _isRegex = false; - if (value.HasMember("regex")) { - const rapidjson::Value ®ex = value["regex"]; - if (regex.IsBool()) { - _isRegex = regex.GetBool(); - } - } + + chatterino::rj::getSafe(value, "pattern", _pattern); + chatterino::rj::getSafe(value, "alert", _alert); + chatterino::rj::getSafe(value, "sound", _sound); + chatterino::rj::getSafe(value, "regex", _isRegex); return chatterino::controllers::highlights::HighlightPhrase(_pattern, _alert, _sound, _isRegex);