diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-25 21:27:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-25 21:27:35 +0000 |
commit | 80aa9c41fe75efdfdb7ef5a54e51fa6e580ad044 (patch) | |
tree | d0f0c44c4f99f01690d1aaed285d2c66363d5f35 /src | |
parent | 99bea7a69e782c02d371f94a2988d49d0825fd7e (diff) |
JSONNode::isnull() - correct way of checking for missing / erroneous nodes
also can be written as !node
git-svn-id: http://svn.miranda-ng.org/main/trunk@13833 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_core/src/json/JSONNode.h | 20 | ||||
-rw-r--r-- | src/mir_core/src/json/JSONWorker.cpp | 4 | ||||
-rw-r--r-- | src/mir_core/src/json/libJSON.cpp | 2 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 2 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 2 |
5 files changed, 25 insertions, 5 deletions
diff --git a/src/mir_core/src/json/JSONNode.h b/src/mir_core/src/json/JSONNode.h index 8e415adfe3..01c6ffb405 100644 --- a/src/mir_core/src/json/JSONNode.h +++ b/src/mir_core/src/json/JSONNode.h @@ -93,6 +93,7 @@ public: json_index_t size(void) const;
bool empty(void) const;
+ bool isnull(void) const;
void clear(void);
unsigned char type(void) const;
@@ -135,6 +136,7 @@ public: JSONNode & at_nocase(const json_string & name_t);
const JSONNode & at_nocase(const json_string & name_t) const;
#endif
+ bool operator!() const;
JSONNode & operator[](const json_char *name_t);
const JSONNode & operator[](const json_char *name_t) const;
#ifdef JSON_LIBRARY
@@ -504,11 +506,23 @@ inline void JSONNode::clear(void){ internal -> Children.clear();
}
}
-inline unsigned char JSONNode::type(void) const {
+inline unsigned char JSONNode::type(void) const
+{
+ JSON_CHECK_INTERNAL();
+ return internal->type();
+}
+inline bool JSONNode::isnull(void) const
+{
JSON_CHECK_INTERNAL();
- return internal -> type();
+ return internal->type() == JSON_NULL;
}
-inline const json_char* JSONNode::name(void) const {
+inline bool JSONNode::operator!() const
+{
+ JSON_CHECK_INTERNAL();
+ return internal->type() == JSON_NULL;
+}
+inline const json_char* JSONNode::name(void) const
+{
JSON_CHECK_INTERNAL();
return internal -> name();
}
diff --git a/src/mir_core/src/json/JSONWorker.cpp b/src/mir_core/src/json/JSONWorker.cpp index 832a9fee47..516f9095f1 100644 --- a/src/mir_core/src/json/JSONWorker.cpp +++ b/src/mir_core/src/json/JSONWorker.cpp @@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JSONWorker.h"
+extern JSONNode nullNode;
+
#ifdef JSON_VALIDATE
JSONNode JSONWorker::validate(const json_string & json){
JSONNode res = parse(json);
@@ -91,7 +93,7 @@ JSONNode JSONWorker::parse(const json_string & json){ }
JSON_FAIL(JSON_TEXT("Not JSON!"));
- throw std::invalid_argument(EMPTY_STRING2);
+ return nullNode;
}
#define QUOTECASE()\
diff --git a/src/mir_core/src/json/libJSON.cpp b/src/mir_core/src/json/libJSON.cpp index 2a735ec3b4..9b977c259f 100644 --- a/src/mir_core/src/json/libJSON.cpp +++ b/src/mir_core/src/json/libJSON.cpp @@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "JSONNode.h"
#include "JSONWorker.h"
-#include <stdexcept> //some methods throw exceptions
+
#ifdef JSON_MEMORY_MANAGE
auto_expand StringHandler;
auto_expand_node NodeHandler;
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index ded290235f..8c3473fcc0 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1239,3 +1239,5 @@ Proto_RegisterModule @1074 NONAME ?type@JSONNode@@QBEEXZ @1242 NONAME
?write@JSONNode@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ @1243 NONAME
?write_formatted@JSONNode@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ @1244 NONAME
+?isnull@JSONNode@@QBE_NXZ @1245 NONAME
+??7JSONNode@@QBE_NXZ @1246 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 84b561fc13..70dc985da7 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1239,3 +1239,5 @@ Proto_RegisterModule @1074 NONAME ?type@JSONNode@@QEBAEXZ @1242 NONAME
?write@JSONNode@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ @1243 NONAME
?write_formatted@JSONNode@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ @1244 NONAME
+?isnull@JSONNode@@QEBA_NXZ @1245 NONAME
+??7JSONNode@@QEBA_NXZ @1246 NONAME
|