[DEV] it works
This commit is contained in:
parent
217c194765
commit
9a05682468
@ -24,13 +24,99 @@ void ejson::Array::Clear(void)
|
|||||||
|
|
||||||
bool ejson::Array::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Array::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
||||||
{
|
{
|
||||||
|
JSON_PARSE_ELEMENT("start parse : 'Object' ");
|
||||||
|
for (int32_t iii=_pos+1; iii<_data.Size(); iii++) {
|
||||||
|
_filePos.Check(_data[iii]);
|
||||||
|
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
||||||
|
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(_data[iii]==']') {
|
||||||
|
// find end of value:
|
||||||
|
_pos=iii; // ==> return the end element type ==> usefull to check end and check if adding element is needed
|
||||||
|
return true;
|
||||||
|
} else if (_data[iii]=='{') {
|
||||||
|
// find an object:
|
||||||
|
JSON_PARSE_ELEMENT("find Object");
|
||||||
|
ejson::Object * tmpElement = new ejson::Object();
|
||||||
|
if (NULL==tmpElement) {
|
||||||
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
|
||||||
|
_pos=iii;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
|
m_value.PushBack(tmpElement);
|
||||||
|
} else if (_data[iii]=='"') {
|
||||||
|
// find a string:
|
||||||
|
JSON_PARSE_ELEMENT("find String quoted");
|
||||||
|
ejson::String * tmpElement = new ejson::String(true);
|
||||||
|
if (NULL==tmpElement) {
|
||||||
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
|
||||||
|
_pos=iii;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
|
m_value.PushBack(tmpElement);
|
||||||
|
} else if (_data[iii]=='[') {
|
||||||
|
// find a list:
|
||||||
|
JSON_PARSE_ELEMENT("find List");
|
||||||
|
ejson::Array * tmpElement = new ejson::Array();
|
||||||
|
if (NULL==tmpElement) {
|
||||||
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
|
||||||
|
_pos=iii;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
|
m_value.PushBack(tmpElement);
|
||||||
|
} else if( CheckAvaillable(_data[iii]) ) {
|
||||||
|
// find a string without "" ==> special hook for the etk-json parser
|
||||||
|
JSON_PARSE_ELEMENT("find String");
|
||||||
|
ejson::String * tmpElement = new ejson::String(false);
|
||||||
|
if (NULL==tmpElement) {
|
||||||
|
EJSON_CREATE_ERROR(_doc, _data, iii-1, _filePos, "Allocation error in String");
|
||||||
|
_pos=iii;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
|
JSON_PARSE_ELEMENT("find String (end)");
|
||||||
|
m_value.PushBack(tmpElement);
|
||||||
|
} else if(_data[iii]==',') {
|
||||||
|
// find Separator : Restart cycle ...
|
||||||
|
// TODO : check if element are separated with ','
|
||||||
|
} else {
|
||||||
|
// find an error ....
|
||||||
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Find '>' with no element in the element...");
|
||||||
|
// move the curent index
|
||||||
|
_pos = iii+1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_pos = _data.Size();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Array::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Array::IGenerate(etk::UString& _data, int32_t _indent) const
|
||||||
{
|
{
|
||||||
return false;
|
_data += "[\n";
|
||||||
|
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
||||||
|
AddIndent(_data, _indent);
|
||||||
|
if (NULL != m_value[iii]) {
|
||||||
|
m_value[iii]->IGenerate(_data, _indent+1);
|
||||||
|
if (iii<m_value.Size()-1) {
|
||||||
|
_data += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_data += "\n";
|
||||||
|
}
|
||||||
|
AddIndent(_data, _indent-1);
|
||||||
|
_data += "]";
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,13 +64,15 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (CheckAvaillable(_data[iii]) ) {
|
} else if (CheckAvaillable(_data[iii]) ) {
|
||||||
|
currentName += _data[iii];
|
||||||
for (iii++; iii<_data.Size(); iii++) {
|
for (iii++; iii<_data.Size(); iii++) {
|
||||||
_filePos.Check(_data[iii]);
|
_filePos.Check(_data[iii]);
|
||||||
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
||||||
DrawElementParsed(_data[iii], _filePos);
|
DrawElementParsed(_data[iii], _filePos);
|
||||||
#endif
|
#endif
|
||||||
if (CheckAvaillable(_data[iii])) {
|
if (false==CheckAvaillable(_data[iii])) {
|
||||||
mode = parseMiddle;
|
mode = parseMiddle;
|
||||||
|
iii--;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
currentName += _data[iii];
|
currentName += _data[iii];
|
||||||
@ -102,6 +104,7 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
m_value.Add(currentName, tmpElement);
|
m_value.Add(currentName, tmpElement);
|
||||||
|
currentName = "";
|
||||||
} else if (_data[iii]=='"') {
|
} else if (_data[iii]=='"') {
|
||||||
// find a string:
|
// find a string:
|
||||||
JSON_PARSE_ELEMENT("find String quoted");
|
JSON_PARSE_ELEMENT("find String quoted");
|
||||||
@ -112,8 +115,8 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
JSON_WARNING(" add : " << currentName);
|
|
||||||
m_value.Add(currentName, tmpElement);
|
m_value.Add(currentName, tmpElement);
|
||||||
|
currentName = "";
|
||||||
} else if (_data[iii]=='[') {
|
} else if (_data[iii]=='[') {
|
||||||
// find a list:
|
// find a list:
|
||||||
JSON_PARSE_ELEMENT("find List");
|
JSON_PARSE_ELEMENT("find List");
|
||||||
@ -125,6 +128,7 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
m_value.Add(currentName, tmpElement);
|
m_value.Add(currentName, tmpElement);
|
||||||
|
currentName = "";
|
||||||
} else if( CheckAvaillable(_data[iii]) ) {
|
} else if( CheckAvaillable(_data[iii]) ) {
|
||||||
// find a string without "" ==> special hook for the etk-json parser
|
// find a string without "" ==> special hook for the etk-json parser
|
||||||
JSON_PARSE_ELEMENT("find String");
|
JSON_PARSE_ELEMENT("find String");
|
||||||
@ -134,11 +138,14 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
iii--;
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->IParse(_data, iii, _filePos, _doc);
|
||||||
|
iii--;
|
||||||
|
//JSON_ERROR(" add : " << currentName );
|
||||||
m_value.Add(currentName, tmpElement);
|
m_value.Add(currentName, tmpElement);
|
||||||
|
currentName = "";
|
||||||
} else if(_data[iii]==',') {
|
} else if(_data[iii]==',') {
|
||||||
// find Separator : Restart cycle ...
|
// find Separator : Restart cycle ...
|
||||||
JSON_INFO("start new parse ...");
|
|
||||||
mode = parseName;
|
mode = parseName;
|
||||||
currentName = "";
|
currentName = "";
|
||||||
} else {
|
} else {
|
||||||
@ -156,7 +163,6 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
}
|
}
|
||||||
bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
|
||||||
{
|
{
|
||||||
AddIndent(_data, _indent);
|
|
||||||
_data += "{\n";
|
_data += "{\n";
|
||||||
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
||||||
AddIndent(_data, _indent);
|
AddIndent(_data, _indent);
|
||||||
@ -164,10 +170,13 @@ bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
|
|||||||
_data += m_value.GetKey(iii);
|
_data += m_value.GetKey(iii);
|
||||||
_data += "\": ";
|
_data += "\": ";
|
||||||
m_value.GetValue(iii)->IGenerate(_data, _indent+1);
|
m_value.GetValue(iii)->IGenerate(_data, _indent+1);
|
||||||
|
if (iii<m_value.Size()-1) {
|
||||||
|
_data += ",";
|
||||||
|
}
|
||||||
_data += "\n";
|
_data += "\n";
|
||||||
}
|
}
|
||||||
AddIndent(_data, _indent);
|
AddIndent(_data, _indent-1);
|
||||||
_data += "}\n";
|
_data += "}";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
// white space ==> nothing to do ...
|
// white space ==> nothing to do ...
|
||||||
} else if(m_quoted==true) {
|
} else if(m_quoted==true) {
|
||||||
// TODO : manage \x
|
// TODO : manage \x
|
||||||
if( _data[iii]!= '"') {
|
if( _data[iii]!= '\"') {
|
||||||
m_value += _data[iii];
|
m_value += _data[iii];
|
||||||
} else {
|
} else {
|
||||||
_pos = iii;
|
_pos = iii;
|
||||||
@ -65,13 +65,13 @@ bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
|
|
||||||
bool ejson::String::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::String::IGenerate(etk::UString& _data, int32_t _indent) const
|
||||||
{
|
{
|
||||||
if (m_quoted==true) {
|
//if (m_quoted==true) {
|
||||||
_data += '"';
|
_data += "\"";;
|
||||||
}
|
//}
|
||||||
_data += m_value;
|
_data += m_value;
|
||||||
if (m_quoted==true) {
|
//if (m_quoted==true) {
|
||||||
_data += '"';
|
_data += "\"";;
|
||||||
}
|
//}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ bool ejson::Value::CheckAvaillable(const etk::UniChar& _val, bool _firstChar) co
|
|||||||
|| _val == '+'
|
|| _val == '+'
|
||||||
|| _val == ','
|
|| _val == ','
|
||||||
|| _val == '/'
|
|| _val == '/'
|
||||||
|
|| _val == ':'
|
||||||
|| _val == ';'
|
|| _val == ';'
|
||||||
|| _val == '<'
|
|| _val == '<'
|
||||||
|| _val == '='
|
|| _val == '='
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
|
|
||||||
namespace ejson
|
namespace ejson
|
||||||
{
|
{
|
||||||
#define ENABLE_DISPLAY_PARSED_ELEMENT
|
//#define ENABLE_DISPLAY_PARSED_ELEMENT
|
||||||
#if 0
|
#if 1
|
||||||
#define JSON_PARSE_ELEMENT JSON_VERBOSE
|
#define JSON_PARSE_ELEMENT JSON_VERBOSE
|
||||||
#else
|
#else
|
||||||
#define JSON_PARSE_ELEMENT JSON_DEBUG
|
#define JSON_PARSE_ELEMENT JSON_DEBUG
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 1
|
||||||
#define JSON_PARSE_ATTRIBUTE JSON_VERBOSE
|
#define JSON_PARSE_ATTRIBUTE JSON_VERBOSE
|
||||||
#else
|
#else
|
||||||
#define JSON_PARSE_ATTRIBUTE JSON_DEBUG
|
#define JSON_PARSE_ATTRIBUTE JSON_DEBUG
|
||||||
|
@ -37,13 +37,10 @@ ejson::Document::~Document(void)
|
|||||||
|
|
||||||
bool ejson::Document::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Document::IGenerate(etk::UString& _data, int32_t _indent) const
|
||||||
{
|
{
|
||||||
AddIndent(_data, _indent);
|
|
||||||
_data += "{\n";
|
|
||||||
if (NULL!=m_subElement) {
|
if (NULL!=m_subElement) {
|
||||||
m_subElement->IGenerate(_data, _indent+1);
|
m_subElement->IGenerate(_data, _indent+1);
|
||||||
}
|
}
|
||||||
AddIndent(_data, _indent);
|
_data += "\n";
|
||||||
_data += "}\n";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ namespace ejson
|
|||||||
|
|
||||||
#define EJSON_CREATE_ERROR(doc,data,pos,filePos,comment) \
|
#define EJSON_CREATE_ERROR(doc,data,pos,filePos,comment) \
|
||||||
do { \
|
do { \
|
||||||
JSON_CRITICAL(comment); \
|
JSON_ERROR(comment); \
|
||||||
(doc).CreateError((data),(pos),(filePos),(comment)); \
|
(doc).CreateError((data),(pos),(filePos),(comment)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -61,7 +61,10 @@ void Init(void)
|
|||||||
" \"id\": \"file\",\n"
|
" \"id\": \"file\",\n"
|
||||||
" \"value\": \"File\",\n"
|
" \"value\": \"File\",\n"
|
||||||
" \"popup\": {\n"
|
" \"popup\": {\n"
|
||||||
" \"menuitem\": {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n"
|
" \"menuitem\": {\n"
|
||||||
|
" \"value\": \"Close\",\n"
|
||||||
|
" \"onclick\": \"CloseDoc()\"\n"
|
||||||
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
@ -69,15 +72,29 @@ void Init(void)
|
|||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.PushBack(check);
|
||||||
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"menu\": {\n"
|
" \"menu\": {\n"
|
||||||
" \"id\": \"file\",\n"
|
" \"id\": \"file\",\n"
|
||||||
" \"value\": \"File\",\n"
|
" \"value\": \"File\",\n"
|
||||||
" \"popup\": {\n"
|
" \"popup\": {\n"
|
||||||
" \"menuitem\": [\n"
|
" \"menuitem\": [\n"
|
||||||
" {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n"
|
" {\n"
|
||||||
" {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n"
|
" \"value\": \"Close\",\n"
|
||||||
" {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n"
|
" \"onclick\": \"CloseDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" \"value\": \"New\",\n"
|
||||||
|
" \"onclick\": \"CreateNewDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" \"value\": \"Open\",\n"
|
||||||
|
" \"onclick\": \"OpenDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" \"value\": \"Close\",\n"
|
||||||
|
" \"onclick\": \"CloseDoc()\"\n"
|
||||||
|
" }\n"
|
||||||
" ]\n"
|
" ]\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@ -86,6 +103,36 @@ void Init(void)
|
|||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.PushBack(check);
|
||||||
|
// ------------------------------------------------------
|
||||||
|
check.Set(reference,
|
||||||
|
-1,
|
||||||
|
"{\n"
|
||||||
|
" menu: {\n"
|
||||||
|
" id: file,\n"
|
||||||
|
" value: File,\n"
|
||||||
|
" popup: {\n"
|
||||||
|
" menuitem: [\n"
|
||||||
|
" {\n"
|
||||||
|
" value: Close,\n"
|
||||||
|
" onclick: \"CloseDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" value: New,\n"
|
||||||
|
" onclick: \"CreateNewDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" value: Open,\n"
|
||||||
|
" onclick: \"OpenDoc()\"\n"
|
||||||
|
" },\n"
|
||||||
|
" {\n"
|
||||||
|
" value: Close,\n"
|
||||||
|
" onclick: \"CloseDoc()\"\n"
|
||||||
|
" }\n"
|
||||||
|
" ]\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
l_list.PushBack(check);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user