diff --git a/ejson/Object.cpp b/ejson/Object.cpp index 40a95c8..fe7fd90 100644 --- a/ejson/Object.cpp +++ b/ejson/Object.cpp @@ -181,5 +181,34 @@ bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const } +ejson::Value* ejson::Object::GetSub(const etk::UString& _named) const +{ + return m_value[_named]; +} +ejson::Object* ejson::Object::GetSubObject(const etk::UString& _named) const +{ + ejson::Value* tmp = m_value[_named]; + if (NULL == tmp) { + return NULL; + } + return tmp->ToObject(); +} +ejson::String* ejson::Object::GetSubString(const etk::UString& _named) const +{ + ejson::Value* tmp = m_value[_named]; + if (NULL == tmp) { + return NULL; + } + return tmp->ToString(); +} + +ejson::Array* ejson::Object::GetSubArray(const etk::UString& _named) const +{ + ejson::Value* tmp = m_value[_named]; + if (NULL == tmp) { + return NULL; + } + return tmp->ToArray(); +} diff --git a/ejson/Object.h b/ejson/Object.h index d77e792..69e5582 100644 --- a/ejson/Object.h +++ b/ejson/Object.h @@ -48,7 +48,10 @@ namespace ejson protected: etk::Hash m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) public: - + ejson::Value* GetSub(const etk::UString& _named) const; + ejson::Object* GetSubObject(const etk::UString& _named) const; + ejson::String* GetSubString(const etk::UString& _named) const; + ejson::Array* GetSubArray(const etk::UString& _named) const; public: /** * @brief Get the node type. diff --git a/ejson/String.cpp b/ejson/String.cpp index a43374c..ad5b0d8 100644 --- a/ejson/String.cpp +++ b/ejson/String.cpp @@ -31,12 +31,7 @@ bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::file DrawElementParsed(_data[iii], _filePos); #endif ejson::filePos tmpPos; - if( _data[iii]==' ' - || _data[iii]=='\t' - || _data[iii]=='\n' - || _data[iii]=='\r') { - // white space ==> nothing to do ... - } else if(m_quoted==true) { + if(m_quoted==true) { // TODO : manage \x if( _data[iii]!= '\"') { m_value += _data[iii]; diff --git a/ejson/ejson.cpp b/ejson/ejson.cpp index 02459e9..34834f6 100644 --- a/ejson/ejson.cpp +++ b/ejson/ejson.cpp @@ -130,7 +130,7 @@ void ejson::Document::Display(void) JSON_INFO("Generated JSON : \n" << tmpp); } -etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos) +static etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos) { etk::UString out; int32_t iii; @@ -244,3 +244,43 @@ bool ejson::Document::IParse(const etk::UString& _data, int32_t& _pos, ejson::fi } return true; } + + +ejson::Value* ejson::Document::GetSub(const etk::UString& _named) const +{ + if (m_subElement == NULL) { + return NULL; + } + ejson::Object* tmp = m_subElement->ToObject(); + if (NULL==tmp) { + return NULL; + } + return tmp->GetSub(_named); +} + +ejson::Object* ejson::Document::GetSubObject(const etk::UString& _named) const +{ + ejson::Value* tmp = GetSub(_named); + if (NULL == tmp) { + return NULL; + } + return tmp->ToObject(); +} + +ejson::String* ejson::Document::GetSubString(const etk::UString& _named) const +{ + ejson::Value* tmp = GetSub(_named); + if (NULL == tmp) { + return NULL; + } + return tmp->ToString(); +} + +ejson::Array* ejson::Document::GetSubArray(const etk::UString& _named) const +{ + ejson::Value* tmp = GetSub(_named); + if (NULL == tmp) { + return NULL; + } + return tmp->ToArray(); +} diff --git a/ejson/ejson.h b/ejson/ejson.h index d8102b3..e18bd72 100644 --- a/ejson/ejson.h +++ b/ejson/ejson.h @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include namespace ejson { @@ -63,7 +66,10 @@ namespace ejson private: ejson::Value* m_subElement; //!< only element that contain the json document: public: - // TODO : sdfsdfsdf + ejson::Value* GetSub(const etk::UString& _named) const; + ejson::Object* GetSubObject(const etk::UString& _named) const; + ejson::String* GetSubString(const etk::UString& _named) const; + ejson::Array* GetSubArray(const etk::UString& _named) const; private: bool m_writeErrorWhenDetexted; etk::UString m_comment;