Procházet zdrojové kódy

Add JSONElement::has_key

Daniele Bartolini před 12 roky
rodič
revize
ee4b9d841e
2 změnil soubory, kde provedl 21 přidání a 0 odebrání
  1. 18 0
      engine/core/json/JSONParser.cpp
  2. 3 0
      engine/core/json/JSONParser.h

+ 18 - 0
engine/core/json/JSONParser.cpp

@@ -257,6 +257,24 @@ JSONElement& JSONElement::key(const char* k)
 	return *this;
 }
 
+//--------------------------------------------------------------------------
+bool JSONElement::has_key(const char* k) const
+{
+	TempAllocator1024 alloc;
+	List<JSONPair> object(alloc);
+	JSONParser::parse_object(m_at, object);
+
+	for (uint32_t i = 0; i < object.size(); i++)
+	{
+		if (string::strcmp(k, object[i].key) == 0)
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
 //--------------------------------------------------------------------------
 bool JSONElement::bool_value() const
 {

+ 3 - 0
engine/core/json/JSONParser.h

@@ -77,6 +77,9 @@ public:
 	/// key in order of appearance will be selected.
 	JSONElement&		key(const char* k);
 
+	/// Returns whether the element has the @a k key.
+	bool				has_key(const char* k) const;
+
 	/// Returns true wheter the element is the JSON nil special value.
 	bool				is_nil() const;