From a7d5e440c2116f84d9f189a82a5d989ab4b7a5b7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 9 Jun 2024 20:50:11 +0300 Subject: =?UTF-8?q?fixes=20#4461=20(SkypeWeb:=20=D0=BD=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D1=85=D0=BE=D0=B4=D1=8F=D1=82=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/libjson/src/stdafx.cxx | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'libs/libjson/src') diff --git a/libs/libjson/src/stdafx.cxx b/libs/libjson/src/stdafx.cxx index e96fbffa1b..58c1046959 100644 --- a/libs/libjson/src/stdafx.cxx +++ b/libs/libjson/src/stdafx.cxx @@ -18,33 +18,34 @@ along with this program. If not, see . #include "stdafx.h" +static void eraseOldValue(JSONNode &json, const char *pszName) +{ + if (pszName && *pszName != 0) { + auto n = json.find(pszName); + if (n != json.end()) + json.erase(n); + } +} + ///////////////////////////////////////////////////////////////////////////////////////// LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const INT_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); - + eraseOldValue(json, param.szName); json.push_back(JSONNode(param.szName, param.iValue)); return json; } LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const INT64_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); - + eraseOldValue(json, param.szName); json.push_back(JSONNode(param.szName, param.iValue)); return json; } LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const SINT64_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); + eraseOldValue(json, param.szName); char str[40]; _i64toa(param.iValue, str, 10); @@ -53,19 +54,14 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const SINT64_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const BOOL_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); - + eraseOldValue(json, param.szName); json.push_back(JSONNode(param.szName, param.bValue)); return json; } LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const CHAR_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); + eraseOldValue(json, param.szName); if (param.szValue == nullptr) { JSONNode tmp(JSON_NULL); tmp.set_name(param.szName); @@ -82,19 +78,14 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const CHAR_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const WCHAR_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); - + eraseOldValue(json, param.szName); json.push_back(JSONNode(param.szName, ptrA(mir_utf8encodeW(param.wszValue)).get())); return json; } LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const NULL_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); + eraseOldValue(json, param.szName); JSONNode newOne(JSON_NULL); newOne.set_name(param.szName); @@ -104,9 +95,7 @@ LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const NULL_PARAM ¶m) LIBJSON_DLL(JSONNode&) operator<<(JSONNode &json, const JSON_PARAM ¶m) { - auto n = json.find(param.szName); - if (n != json.end()) - json.erase(n); + eraseOldValue(json, param.szName); JSONNode newOne(param.node); newOne.set_name(param.szName); -- cgit v1.2.3