[DEV] change coding style
This commit is contained in:
parent
299ca3e6b2
commit
a788a3c450
220
ejson/Array.cpp
220
ejson/Array.cpp
@ -20,104 +20,102 @@
|
|||||||
#define __class__ "Array"
|
#define __class__ "Array"
|
||||||
|
|
||||||
|
|
||||||
void ejson::Array::Clear(void)
|
void ejson::Array::clear(void) {
|
||||||
{
|
for (esize_t iii=0; iii<m_value.size(); ++iii) {
|
||||||
for (esize_t iii=0; iii<m_value.Size(); ++iii) {
|
|
||||||
if (NULL == m_value[iii]) {
|
if (NULL == m_value[iii]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
delete(m_value[iii]);
|
delete(m_value[iii]);
|
||||||
m_value[iii] = NULL;
|
m_value[iii] = NULL;
|
||||||
}
|
}
|
||||||
m_value.Clear();
|
m_value.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
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' ");
|
JSON_PARSE_ELEMENT("start parse : 'Object' ");
|
||||||
for (int32_t iii=_pos+1; iii<_data.Size(); iii++) {
|
for (int32_t iii=_pos+1; 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
|
||||||
ejson::filePos tmpPos;
|
ejson::filePos tmpPos;
|
||||||
if( _data[iii]==' '
|
if( _data[iii] == ' '
|
||||||
|| _data[iii]=='\t'
|
|| _data[iii] == '\t'
|
||||||
|| _data[iii]=='\n'
|
|| _data[iii] == '\n'
|
||||||
|| _data[iii]=='\r') {
|
|| _data[iii] == '\r') {
|
||||||
// white space ==> nothing to do ...
|
// white space == > nothing to do ...
|
||||||
} else if(_data[iii]==']') {
|
} else if(_data[iii] == ']') {
|
||||||
// find end of value:
|
// find end of value:
|
||||||
_pos=iii; // ==> return the end element type ==> usefull to check end and check if adding element is needed
|
_pos=iii; // == > return the end element type ==> usefull to check end and check if adding element is needed
|
||||||
return true;
|
return true;
|
||||||
} else if (_data[iii]=='{') {
|
} else if (_data[iii] == '{') {
|
||||||
// find an object:
|
// find an object:
|
||||||
JSON_PARSE_ELEMENT("find Object");
|
JSON_PARSE_ELEMENT("find Object");
|
||||||
ejson::Object * tmpElement = new ejson::Object();
|
ejson::Object * tmpElement = new ejson::Object();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} 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");
|
||||||
ejson::String * tmpElement = new ejson::String();
|
ejson::String * tmpElement = new ejson::String();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} else if (_data[iii]=='[') {
|
} else if (_data[iii] == '[') {
|
||||||
// find a list:
|
// find a list:
|
||||||
JSON_PARSE_ELEMENT("find List");
|
JSON_PARSE_ELEMENT("find List");
|
||||||
ejson::Array * tmpElement = new ejson::Array();
|
ejson::Array * tmpElement = new ejson::Array();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} else if( _data[iii] == 'f'
|
} else if( _data[iii] == 'f'
|
||||||
|| _data[iii] == 't' ) {
|
|| _data[iii] == 't' ) {
|
||||||
// find boolean:
|
// find boolean:
|
||||||
JSON_PARSE_ELEMENT("find Boolean");
|
JSON_PARSE_ELEMENT("find Boolean");
|
||||||
ejson::Boolean * tmpElement = new ejson::Boolean();
|
ejson::Boolean * tmpElement = new ejson::Boolean();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} else if( _data[iii] == 'n') {
|
} else if( _data[iii] == 'n') {
|
||||||
// find null:
|
// find null:
|
||||||
JSON_PARSE_ELEMENT("find Null");
|
JSON_PARSE_ELEMENT("find Null");
|
||||||
ejson::Null * tmpElement = new ejson::Null();
|
ejson::Null * tmpElement = new ejson::Null();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} else if(true==CheckNumber(_data[iii])) {
|
} else if(true == checkNumber(_data[iii])) {
|
||||||
// find number:
|
// find number:
|
||||||
JSON_PARSE_ELEMENT("find Number");
|
JSON_PARSE_ELEMENT("find Number");
|
||||||
ejson::Number * tmpElement = new ejson::Number();
|
ejson::Number * tmpElement = new ejson::Number();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
m_value.PushBack(tmpElement);
|
m_value.pushBack(tmpElement);
|
||||||
} else if(_data[iii]==',') {
|
} else if(_data[iii] == ',') {
|
||||||
// find Separator : Restart cycle ...
|
// find Separator : Restart cycle ...
|
||||||
// TODO : check if element are separated with ','
|
// TODO : check if element are separated with ','
|
||||||
} else {
|
} else {
|
||||||
@ -128,34 +126,33 @@ bool ejson::Array::IParse(const etk::UString& _data, int32_t& _pos, ejson::fileP
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pos = _data.Size();
|
_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 {
|
||||||
{
|
|
||||||
bool oneLine=true;
|
bool oneLine=true;
|
||||||
if (m_value.Size()>3) {
|
if (m_value.size()>3) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
} else {
|
} else {
|
||||||
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
for (esize_t iii=0; iii<m_value.size() ; iii++) {
|
||||||
ejson::Value* tmp = m_value[iii];
|
ejson::Value* tmp = m_value[iii];
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsObject()) {
|
if (true == tmp->isObject()) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsArray()) {
|
if (true == tmp->isArray()) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsString()) {
|
if (true == tmp->isString()) {
|
||||||
ejson::String* tmp2 = tmp->ToString();
|
ejson::String* tmp2 = tmp->toString();
|
||||||
if (NULL!=tmp2) {
|
if (NULL!=tmp2) {
|
||||||
if(tmp2->Get().Size()>40) {
|
if(tmp2->get().size()>40) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -163,192 +160,175 @@ bool ejson::Array::IGenerate(etk::UString& _data, int32_t _indent) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (true==oneLine) {
|
if (true == oneLine) {
|
||||||
_data += "[ ";
|
_data += "[ ";
|
||||||
} else {
|
} else {
|
||||||
_data += "[\n";
|
_data += "[\n";
|
||||||
}
|
}
|
||||||
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
for (esize_t iii=0; iii<m_value.size() ; iii++) {
|
||||||
if (false==oneLine) {
|
if (false == oneLine) {
|
||||||
AddIndent(_data, _indent);
|
addIndent(_data, _indent);
|
||||||
}
|
}
|
||||||
if (NULL != m_value[iii]) {
|
if (NULL != m_value[iii]) {
|
||||||
m_value[iii]->IGenerate(_data, _indent+1);
|
m_value[iii]->iGenerate(_data, _indent+1);
|
||||||
if (iii<m_value.Size()-1) {
|
if (iii<m_value.size()-1) {
|
||||||
_data += ",";
|
_data += ",";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (true==oneLine) {
|
if (true == oneLine) {
|
||||||
_data += " ";
|
_data += " ";
|
||||||
} else {
|
} else {
|
||||||
_data += "\n";
|
_data += "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (false==oneLine) {
|
if (false == oneLine) {
|
||||||
AddIndent(_data, _indent-1);
|
addIndent(_data, _indent-1);
|
||||||
}
|
}
|
||||||
_data += "]";
|
_data += "]";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::Add(ejson::Value* _element)
|
bool ejson::Array::add(ejson::Value* _element) {
|
||||||
{
|
if (NULL == _element) {
|
||||||
if (NULL==_element) {
|
|
||||||
JSON_ERROR("Request add on an NULL pointer");
|
JSON_ERROR("Request add on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_value.PushBack(_element);
|
m_value.pushBack(_element);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::AddString(const etk::UString& _value)
|
bool ejson::Array::addString(const etk::UString& _value) {
|
||||||
{
|
return add(new ejson::String(_value));
|
||||||
return Add(new ejson::String(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::AddNull(void)
|
bool ejson::Array::addNull(void) {
|
||||||
{
|
return add(new ejson::Null());
|
||||||
return Add(new ejson::Null());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::AddBoolean(bool _value)
|
bool ejson::Array::addBoolean(bool _value) {
|
||||||
{
|
return add(new ejson::Boolean(_value));
|
||||||
return Add(new ejson::Boolean(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::AddNumber(double _value)
|
bool ejson::Array::addNumber(double _value) {
|
||||||
{
|
return add(new ejson::Number(_value));
|
||||||
return Add(new ejson::Number(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Array::TransfertIn(ejson::Value* _obj)
|
bool ejson::Array::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::Array* other = _obj->ToArray();
|
ejson::Array* other = _obj->toArray();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an array");
|
JSON_ERROR("Request transfer on an element that is not an array");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// remove destination elements
|
// remove destination elements
|
||||||
other->Clear();
|
other->clear();
|
||||||
// Copy to the destination
|
// Copy to the destination
|
||||||
other->m_value = m_value;
|
other->m_value = m_value;
|
||||||
// remove current:
|
// remove current:
|
||||||
m_value.Clear();
|
m_value.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Manage error ...
|
// TODO : Manage error ...
|
||||||
ejson::Value* ejson::Array::Duplicate(void) const
|
ejson::Value* ejson::Array::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::Array* output = new ejson::Array();
|
ejson::Array* output = new ejson::Array();
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (esize_t iii=0; iii<m_value.Size(); ++iii) {
|
for (esize_t iii=0; iii<m_value.size(); ++iii) {
|
||||||
ejson::Value* val = m_value[iii];
|
ejson::Value* val = m_value[iii];
|
||||||
if (NULL == val) {
|
if (NULL == val) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output->Add(val->Duplicate());
|
output->add(val->duplicate());
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Object* ejson::Array::GetObject(esize_t _id)
|
ejson::Object* ejson::Array::getObject(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToObject();
|
return tmpElement->toObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::String* ejson::Array::GetString(esize_t _id)
|
ejson::String* ejson::Array::getString(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToString();
|
return tmpElement->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Array* ejson::Array::GetArray(esize_t _id)
|
ejson::Array* ejson::Array::getArray(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToArray();
|
return tmpElement->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Null* ejson::Array::GetNull(esize_t _id)
|
ejson::Null* ejson::Array::getNull(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToNull();
|
return tmpElement->toNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Number* ejson::Array::GetNumber(esize_t _id)
|
ejson::Number* ejson::Array::getNumber(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToNumber();
|
return tmpElement->toNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Boolean* ejson::Array::GetBoolean(esize_t _id)
|
ejson::Boolean* ejson::Array::getBoolean(esize_t _id) {
|
||||||
{
|
|
||||||
ejson::Value* tmpElement = m_value[_id];
|
ejson::Value* tmpElement = m_value[_id];
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmpElement->ToBoolean();
|
return tmpElement->toBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
const etk::UString& ejson::Array::GetStringValue(esize_t _id)
|
const etk::UString& ejson::Array::getStringValue(esize_t _id) {
|
||||||
{
|
|
||||||
static const etk::UString errorValue("");
|
static const etk::UString errorValue("");
|
||||||
ejson::String* tmpElement = GetString(_id);
|
ejson::String* tmpElement = getString(_id);
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return errorValue;
|
return errorValue;
|
||||||
}
|
}
|
||||||
return tmpElement->Get();
|
return tmpElement->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
etk::UString ejson::Array::GetStringValue(esize_t _id, const etk::UString& _errorValue)
|
etk::UString ejson::Array::getStringValue(esize_t _id, const etk::UString& _errorValue) {
|
||||||
{
|
ejson::String* tmpElement = getString(_id);
|
||||||
ejson::String* tmpElement = GetString(_id);
|
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpElement->Get();
|
return tmpElement->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
double ejson::Array::GetNumberValue(esize_t _id, double _errorValue)
|
double ejson::Array::getNumberValue(esize_t _id, double _errorValue) {
|
||||||
{
|
ejson::Number* tmpElement = getNumber(_id);
|
||||||
ejson::Number* tmpElement = GetNumber(_id);
|
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpElement->Get();
|
return tmpElement->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Array::GetBooleanValue(esize_t _id, bool _errorValue)
|
bool ejson::Array::getBooleanValue(esize_t _id, bool _errorValue) {
|
||||||
{
|
ejson::Boolean* tmpElement = getBoolean(_id);
|
||||||
ejson::Boolean* tmpElement = GetBoolean(_id);
|
|
||||||
if (NULL == tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpElement->Get();
|
return tmpElement->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,119 +31,119 @@ namespace ejson
|
|||||||
etk::Vector<ejson::Value*> m_value; //!< vector of sub elements
|
etk::Vector<ejson::Value*> m_value; //!< vector of sub elements
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Get the number of sub element in the current one
|
* @brief get the number of sub element in the current one
|
||||||
* @return the Number of stored element
|
* @return the Number of stored element
|
||||||
*/
|
*/
|
||||||
esize_t Size(void) const { return m_value.Size(); };
|
esize_t size(void) const { return m_value.size(); };
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID.
|
* @brief get the pointer on an element reference with his ID.
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
const ejson::Value* Get(esize_t _id) const { return m_value[_id]; };
|
const ejson::Value* get(esize_t _id) const { return m_value[_id]; };
|
||||||
ejson::Value* Get(esize_t _id) { return m_value[_id]; };
|
ejson::Value* get(esize_t _id) { return m_value[_id]; };
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in Object if it is an object).
|
* @brief get the pointer on an element reference with his ID (casted in Object if it is an object).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::Object* GetObject(esize_t _id);
|
ejson::Object* getObject(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in String if it is an String).
|
* @brief get the pointer on an element reference with his ID (casted in String if it is an String).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::String* GetString(esize_t _id);
|
ejson::String* getString(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the value of the string element (if not a string return "")
|
* @brief get the value of the string element (if not a string return "")
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return value of the element.
|
* @return value of the element.
|
||||||
*/
|
*/
|
||||||
const etk::UString& GetStringValue(esize_t _id);
|
const etk::UString& getStringValue(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the value of the string element
|
* @brief get the value of the string element
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @param[in] _errorValue The return value if an error occured.
|
* @param[in] _errorValue The return value if an error occured.
|
||||||
* @return value of the element, or the _errorValue.
|
* @return value of the element, or the _errorValue.
|
||||||
*/
|
*/
|
||||||
etk::UString GetStringValue(esize_t _id, const etk::UString& _errorValue);
|
etk::UString getStringValue(esize_t _id, const etk::UString& _errorValue);
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in Array if it is an Array).
|
* @brief get the pointer on an element reference with his ID (casted in Array if it is an Array).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::Array* GetArray(esize_t _id);
|
ejson::Array* getArray(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in Null if it is an Null).
|
* @brief get the pointer on an element reference with his ID (casted in Null if it is an Null).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::Null* GetNull(esize_t _id);
|
ejson::Null* getNull(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in Number if it is an Number).
|
* @brief get the pointer on an element reference with his ID (casted in Number if it is an Number).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::Number* GetNumber(esize_t _id);
|
ejson::Number* getNumber(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the value of the Number element
|
* @brief get the value of the Number element
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @param[in] _errorValue The return value if an error occured.
|
* @param[in] _errorValue The return value if an error occured.
|
||||||
* @return value of the element, or the _errorValue.
|
* @return value of the element, or the _errorValue.
|
||||||
*/
|
*/
|
||||||
double GetNumberValue(esize_t _id, double _errorValue);
|
double getNumberValue(esize_t _id, double _errorValue);
|
||||||
/**
|
/**
|
||||||
* @brief Get the pointer on an element reference with his ID (casted in Boolean if it is an Boolean).
|
* @brief get the pointer on an element reference with his ID (casted in Boolean if it is an Boolean).
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @return NULL if the element does not exist.
|
* @return NULL if the element does not exist.
|
||||||
*/
|
*/
|
||||||
ejson::Boolean* GetBoolean(esize_t _id);
|
ejson::Boolean* getBoolean(esize_t _id);
|
||||||
/**
|
/**
|
||||||
* @brief Get the value of the Boolean element
|
* @brief get the value of the Boolean element
|
||||||
* @param[in] _id Id of the element.
|
* @param[in] _id Id of the element.
|
||||||
* @param[in] _errorValue The return value if an error occured.
|
* @param[in] _errorValue The return value if an error occured.
|
||||||
* @return value of the element, or the _errorValue.
|
* @return value of the element, or the _errorValue.
|
||||||
*/
|
*/
|
||||||
bool GetBooleanValue(esize_t _id, bool _errorValue);
|
bool getBooleanValue(esize_t _id, bool _errorValue);
|
||||||
/**
|
/**
|
||||||
* @brief Add an element on the array.
|
* @brief add an element on the array.
|
||||||
* @param[in] _element element to add.
|
* @param[in] _element element to add.
|
||||||
* @return false if an error occured.
|
* @return false if an error occured.
|
||||||
*/
|
*/
|
||||||
bool Add(ejson::Value* _element);
|
bool add(ejson::Value* _element);
|
||||||
/**
|
/**
|
||||||
* @brief Add a string element in the Object (automatic creation)
|
* @brief add a string element in the Object (automatic creation)
|
||||||
* @param[in] _value string value to add
|
* @param[in] _value string value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddString(const etk::UString& _value);
|
bool addString(const etk::UString& _value);
|
||||||
/**
|
/**
|
||||||
* @brief Add a "null" element in the Object (automatic creation)
|
* @brief add a "null" element in the Object (automatic creation)
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddNull(void);
|
bool addNull(void);
|
||||||
/**
|
/**
|
||||||
* @brief Add a boolean element in the Object (automatic creation)
|
* @brief add a boolean element in the Object (automatic creation)
|
||||||
* @param[in] _value boolean value to add
|
* @param[in] _value boolean value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddBoolean(bool _value);
|
bool addBoolean(bool _value);
|
||||||
/**
|
/**
|
||||||
* @brief Add a double element in the Object (automatic creation)
|
* @brief add a double element in the Object (automatic creation)
|
||||||
* @param[in] _value double value to add
|
* @param[in] _value double value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddNumber(double _value);
|
bool addNumber(double _value);
|
||||||
|
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeArray; };
|
virtual nodeType_te getType(void) const { return typeArray; };
|
||||||
virtual ejson::Array* ToArray(void) { return this; };
|
virtual ejson::Array* toArray(void) { return this; };
|
||||||
virtual const ejson::Array* ToArray(void) const{ return this; };
|
virtual const ejson::Array* toArray(void) const{ return this; };
|
||||||
virtual void Clear(void);
|
virtual void clear(void);
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,11 +13,10 @@
|
|||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "Boolean"
|
#define __class__ "Boolean"
|
||||||
|
|
||||||
bool ejson::Boolean::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Boolean::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
JSON_PARSE_ELEMENT("start parse : 'Boolean' ");
|
JSON_PARSE_ELEMENT("start parse : 'Boolean' ");
|
||||||
if( _data[_pos] == 't'
|
if( _data[_pos] == 't'
|
||||||
&& _pos+3 < _data.Size()
|
&& _pos+3 < _data.size()
|
||||||
&& _data[_pos+1] == 'r'
|
&& _data[_pos+1] == 'r'
|
||||||
&& _data[_pos+2] == 'u'
|
&& _data[_pos+2] == 'u'
|
||||||
&& _data[_pos+3] == 'e'){
|
&& _data[_pos+3] == 'e'){
|
||||||
@ -27,7 +26,7 @@ bool ejson::Boolean::IParse(const etk::UString& _data, int32_t& _pos, ejson::fil
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if( _data[_pos] == 'f'
|
if( _data[_pos] == 'f'
|
||||||
&& _pos+4 < _data.Size()
|
&& _pos+4 < _data.size()
|
||||||
&& _data[_pos+1] == 'a'
|
&& _data[_pos+1] == 'a'
|
||||||
&& _data[_pos+2] == 'l'
|
&& _data[_pos+2] == 'l'
|
||||||
&& _data[_pos+3] == 's'
|
&& _data[_pos+3] == 's'
|
||||||
@ -42,9 +41,8 @@ bool ejson::Boolean::IParse(const etk::UString& _data, int32_t& _pos, ejson::fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Boolean::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Boolean::iGenerate(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
if (true == m_value) {
|
||||||
if (true==m_value) {
|
|
||||||
_data += "true";
|
_data += "true";
|
||||||
} else {
|
} else {
|
||||||
_data += "false";
|
_data += "false";
|
||||||
@ -53,14 +51,13 @@ bool ejson::Boolean::IGenerate(etk::UString& _data, int32_t _indent) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Boolean::TransfertIn(ejson::Value* _obj)
|
bool ejson::Boolean::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::Boolean* other = _obj->ToBoolean();
|
ejson::Boolean* other = _obj->toBoolean();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an Boolean");
|
JSON_ERROR("Request transfer on an element that is not an Boolean");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -70,10 +67,9 @@ bool ejson::Boolean::TransfertIn(ejson::Value* _obj)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Value* ejson::Boolean::Duplicate(void) const
|
ejson::Value* ejson::Boolean::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::Boolean* output = new ejson::Boolean(m_value);
|
ejson::Boolean* output = new ejson::Boolean(m_value);
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -31,23 +31,23 @@ namespace ejson
|
|||||||
bool m_value; //!< value of the node
|
bool m_value; //!< value of the node
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Set the value of the node.
|
* @brief set the value of the node.
|
||||||
* @param[in] _value New value of the node.
|
* @param[in] _value New value of the node.
|
||||||
*/
|
*/
|
||||||
void Set(bool _value) { m_value = _value; };
|
void set(bool _value) { m_value = _value; };
|
||||||
/**
|
/**
|
||||||
* @brief Get the current element Value.
|
* @brief get the current element Value.
|
||||||
* @return the reference of the string value.
|
* @return the reference of the string value.
|
||||||
*/
|
*/
|
||||||
bool Get(void) const { return m_value; };
|
bool get(void) const { return m_value; };
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeString; };
|
virtual nodeType_te getType(void) const { return typeString; };
|
||||||
virtual ejson::Boolean* ToBoolean(void) { return this; };
|
virtual ejson::Boolean* toBoolean(void) { return this; };
|
||||||
virtual const ejson::Boolean* ToBoolean(void) const{ return this; };
|
virtual const ejson::Boolean* toBoolean(void) const{ return this; };
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,10 +14,9 @@
|
|||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "Null"
|
#define __class__ "Null"
|
||||||
|
|
||||||
bool ejson::Null::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Null::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
JSON_PARSE_ELEMENT("start parse : 'Null' ");
|
JSON_PARSE_ELEMENT("start parse : 'Null' ");
|
||||||
if (_pos+3 >= _data.Size()){
|
if (_pos+3 >= _data.size()){
|
||||||
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! ");
|
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "can not parse null !!! ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -34,31 +33,28 @@ bool ejson::Null::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Null::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Null::iGenerate(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
|
||||||
_data += "null";
|
_data += "null";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Null::TransfertIn(ejson::Value* _obj)
|
bool ejson::Null::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::Null* other = _obj->ToNull();
|
ejson::Null* other = _obj->toNull();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an Null");
|
JSON_ERROR("Request transfer on an element that is not an Null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Value* ejson::Null::Duplicate(void) const
|
ejson::Value* ejson::Null::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::Null* output = new ejson::Null();
|
ejson::Null* output = new ejson::Null();
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
14
ejson/Null.h
14
ejson/Null.h
@ -28,13 +28,13 @@ namespace ejson
|
|||||||
*/
|
*/
|
||||||
virtual ~Null(void) { };
|
virtual ~Null(void) { };
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeString; };
|
virtual nodeType_te getType(void) const { return typeString; };
|
||||||
virtual ejson::Null* ToNull(void) { return this; };
|
virtual ejson::Null* toNull(void) { return this; };
|
||||||
virtual const ejson::Null* ToNull(void) const{ return this; };
|
virtual const ejson::Null* toNull(void) const{ return this; };
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,45 +14,42 @@
|
|||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "Number"
|
#define __class__ "Number"
|
||||||
|
|
||||||
bool ejson::Number::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Number::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
JSON_PARSE_ELEMENT("start parse : 'Number' ");
|
JSON_PARSE_ELEMENT("start parse : 'Number' ");
|
||||||
etk::UString tmpVal;
|
etk::UString tmpVal;
|
||||||
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
|
for (int32_t iii=_pos; 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(true==CheckNumber(_data[iii])) {
|
if(true == checkNumber(_data[iii])) {
|
||||||
tmpVal+=_data[iii];
|
tmpVal+=_data[iii];
|
||||||
} else {
|
} else {
|
||||||
_pos = iii-1;
|
_pos = iii-1;
|
||||||
m_value = tmpVal.ToDouble();
|
m_value = tmpVal.toDouble();
|
||||||
JSON_PARSE_ELEMENT("end parse : 'Number' ");
|
JSON_PARSE_ELEMENT("end parse : 'Number' ");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pos=_data.Size();
|
_pos=_data.size();
|
||||||
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "get end of string whithout fincding end of quote");
|
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "get end of string whithout fincding end of quote");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Number::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Number::iGenerate(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
|
||||||
_data += m_value;
|
_data += m_value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Number::TransfertIn(ejson::Value* _obj)
|
bool ejson::Number::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::Number* other = _obj->ToNumber();
|
ejson::Number* other = _obj->toNumber();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an Number");
|
JSON_ERROR("Request transfer on an element that is not an Number");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -62,10 +59,9 @@ bool ejson::Number::TransfertIn(ejson::Value* _obj)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Value* ejson::Number::Duplicate(void) const
|
ejson::Value* ejson::Number::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::Number* output = new ejson::Number(m_value);
|
ejson::Number* output = new ejson::Number(m_value);
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -31,25 +31,25 @@ namespace ejson
|
|||||||
double m_value; //!< value of the node
|
double m_value; //!< value of the node
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Set the value of the node.
|
* @brief set the value of the node.
|
||||||
* @param[in] _value New value of the node.
|
* @param[in] _value New value of the node.
|
||||||
*/
|
*/
|
||||||
void Set(double _value) { m_value = _value; };
|
void set(double _value) { m_value = _value; };
|
||||||
/**
|
/**
|
||||||
* @brief Get the current element Value.
|
* @brief get the current element Value.
|
||||||
* @return the reference of the string value.
|
* @return the reference of the string value.
|
||||||
*/
|
*/
|
||||||
double Get(void) const { return m_value; };
|
double get(void) const { return m_value; };
|
||||||
int32_t GetInt32(void) const { return (int32_t)m_value; };
|
int32_t getInt32(void) const { return (int32_t)m_value; };
|
||||||
int64_t GetInt64(void) const { return (int64_t)m_value; };
|
int64_t getInt64(void) const { return (int64_t)m_value; };
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeString; };
|
virtual nodeType_te getType(void) const { return typeString; };
|
||||||
virtual ejson::Number* ToNumber(void) { return this; };
|
virtual ejson::Number* toNumber(void) { return this; };
|
||||||
virtual const ejson::Number* ToNumber(void) const{ return this; };
|
virtual const ejson::Number* toNumber(void) const{ return this; };
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
284
ejson/Object.cpp
284
ejson/Object.cpp
@ -19,16 +19,15 @@
|
|||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "Object"
|
#define __class__ "Object"
|
||||||
|
|
||||||
void ejson::Object::Clear(void)
|
void ejson::Object::clear(void) {
|
||||||
{
|
for (esize_t iii=0; iii<m_value.size(); ++iii) {
|
||||||
for (esize_t iii=0; iii<m_value.Size(); ++iii) {
|
|
||||||
if (NULL == m_value[iii]) {
|
if (NULL == m_value[iii]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
delete(m_value[iii]);
|
delete(m_value[iii]);
|
||||||
m_value[iii] = NULL;
|
m_value[iii] = NULL;
|
||||||
}
|
}
|
||||||
m_value.Clear();
|
m_value.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,8 +37,7 @@ typedef enum {
|
|||||||
parseValue,
|
parseValue,
|
||||||
} statusParsing_te;
|
} statusParsing_te;
|
||||||
|
|
||||||
bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Object::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
statusParsing_te mode = parseName;
|
statusParsing_te mode = parseName;
|
||||||
etk::UString currentName;
|
etk::UString currentName;
|
||||||
JSON_PARSE_ELEMENT("start parse : 'Object' ");
|
JSON_PARSE_ELEMENT("start parse : 'Object' ");
|
||||||
@ -49,46 +47,46 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
standalone = false;
|
standalone = false;
|
||||||
startPos = _pos;
|
startPos = _pos;
|
||||||
}
|
}
|
||||||
for (int32_t iii=startPos; iii<_data.Size(); iii++) {
|
for (int32_t iii=startPos; 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
|
||||||
ejson::filePos tmpPos;
|
ejson::filePos tmpPos;
|
||||||
if( _data[iii]==' '
|
if( _data[iii] == ' '
|
||||||
|| _data[iii]=='\t'
|
|| _data[iii] == '\t'
|
||||||
|| _data[iii]=='\n'
|
|| _data[iii] == '\n'
|
||||||
|| _data[iii]=='\r') {
|
|| _data[iii] == '\r') {
|
||||||
// white space ==> nothing to do ...
|
// white space == > nothing to do ...
|
||||||
} else if(_data[iii]=='}') {
|
} else if(_data[iii] == '}') {
|
||||||
// find end of value:
|
// find end of value:
|
||||||
_pos=iii; // ==> return the end element type ==> usefull to check end and check if adding element is needed
|
_pos=iii; // == > return the end element type ==> usefull to check end and check if adding element is needed
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (mode == parseName) {
|
if (mode == parseName) {
|
||||||
JSON_PARSE_ELEMENT("name START " << '"');
|
JSON_PARSE_ELEMENT("name START " << '"');
|
||||||
if (_data[iii]=='"') {
|
if (_data[iii] == '"') {
|
||||||
currentName = "";
|
currentName = "";
|
||||||
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 (_data[iii]=='\"') {
|
if (_data[iii] == '\"') {
|
||||||
mode = parseMiddle;
|
mode = parseMiddle;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
currentName += _data[iii];
|
currentName += _data[iii];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (CheckString(_data[iii]) ) {
|
} else if (checkString(_data[iii]) ) {
|
||||||
currentName += _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 (false==CheckString(_data[iii])) {
|
if (false == checkString(_data[iii])) {
|
||||||
mode = parseMiddle;
|
mode = parseMiddle;
|
||||||
iii--;
|
iii--;
|
||||||
break;
|
break;
|
||||||
@ -104,87 +102,87 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
JSON_PARSE_ELEMENT("name END ");
|
JSON_PARSE_ELEMENT("name END ");
|
||||||
} else if (mode == parseMiddle) {
|
} else if (mode == parseMiddle) {
|
||||||
JSON_PARSE_ELEMENT(" middle ... ");
|
JSON_PARSE_ELEMENT(" middle ... ");
|
||||||
if (_data[iii]==':') {
|
if (_data[iii] == ':') {
|
||||||
mode = parseValue;
|
mode = parseValue;
|
||||||
} else {
|
} else {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "separator is not ':'");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "separator is not ':'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (mode == parseValue) {
|
} else if (mode == parseValue) {
|
||||||
if (_data[iii]=='{') {
|
if (_data[iii] == '{') {
|
||||||
// find an object:
|
// find an object:
|
||||||
JSON_PARSE_ELEMENT("find Object");
|
JSON_PARSE_ELEMENT("find Object");
|
||||||
ejson::Object * tmpElement = new ejson::Object();
|
ejson::Object * tmpElement = new ejson::Object();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in object");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
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");
|
||||||
ejson::String * tmpElement = new ejson::String();
|
ejson::String * tmpElement = new ejson::String();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in String");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
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");
|
||||||
ejson::Array * tmpElement = new ejson::Array();
|
ejson::Array * tmpElement = new ejson::Array();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Array");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
currentName = "";
|
||||||
} else if( _data[iii] == 'f'
|
} else if( _data[iii] == 'f'
|
||||||
|| _data[iii] == 't' ) {
|
|| _data[iii] == 't' ) {
|
||||||
// find boolean:
|
// find boolean:
|
||||||
JSON_PARSE_ELEMENT("find Boolean");
|
JSON_PARSE_ELEMENT("find Boolean");
|
||||||
ejson::Boolean * tmpElement = new ejson::Boolean();
|
ejson::Boolean * tmpElement = new ejson::Boolean();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
currentName = "";
|
||||||
} else if( _data[iii] == 'n') {
|
} else if( _data[iii] == 'n') {
|
||||||
// find null:
|
// find null:
|
||||||
JSON_PARSE_ELEMENT("find Null");
|
JSON_PARSE_ELEMENT("find Null");
|
||||||
ejson::Null * tmpElement = new ejson::Null();
|
ejson::Null * tmpElement = new ejson::Null();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
currentName = "";
|
||||||
} else if(true==CheckNumber(_data[iii])) {
|
} else if(true == checkNumber(_data[iii])) {
|
||||||
// find number:
|
// find number:
|
||||||
JSON_PARSE_ELEMENT("find Number");
|
JSON_PARSE_ELEMENT("find Number");
|
||||||
ejson::Number * tmpElement = new ejson::Number();
|
ejson::Number * tmpElement = new ejson::Number();
|
||||||
if (NULL==tmpElement) {
|
if (NULL == tmpElement) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Allocation error in Boolean");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpElement->IParse(_data, iii, _filePos, _doc);
|
tmpElement->iParse(_data, iii, _filePos, _doc);
|
||||||
Add(currentName, tmpElement);
|
add(currentName, tmpElement);
|
||||||
currentName = "";
|
currentName = "";
|
||||||
} else if(_data[iii]==',') {
|
} else if(_data[iii] == ',') {
|
||||||
// find Separator : Restart cycle ...
|
// find Separator : Restart cycle ...
|
||||||
mode = parseName;
|
mode = parseName;
|
||||||
currentName = "";
|
currentName = "";
|
||||||
@ -198,38 +196,37 @@ bool ejson::Object::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pos = _data.Size();
|
_pos = _data.size();
|
||||||
if (false==standalone) {
|
if (false == standalone) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::Object::iGenerate(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
|
||||||
bool oneLine=true;
|
bool oneLine=true;
|
||||||
if (m_value.Size()>3) {
|
if (m_value.size()>3) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
} else if (_indent<=1) {
|
} else if (_indent<=1) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
} else {
|
} else {
|
||||||
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
for (esize_t iii=0; iii<m_value.size() ; iii++) {
|
||||||
ejson::Value* tmp = m_value[iii];
|
ejson::Value* tmp = m_value[iii];
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsObject()) {
|
if (true == tmp->isObject()) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsArray()) {
|
if (true == tmp->isArray()) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (true==tmp->IsString()) {
|
if (true == tmp->isString()) {
|
||||||
ejson::String* tmp2 = tmp->ToString();
|
ejson::String* tmp2 = tmp->toString();
|
||||||
if (NULL!=tmp2) {
|
if (NULL!=tmp2) {
|
||||||
if( tmp2->Get().Size()>25
|
if( tmp2->get().size()>25
|
||||||
|| m_value.GetKey(iii).Size()>25) {
|
|| m_value.getKey(iii).size()>25) {
|
||||||
oneLine=false;
|
oneLine=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -237,213 +234,194 @@ bool ejson::Object::IGenerate(etk::UString& _data, int32_t _indent) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (true==oneLine) {
|
if (true == oneLine) {
|
||||||
_data += "{ ";
|
_data += "{ ";
|
||||||
} else {
|
} else {
|
||||||
_data += "{\n";
|
_data += "{\n";
|
||||||
}
|
}
|
||||||
for (esize_t iii=0; iii<m_value.Size() ; iii++) {
|
for (esize_t iii=0; iii<m_value.size() ; iii++) {
|
||||||
if (false==oneLine) {
|
if (false == oneLine) {
|
||||||
AddIndent(_data, _indent);
|
addIndent(_data, _indent);
|
||||||
}
|
}
|
||||||
_data += "\"";
|
_data += "\"";
|
||||||
_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) {
|
if (iii<m_value.size()-1) {
|
||||||
_data += ",";
|
_data += ",";
|
||||||
}
|
}
|
||||||
if (true==oneLine) {
|
if (true == oneLine) {
|
||||||
_data += " ";
|
_data += " ";
|
||||||
} else {
|
} else {
|
||||||
_data += "\n";
|
_data += "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (false==oneLine) {
|
if (false == oneLine) {
|
||||||
AddIndent(_data, _indent-1);
|
addIndent(_data, _indent-1);
|
||||||
}
|
}
|
||||||
_data += "}";
|
_data += "}";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::Exist(const etk::UString& _name) const
|
bool ejson::Object::exist(const etk::UString& _name) const {
|
||||||
{
|
return m_value.exist(_name);
|
||||||
return m_value.Exist(_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Value* ejson::Object::Get(const etk::UString& _name) const
|
ejson::Value* ejson::Object::get(const etk::UString& _name) const {
|
||||||
{
|
if (false == m_value.exist(_name)) {
|
||||||
if (false==m_value.Exist(_name)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return m_value[_name];
|
return m_value[_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Object* ejson::Object::GetObject(const etk::UString& _name) const
|
ejson::Object* ejson::Object::getObject(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToObject();
|
return tmp->toObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Array* ejson::Object::GetArray(const etk::UString& _name) const
|
ejson::Array* ejson::Object::getArray(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToArray();
|
return tmp->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Null* ejson::Object::GetNull(const etk::UString& _name) const
|
ejson::Null* ejson::Object::getNull(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToNull();
|
return tmp->toNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::String* ejson::Object::GetString(const etk::UString& _name) const
|
ejson::String* ejson::Object::getString(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToString();
|
return tmp->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const etk::UString& ejson::Object::GetStringValue(const etk::UString& _name) const
|
const etk::UString& ejson::Object::getStringValue(const etk::UString& _name) const {
|
||||||
{
|
|
||||||
static const etk::UString errorString("");
|
static const etk::UString errorString("");
|
||||||
ejson::String* tmpp = GetString(_name);
|
ejson::String* tmpp = getString(_name);
|
||||||
if (NULL==tmpp) {
|
if (NULL == tmpp) {
|
||||||
return errorString;
|
return errorString;
|
||||||
}
|
}
|
||||||
return tmpp->Get();
|
return tmpp->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
etk::UString ejson::Object::GetStringValue(const etk::UString& _name, const etk::UString& _errorValue) const
|
etk::UString ejson::Object::getStringValue(const etk::UString& _name, const etk::UString& _errorValue) const {
|
||||||
{
|
ejson::String* tmpp = getString(_name);
|
||||||
ejson::String* tmpp = GetString(_name);
|
if (NULL == tmpp) {
|
||||||
if (NULL==tmpp) {
|
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpp->Get();
|
return tmpp->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Boolean* ejson::Object::GetBoolean(const etk::UString& _name) const
|
ejson::Boolean* ejson::Object::getBoolean(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToBoolean();
|
return tmp->toBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::GetBooleanValue(const etk::UString& _name, bool _errorValue) const
|
bool ejson::Object::getBooleanValue(const etk::UString& _name, bool _errorValue) const {
|
||||||
{
|
ejson::Boolean* tmpp = getBoolean(_name);
|
||||||
ejson::Boolean* tmpp = GetBoolean(_name);
|
if (NULL == tmpp) {
|
||||||
if (NULL==tmpp) {
|
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpp->Get();
|
return tmpp->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Number* ejson::Object::GetNumber(const etk::UString& _name) const
|
ejson::Number* ejson::Object::getNumber(const etk::UString& _name) const {
|
||||||
{
|
ejson::Value* tmp = get(_name);
|
||||||
ejson::Value* tmp = Get(_name);
|
|
||||||
if (NULL == tmp) {
|
if (NULL == tmp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return tmp->ToNumber();
|
return tmp->toNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
double ejson::Object::GetNumberValue(const etk::UString& _name, double _errorValue) const
|
double ejson::Object::getNumberValue(const etk::UString& _name, double _errorValue) const {
|
||||||
{
|
ejson::Number* tmpp = getNumber(_name);
|
||||||
ejson::Number* tmpp = GetNumber(_name);
|
if (NULL == tmpp) {
|
||||||
if (NULL==tmpp) {
|
|
||||||
return _errorValue;
|
return _errorValue;
|
||||||
}
|
}
|
||||||
return tmpp->Get();
|
return tmpp->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Object::Add(const etk::UString& _name, ejson::Value* _value)
|
bool ejson::Object::add(const etk::UString& _name, ejson::Value* _value) {
|
||||||
{
|
|
||||||
if (NULL == _value) {
|
if (NULL == _value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_name.Size()==0) {
|
if (_name.size() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_value.Exist(_name)) {
|
if (m_value.exist(_name)) {
|
||||||
ejson::Value* tmp = m_value[_name];
|
ejson::Value* tmp = m_value[_name];
|
||||||
delete(tmp);
|
delete(tmp);
|
||||||
m_value[_name] = _value;
|
m_value[_name] = _value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_value.Add(_name, _value);
|
m_value.add(_name, _value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::AddString(const etk::UString& _name, const etk::UString& _value)
|
bool ejson::Object::addString(const etk::UString& _name, const etk::UString& _value) {
|
||||||
{
|
return add(_name, new ejson::String(_value));
|
||||||
return Add(_name, new ejson::String(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::AddNull(const etk::UString& _name)
|
bool ejson::Object::addNull(const etk::UString& _name) {
|
||||||
{
|
return add(_name, new ejson::Null());
|
||||||
return Add(_name, new ejson::Null());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::AddBoolean(const etk::UString& _name, bool _value)
|
bool ejson::Object::addBoolean(const etk::UString& _name, bool _value) {
|
||||||
{
|
return add(_name, new ejson::Boolean(_value));
|
||||||
return Add(_name, new ejson::Boolean(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::AddNumber(const etk::UString& _name, double _value)
|
bool ejson::Object::addNumber(const etk::UString& _name, double _value) {
|
||||||
{
|
return add(_name, new ejson::Number(_value));
|
||||||
return Add(_name, new ejson::Number(_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Object::TransfertIn(ejson::Value* _obj)
|
bool ejson::Object::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::Object* other = _obj->ToObject();
|
ejson::Object* other = _obj->toObject();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an object");
|
JSON_ERROR("Request transfer on an element that is not an object");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// remove destination elements
|
// remove destination elements
|
||||||
other->Clear();
|
other->clear();
|
||||||
// Copy to the destination
|
// Copy to the destination
|
||||||
other->m_value = m_value;
|
other->m_value = m_value;
|
||||||
// remove current:
|
// remove current:
|
||||||
m_value.Clear();
|
m_value.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Manage error ...
|
// TODO : Manage error ...
|
||||||
ejson::Value* ejson::Object::Duplicate(void) const
|
ejson::Value* ejson::Object::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::Object* output = new ejson::Object();
|
ejson::Object* output = new ejson::Object();
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (esize_t iii=0; iii<m_value.Size(); ++iii) {
|
for (esize_t iii=0; iii<m_value.size(); ++iii) {
|
||||||
ejson::Value* val = m_value.GetValue(iii);
|
ejson::Value* val = m_value.getValue(iii);
|
||||||
etk::UString key = m_value.GetKey(iii);
|
etk::UString key = m_value.getKey(iii);
|
||||||
if (NULL == val) {
|
if (NULL == val) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output->Add(key, val->Duplicate());
|
output->add(key, val->duplicate());
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -32,124 +32,124 @@ namespace ejson
|
|||||||
etk::Hash<ejson::Value*> m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
etk::Hash<ejson::Value*> m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Check if an element exist.
|
* @brief check if an element exist.
|
||||||
* @param[in] _name name of the object.
|
* @param[in] _name name of the object.
|
||||||
* @return The existance of the element.
|
* @return The existance of the element.
|
||||||
*/
|
*/
|
||||||
bool Exist(const etk::UString& _name) const;
|
bool exist(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (no cast check)
|
* @brief get the sub element with his name (no cast check)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Value* Get(const etk::UString& _name) const;
|
ejson::Value* get(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as Object if it is possible)
|
* @brief get the sub element with his name (Casted as Object if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Object* GetObject(const etk::UString& _name) const;
|
ejson::Object* getObject(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as Array if it is possible)
|
* @brief get the sub element with his name (Casted as Array if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Array* GetArray(const etk::UString& _name) const;
|
ejson::Array* getArray(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as Null if it is possible)
|
* @brief get the sub element with his name (Casted as Null if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Null* GetNull(const etk::UString& _name) const;
|
ejson::Null* getNull(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as String if it is possible)
|
* @brief get the sub element with his name (Casted as String if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::String* GetString(const etk::UString& _name) const;
|
ejson::String* getString(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub string value of the requested element
|
* @brief get the sub string value of the requested element
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return Value of the string or an error string (empty)
|
* @return Value of the string or an error string (empty)
|
||||||
*/
|
*/
|
||||||
const etk::UString& GetStringValue(const etk::UString& _name) const;
|
const etk::UString& getStringValue(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub string value of the requested element (with error return value)
|
* @brief get the sub string value of the requested element (with error return value)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @param[in] _errorValue The return value if the element does not exist.
|
* @param[in] _errorValue The return value if the element does not exist.
|
||||||
* @return Value of the string or an error string (empty)
|
* @return Value of the string or an error string (empty)
|
||||||
*/
|
*/
|
||||||
etk::UString GetStringValue(const etk::UString& _name, const etk::UString& _errorValue) const;
|
etk::UString getStringValue(const etk::UString& _name, const etk::UString& _errorValue) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as Boolean if it is possible)
|
* @brief get the sub element with his name (Casted as Boolean if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Boolean* GetBoolean(const etk::UString& _name) const;
|
ejson::Boolean* getBoolean(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub boolean value of the requested element.
|
* @brief get the sub boolean value of the requested element.
|
||||||
* @param[in] _name name of the object.
|
* @param[in] _name name of the object.
|
||||||
* @param[in] _errorValue The return value if the element does not exist.
|
* @param[in] _errorValue The return value if the element does not exist.
|
||||||
* @return Value of the Boolean or the _errorValue;
|
* @return Value of the Boolean or the _errorValue;
|
||||||
*/
|
*/
|
||||||
bool GetBooleanValue(const etk::UString& _name, bool _errorValue=false) const;
|
bool getBooleanValue(const etk::UString& _name, bool _errorValue=false) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub element with his name (Casted as Number if it is possible)
|
* @brief get the sub element with his name (Casted as Number if it is possible)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
* @return pointer on the element requested or NULL if it not the corect type or does not existed
|
||||||
*/
|
*/
|
||||||
ejson::Number* GetNumber(const etk::UString& _name) const;
|
ejson::Number* getNumber(const etk::UString& _name) const;
|
||||||
/**
|
/**
|
||||||
* @brief Get the sub Number value of the requested element.
|
* @brief get the sub Number value of the requested element.
|
||||||
* @param[in] _name name of the object.
|
* @param[in] _name name of the object.
|
||||||
* @param[in] _errorValue The return value if the element does not exist.
|
* @param[in] _errorValue The return value if the element does not exist.
|
||||||
* @return Value of the Number or the _errorValue;
|
* @return Value of the Number or the _errorValue;
|
||||||
*/
|
*/
|
||||||
double GetNumberValue(const etk::UString& _name, double _errorValue=false) const;
|
double getNumberValue(const etk::UString& _name, double _errorValue=false) const;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Add an element in the Object
|
* @brief add an element in the Object
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @param[in] _value Element to add
|
* @param[in] _value Element to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool Add(const etk::UString& _name, ejson::Value* _value);
|
bool add(const etk::UString& _name, ejson::Value* _value);
|
||||||
/**
|
/**
|
||||||
* @brief Add a string element in the Object (automatic creation)
|
* @brief add a string element in the Object (automatic creation)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @param[in] _value string value to add
|
* @param[in] _value string value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddString(const etk::UString& _name, const etk::UString& _value);
|
bool addString(const etk::UString& _name, const etk::UString& _value);
|
||||||
/**
|
/**
|
||||||
* @brief Add a "null" element in the Object (automatic creation)
|
* @brief add a "null" element in the Object (automatic creation)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddNull(const etk::UString& _name);
|
bool addNull(const etk::UString& _name);
|
||||||
/**
|
/**
|
||||||
* @brief Add a boolean element in the Object (automatic creation)
|
* @brief add a boolean element in the Object (automatic creation)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @param[in] _value boolean value to add
|
* @param[in] _value boolean value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddBoolean(const etk::UString& _name, bool _value);
|
bool addBoolean(const etk::UString& _name, bool _value);
|
||||||
/**
|
/**
|
||||||
* @brief Add a double element in the Object (automatic creation)
|
* @brief add a double element in the Object (automatic creation)
|
||||||
* @param[in] _name name of the object
|
* @param[in] _name name of the object
|
||||||
* @param[in] _value double value to add
|
* @param[in] _value double value to add
|
||||||
* @return false if an error occured
|
* @return false if an error occured
|
||||||
*/
|
*/
|
||||||
bool AddNumber(const etk::UString& _name, double _value);
|
bool addNumber(const etk::UString& _name, double _value);
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeObject; };
|
virtual nodeType_te getType(void) const { return typeObject; };
|
||||||
virtual ejson::Object* ToObject(void) { return this; };
|
virtual ejson::Object* toObject(void) { return this; };
|
||||||
virtual const ejson::Object* ToObject(void) const{ return this; };
|
virtual const ejson::Object* toObject(void) const{ return this; };
|
||||||
virtual void Clear(void);
|
virtual void clear(void);
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,13 +18,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::String::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
JSON_PARSE_ELEMENT("start parse : 'String' ");
|
JSON_PARSE_ELEMENT("start parse : 'String' ");
|
||||||
for (int32_t iii=_pos+1; iii<_data.Size(); iii++) {
|
for (int32_t iii=_pos+1; 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
|
||||||
ejson::filePos tmpPos;
|
ejson::filePos tmpPos;
|
||||||
// TODO : manage \x
|
// TODO : manage \x
|
||||||
@ -35,14 +34,13 @@ bool ejson::String::IParse(const etk::UString& _data, int32_t& _pos, ejson::file
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pos=_data.Size();
|
_pos=_data.size();
|
||||||
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "get end of string whithout fincding end of quote");
|
EJSON_CREATE_ERROR(_doc, _data, _pos, _filePos, "get end of string whithout fincding end of quote");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::String::IGenerate(etk::UString& _data, int32_t _indent) const
|
bool ejson::String::iGenerate(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
|
||||||
_data += "\"";;
|
_data += "\"";;
|
||||||
_data += m_value;
|
_data += m_value;
|
||||||
_data += "\"";;
|
_data += "\"";;
|
||||||
@ -50,14 +48,13 @@ bool ejson::String::IGenerate(etk::UString& _data, int32_t _indent) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::String::TransfertIn(ejson::Value* _obj)
|
bool ejson::String::transfertIn(ejson::Value* _obj) {
|
||||||
{
|
if (NULL == _obj) {
|
||||||
if (NULL==_obj) {
|
|
||||||
JSON_ERROR("Request transfer on an NULL pointer");
|
JSON_ERROR("Request transfer on an NULL pointer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ejson::String* other = _obj->ToString();
|
ejson::String* other = _obj->toString();
|
||||||
if (NULL==other) {
|
if (NULL == other) {
|
||||||
JSON_ERROR("Request transfer on an element that is not an String");
|
JSON_ERROR("Request transfer on an element that is not an String");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -66,10 +63,9 @@ bool ejson::String::TransfertIn(ejson::Value* _obj)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Value* ejson::String::Duplicate(void) const
|
ejson::Value* ejson::String::duplicate(void) const {
|
||||||
{
|
|
||||||
ejson::String* output = new ejson::String(m_value);
|
ejson::String* output = new ejson::String(m_value);
|
||||||
if (NULL==output) {
|
if (NULL == output) {
|
||||||
JSON_ERROR("Allocation error ...");
|
JSON_ERROR("Allocation error ...");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -31,23 +31,23 @@ namespace ejson
|
|||||||
etk::UString m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
etk::UString m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Set the value of the node.
|
* @brief set the value of the node.
|
||||||
* @param[in] _value New value of the node.
|
* @param[in] _value New value of the node.
|
||||||
*/
|
*/
|
||||||
void Set(const etk::UString& _value) { m_value = _value; };
|
void set(const etk::UString& _value) { m_value = _value; };
|
||||||
/**
|
/**
|
||||||
* @brief Get the current element Value.
|
* @brief get the current element Value.
|
||||||
* @return the reference of the string value.
|
* @return the reference of the string value.
|
||||||
*/
|
*/
|
||||||
const etk::UString& Get(void) const { return m_value; };
|
const etk::UString& get(void) const { return m_value; };
|
||||||
public: // herited function :
|
public: // herited function :
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual nodeType_te GetType(void) const { return typeString; };
|
virtual nodeType_te getType(void) const { return typeString; };
|
||||||
virtual ejson::String* ToString(void) { return this; };
|
virtual ejson::String* toString(void) { return this; };
|
||||||
virtual const ejson::String* ToString(void) const{ return this; };
|
virtual const ejson::String* toString(void) const{ return this; };
|
||||||
virtual bool TransfertIn(ejson::Value* _obj);
|
virtual bool transfertIn(ejson::Value* _obj);
|
||||||
virtual ejson::Value* Duplicate(void) const;
|
virtual ejson::Value* duplicate(void) const;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,47 +14,42 @@
|
|||||||
#define __class__ "Value"
|
#define __class__ "Value"
|
||||||
|
|
||||||
|
|
||||||
ejson::Value::~Value(void)
|
ejson::Value::~Value(void) {
|
||||||
{
|
clear();
|
||||||
Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj)
|
etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj) {
|
||||||
{
|
|
||||||
_os << "(l=";
|
_os << "(l=";
|
||||||
_os << _obj.GetLine();
|
_os << _obj.getLine();
|
||||||
_os << ",c=";
|
_os << ",c=";
|
||||||
_os << _obj.GetCol();
|
_os << _obj.getCol();
|
||||||
_os << ")";
|
_os << ")";
|
||||||
return _os;
|
return _os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ejson::Value::AddIndent(etk::UString& _data, int32_t _indent) const
|
void ejson::Value::addIndent(etk::UString& _data, int32_t _indent) const {
|
||||||
{
|
|
||||||
for (int32_t iii=0; iii<_indent; iii++) {
|
for (int32_t iii=0; iii<_indent; iii++) {
|
||||||
_data+="\t";
|
_data+="\t";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ejson::Value::DrawElementParsed(const etk::UniChar& _val, const ejson::filePos& _filePos) const
|
void ejson::Value::drawElementParsed(const etk::UniChar& _val, const ejson::filePos& _filePos) const {
|
||||||
{
|
if (_val == '\n') {
|
||||||
if (_val=='\n') {
|
JSON_DEBUG(_filePos << " parse '\\n'");
|
||||||
JSON_DEBUG(_filePos << " Parse '\\n'");
|
} else if (_val == '\t') {
|
||||||
} else if (_val=='\t') {
|
JSON_DEBUG(_filePos << " parse '\\t'");
|
||||||
JSON_DEBUG(_filePos << " Parse '\\t'");
|
|
||||||
} else {
|
} else {
|
||||||
JSON_DEBUG(_filePos << " Parse '" << _val << "'");
|
JSON_DEBUG(_filePos << " parse '" << _val << "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ejson::Value::CountWhiteChar(const etk::UString& _data, int32_t _pos, ejson::filePos& _filePos) const
|
int32_t ejson::Value::countWhiteChar(const etk::UString& _data, int32_t _pos, ejson::filePos& _filePos) const {
|
||||||
{
|
_filePos.clear();
|
||||||
_filePos.Clear();
|
|
||||||
int32_t white=0;
|
int32_t white=0;
|
||||||
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
|
for (int32_t iii=_pos; iii<_data.size(); iii++) {
|
||||||
_filePos.Check(_data[iii]);
|
_filePos.check(_data[iii]);
|
||||||
if(true == _data[iii].IsWhiteChar()) {
|
if(true == _data[iii].isWhiteChar()) {
|
||||||
white++;
|
white++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -65,8 +60,7 @@ int32_t ejson::Value::CountWhiteChar(const etk::UString& _data, int32_t _pos, ej
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ejson::Value::CheckString(const etk::UniChar& _val) const
|
bool ejson::Value::checkString(const etk::UniChar& _val) const {
|
||||||
{
|
|
||||||
if( _val == '!'
|
if( _val == '!'
|
||||||
|| _val == '"'
|
|| _val == '"'
|
||||||
|| _val == '#'
|
|| _val == '#'
|
||||||
@ -105,12 +99,11 @@ bool ejson::Value::CheckString(const etk::UniChar& _val) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Value::CheckNumber(const etk::UniChar& _val) const
|
bool ejson::Value::checkNumber(const etk::UniChar& _val) const {
|
||||||
{
|
if( _val == '-'
|
||||||
if( _val=='-'
|
|| _val == '+'
|
||||||
|| _val=='+'
|
|| _val == 'e'
|
||||||
|| _val=='e'
|
|| _val == '.'
|
||||||
|| _val=='.'
|
|
||||||
|| ( _val>='0'
|
|| ( _val>='0'
|
||||||
&& _val<='9' ) ) {
|
&& _val<='9' ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
122
ejson/Value.h
122
ejson/Value.h
@ -57,9 +57,8 @@ namespace ejson
|
|||||||
~filePos(void) { };
|
~filePos(void) { };
|
||||||
filePos& operator ++(void) { m_col++; return *this; };
|
filePos& operator ++(void) { m_col++; return *this; };
|
||||||
filePos& operator --(void) { m_col--; if(m_col<0) { m_col=0;} return *this; };
|
filePos& operator --(void) { m_col--; if(m_col<0) { m_col=0;} return *this; };
|
||||||
const filePos& operator +=(const filePos& _obj)
|
const filePos& operator +=(const filePos& _obj) {
|
||||||
{
|
if (_obj.m_line == 0) {
|
||||||
if (_obj.m_line==0) {
|
|
||||||
m_col += _obj.m_col;
|
m_col += _obj.m_col;
|
||||||
} else {
|
} else {
|
||||||
m_col = _obj.m_col;
|
m_col = _obj.m_col;
|
||||||
@ -67,39 +66,34 @@ namespace ejson
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
};
|
};
|
||||||
const filePos& operator +=(int32_t _col)
|
const filePos& operator +=(int32_t _col) {
|
||||||
{
|
|
||||||
m_col += _col;
|
m_col += _col;
|
||||||
return *this;
|
return *this;
|
||||||
};
|
};
|
||||||
const filePos& operator= (const filePos& _obj )
|
const filePos& operator= (const filePos& _obj ) {
|
||||||
{
|
|
||||||
m_col = _obj.m_col;
|
m_col = _obj.m_col;
|
||||||
m_line = _obj.m_line;
|
m_line = _obj.m_line;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void NewLine(void) { m_col=0; m_line++; };
|
void newLine(void) { m_col=0; m_line++; };
|
||||||
bool Check(const etk::UniChar& _val)
|
bool check(const etk::UniChar& _val) {
|
||||||
{
|
|
||||||
m_col++;
|
m_col++;
|
||||||
if (_val=='\n') {
|
if (_val == '\n') {
|
||||||
NewLine();
|
newLine();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
void Set(int32_t _line, int32_t _col)
|
void set(int32_t _line, int32_t _col) {
|
||||||
{
|
|
||||||
m_col = _col;
|
m_col = _col;
|
||||||
m_line = _line;
|
m_line = _line;
|
||||||
}
|
}
|
||||||
void Clear(void)
|
void clear(void) {
|
||||||
{
|
|
||||||
m_col = 0;
|
m_col = 0;
|
||||||
m_line = 0;
|
m_line = 0;
|
||||||
}
|
}
|
||||||
int32_t GetCol(void) const { return m_col; };
|
int32_t getCol(void) const { return m_col; };
|
||||||
int32_t GetLine(void) const { return m_line; };
|
int32_t getLine(void) const { return m_line; };
|
||||||
};
|
};
|
||||||
etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj);
|
etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj);
|
||||||
|
|
||||||
@ -116,50 +110,50 @@ namespace ejson
|
|||||||
virtual ~Value(void);
|
virtual ~Value(void);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Parse the Current node [pure VIRUAL]
|
* @brief parse the Current node [pure VIRUAL]
|
||||||
* @param[in] _data data string to parse.
|
* @param[in] _data data string to parse.
|
||||||
* @param[in,out] _pos position in the string to start parse, return the position end of parsing.
|
* @param[in,out] _pos position in the string to start parse, return the position end of parsing.
|
||||||
* @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case)
|
* @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case)
|
||||||
* @param[in,out] file parsing position (line x col x)
|
* @param[in,out] file parsing position (line x col x)
|
||||||
* @return false if an error occured.
|
* @return false if an error occured.
|
||||||
*/
|
*/
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) = 0;
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) = 0;
|
||||||
/**
|
/**
|
||||||
* @brief Generate a string with the tree of the xml
|
* @brief generate a string with the tree of the xml
|
||||||
* @param[in,out] _data string where to add the elements
|
* @param[in,out] _data string where to add the elements
|
||||||
* @param[in] current indentation of the file
|
* @param[in] current indentation of the file
|
||||||
* @return false if an error occured.
|
* @return false if an error occured.
|
||||||
*/
|
*/
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const = 0;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const = 0;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Get the node type.
|
* @brief get the node type.
|
||||||
* @return the type of the Node.
|
* @return the type of the Node.
|
||||||
*/
|
*/
|
||||||
virtual nodeType_te GetType(void) const { return typeValue; };
|
virtual nodeType_te getType(void) const { return typeValue; };
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief Add indentation of the string input.
|
* @brief add indentation of the string input.
|
||||||
* @param[in,out] _data String where the indentation is done.
|
* @param[in,out] _data String where the indentation is done.
|
||||||
* @param[in] _indent Number of tab to add at the string.
|
* @param[in] _indent Number of tab to add at the string.
|
||||||
*/
|
*/
|
||||||
void AddIndent(etk::UString& _data, int32_t _indent) const;
|
void addIndent(etk::UString& _data, int32_t _indent) const;
|
||||||
/**
|
/**
|
||||||
* @brief Display the cuurent element that is curently parse.
|
* @brief Display the cuurent element that is curently parse.
|
||||||
* @param[in] _val Char that is parsed.
|
* @param[in] _val Char that is parsed.
|
||||||
* @param[in] _filePos Position of the char in the file.
|
* @param[in] _filePos Position of the char in the file.
|
||||||
*/
|
*/
|
||||||
void DrawElementParsed(const etk::UniChar& _val, const ejson::filePos& _filePos) const;
|
void drawElementParsed(const etk::UniChar& _val, const ejson::filePos& _filePos) const;
|
||||||
/**
|
/**
|
||||||
* @brief check if an name (for object named) (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r).
|
* @brief check if an name (for object named) (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r).
|
||||||
* @param[in] _val Value to check the conformity.
|
* @param[in] _val Value to check the conformity.
|
||||||
*/
|
*/
|
||||||
bool CheckString(const etk::UniChar& _val) const;
|
bool checkString(const etk::UniChar& _val) const;
|
||||||
/**
|
/**
|
||||||
* @brief check if an number -+.0123456789e).
|
* @brief check if an number -+.0123456789e).
|
||||||
* @param[in] _val Value to check the conformity.
|
* @param[in] _val Value to check the conformity.
|
||||||
*/
|
*/
|
||||||
bool CheckNumber(const etk::UniChar& _val) const;
|
bool checkNumber(const etk::UniChar& _val) const;
|
||||||
/**
|
/**
|
||||||
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
|
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
|
||||||
* @param[in] _data Data to parse.
|
* @param[in] _data Data to parse.
|
||||||
@ -167,109 +161,109 @@ namespace ejson
|
|||||||
* @param[out] _filePos new poistion of te file to add.
|
* @param[out] _filePos new poistion of te file to add.
|
||||||
* @return number of white element.
|
* @return number of white element.
|
||||||
*/
|
*/
|
||||||
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos, ejson::filePos& _filePos) const;
|
int32_t countWhiteChar(const etk::UString& _data, int32_t _pos, ejson::filePos& _filePos) const;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Value if it is possible.
|
* @brief Cast the element in a Value if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Value* ToValue(void) { return this; };
|
virtual ejson::Value* toValue(void) { return this; };
|
||||||
virtual const ejson::Value* ToValue(void) const { return this; };
|
virtual const ejson::Value* toValue(void) const { return this; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Document if it is possible.
|
* @brief Cast the element in a Document if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Document* ToDocument(void) { return NULL; };
|
virtual ejson::Document* toDocument(void) { return NULL; };
|
||||||
virtual const ejson::Document* ToDocument(void) const { return NULL; };
|
virtual const ejson::Document* toDocument(void) const { return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Array if it is possible.
|
* @brief Cast the element in a Array if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Array* ToArray(void) { return NULL; };
|
virtual ejson::Array* toArray(void) { return NULL; };
|
||||||
virtual const ejson::Array* ToArray(void) const{ return NULL; };
|
virtual const ejson::Array* toArray(void) const{ return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Object if it is possible.
|
* @brief Cast the element in a Object if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Object* ToObject(void) { return NULL; };
|
virtual ejson::Object* toObject(void) { return NULL; };
|
||||||
virtual const ejson::Object* ToObject(void) const{ return NULL; };
|
virtual const ejson::Object* toObject(void) const{ return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a String if it is possible.
|
* @brief Cast the element in a String if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::String* ToString(void) { return NULL; };
|
virtual ejson::String* toString(void) { return NULL; };
|
||||||
virtual const ejson::String* ToString(void) const{ return NULL; };
|
virtual const ejson::String* toString(void) const{ return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Number if it is possible.
|
* @brief Cast the element in a Number if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Number* ToNumber(void) { return NULL; };
|
virtual ejson::Number* toNumber(void) { return NULL; };
|
||||||
virtual const ejson::Number* ToNumber(void) const{ return NULL; };
|
virtual const ejson::Number* toNumber(void) const{ return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Boolean if it is possible.
|
* @brief Cast the element in a Boolean if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Boolean* ToBoolean(void) { return NULL; };
|
virtual ejson::Boolean* toBoolean(void) { return NULL; };
|
||||||
virtual const ejson::Boolean* ToBoolean(void) const{ return NULL; };
|
virtual const ejson::Boolean* toBoolean(void) const{ return NULL; };
|
||||||
/**
|
/**
|
||||||
* @brief Cast the element in a Null if it is possible.
|
* @brief Cast the element in a Null if it is possible.
|
||||||
* @return pointer on the class or NULL.
|
* @return pointer on the class or NULL.
|
||||||
*/
|
*/
|
||||||
virtual ejson::Null* ToNull(void) { return NULL; };
|
virtual ejson::Null* toNull(void) { return NULL; };
|
||||||
virtual const ejson::Null* ToNull(void) const{ return NULL; };
|
virtual const ejson::Null* toNull(void) const{ return NULL; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Document
|
* @brief check if the node is a ejson::Document
|
||||||
* @return true if the node is a ejson::Document
|
* @return true if the node is a ejson::Document
|
||||||
*/
|
*/
|
||||||
bool IsDocument(void) const { return GetType()==ejson::typeDocument; };
|
bool isDocument(void) const { return getType() == ejson::typeDocument; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Array
|
* @brief check if the node is a ejson::Array
|
||||||
* @return true if the node is a ejson::Array
|
* @return true if the node is a ejson::Array
|
||||||
*/
|
*/
|
||||||
bool IsArray(void) const { return GetType()==ejson::typeArray; };
|
bool isArray(void) const { return getType() == ejson::typeArray; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Object
|
* @brief check if the node is a ejson::Object
|
||||||
* @return true if the node is a ejson::Object
|
* @return true if the node is a ejson::Object
|
||||||
*/
|
*/
|
||||||
bool IsObject(void) const { return GetType()==ejson::typeObject; };
|
bool isObject(void) const { return getType() == ejson::typeObject; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::String
|
* @brief check if the node is a ejson::String
|
||||||
* @return true if the node is a ejson::String
|
* @return true if the node is a ejson::String
|
||||||
*/
|
*/
|
||||||
bool IsString(void) const { return GetType()==ejson::typeString; };
|
bool isString(void) const { return getType() == ejson::typeString; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Number
|
* @brief check if the node is a ejson::Number
|
||||||
* @return true if the node is a ejson::Number
|
* @return true if the node is a ejson::Number
|
||||||
*/
|
*/
|
||||||
bool IsNumber(void) const { return GetType()==ejson::typeNumber; };
|
bool isNumber(void) const { return getType() == ejson::typeNumber; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Boolean
|
* @brief check if the node is a ejson::Boolean
|
||||||
* @return true if the node is a ejson::Boolean
|
* @return true if the node is a ejson::Boolean
|
||||||
*/
|
*/
|
||||||
bool IsBoolean(void) const { return GetType()==ejson::typeBoolean; };
|
bool isBoolean(void) const { return getType() == ejson::typeBoolean; };
|
||||||
/**
|
/**
|
||||||
* @brief Check if the node is a ejson::Null
|
* @brief check if the node is a ejson::Null
|
||||||
* @return true if the node is a ejson::Null
|
* @return true if the node is a ejson::Null
|
||||||
*/
|
*/
|
||||||
bool IsNull(void) const { return GetType()==ejson::typeNull; };
|
bool isNull(void) const { return getType() == ejson::typeNull; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clear the Node
|
* @brief clear the Node
|
||||||
*/
|
*/
|
||||||
virtual void Clear(void) {};
|
virtual void clear(void) {};
|
||||||
/**
|
/**
|
||||||
* @brief Tranfert all element in the element set in parameter
|
* @brief Tranfert all element in the element set in parameter
|
||||||
* @param[in,out] _obj move all parameter in the selected element
|
* @param[in,out] _obj move all parameter in the selected element
|
||||||
* @return true if transfer is done corectly
|
* @return true if transfer is done corectly
|
||||||
* @note all element is remove from the curent element.
|
* @note all element is remove from the curent element.
|
||||||
*/
|
*/
|
||||||
virtual bool TransfertIn(ejson::Value* _obj) { return false; };
|
virtual bool transfertIn(ejson::Value* _obj) { return false; };
|
||||||
/**
|
/**
|
||||||
* @brief Copy the curent node and all the child in the curent one.
|
* @brief Copy the curent node and all the child in the curent one.
|
||||||
* @return NULL in an error occured, the pointer on the element otherwise
|
* @return NULL in an error occured, the pointer on the element otherwise
|
||||||
*/
|
*/
|
||||||
virtual ejson::Value* Duplicate(void) const { return NULL; };
|
virtual ejson::Value* duplicate(void) const { return NULL; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
128
ejson/ejson.cpp
128
ejson/ejson.cpp
@ -21,57 +21,51 @@
|
|||||||
#define __class__ "Document"
|
#define __class__ "Document"
|
||||||
|
|
||||||
ejson::Document::Document(void) :
|
ejson::Document::Document(void) :
|
||||||
m_writeErrorWhenDetexted(true),
|
m_writeErrorWhenDetexted(true),
|
||||||
m_comment(""),
|
m_comment(""),
|
||||||
m_Line(""),
|
m_Line(""),
|
||||||
m_filePos(0,0)
|
m_filePos(0,0) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ejson::Document::~Document(void)
|
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 {
|
||||||
{
|
ejson::Object::iGenerate(_data, _indent+1);
|
||||||
ejson::Object::IGenerate(_data, _indent+1);
|
|
||||||
_data += "\n";
|
_data += "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Document::Parse(const etk::UString& _data)
|
bool ejson::Document::parse(const etk::UString& _data) {
|
||||||
{
|
JSON_VERBOSE("Start parsing document (type: string) size=" << _data.size());
|
||||||
JSON_VERBOSE("Start parsing document (type: string) size=" << _data.Size());
|
clear();
|
||||||
Clear();
|
|
||||||
ejson::filePos filePos(1,0);
|
ejson::filePos filePos(1,0);
|
||||||
int32_t parsePos = 0;
|
int32_t parsePos = 0;
|
||||||
return IParse(_data, parsePos, filePos, *this);
|
return iParse(_data, parsePos, filePos, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Document::Generate(etk::UString& _data)
|
bool ejson::Document::generate(etk::UString& _data) {
|
||||||
{
|
|
||||||
_data = "";
|
_data = "";
|
||||||
return IGenerate(_data,0);
|
return iGenerate(_data,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Document::Load(const etk::UString& _file)
|
bool ejson::Document::load(const etk::UString& _file) {
|
||||||
{
|
|
||||||
// Start loading the XML :
|
// Start loading the XML :
|
||||||
JSON_VERBOSE("open file (xml) \"" << _file << "\"");
|
JSON_VERBOSE("open file (xml) \"" << _file << "\"");
|
||||||
Clear();
|
clear();
|
||||||
etk::FSNode tmpFile(_file);
|
etk::FSNode tmpFile(_file);
|
||||||
if (false == tmpFile.Exist()) {
|
if (false == tmpFile.exist()) {
|
||||||
JSON_ERROR("File Does not exist : " << _file);
|
JSON_ERROR("File Does not exist : " << _file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int64_t fileSize = tmpFile.FileSize();
|
int64_t fileSize = tmpFile.fileSize();
|
||||||
if (0==fileSize) {
|
if (0 == fileSize) {
|
||||||
JSON_ERROR("This file is empty : " << _file);
|
JSON_ERROR("This file is empty : " << _file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (false == tmpFile.FileOpenRead()) {
|
if (false == tmpFile.fileOpenRead()) {
|
||||||
JSON_ERROR("Can not open (r) the file : " << _file);
|
JSON_ERROR("Can not open (r) the file : " << _file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -84,54 +78,51 @@ bool ejson::Document::Load(const etk::UString& _file)
|
|||||||
// TODO : change this ... get the charset from the Declaration element ...
|
// TODO : change this ... get the charset from the Declaration element ...
|
||||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||||
// load data from the file :
|
// load data from the file :
|
||||||
tmpFile.FileRead(fileBuffer, 1, fileSize);
|
tmpFile.fileRead(fileBuffer, 1, fileSize);
|
||||||
// close the file:
|
// close the file:
|
||||||
tmpFile.FileClose();
|
tmpFile.fileClose();
|
||||||
|
|
||||||
// convert in UTF8 :
|
// convert in UTF8 :
|
||||||
etk::UString tmpDataUnicode(fileBuffer, unicode::EDN_CHARSET_UTF8);
|
etk::UString tmpDataUnicode(fileBuffer, unicode::EDN_CHARSET_UTF8);
|
||||||
// remove temporary buffer:
|
// remove temporary buffer:
|
||||||
delete(fileBuffer);
|
delete(fileBuffer);
|
||||||
// parse the data :
|
// parse the data :
|
||||||
bool ret = Parse(tmpDataUnicode);
|
bool ret = parse(tmpDataUnicode);
|
||||||
//Display();
|
//Display();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Document::Store(const etk::UString& _file)
|
bool ejson::Document::store(const etk::UString& _file) {
|
||||||
{
|
|
||||||
etk::UString createData;
|
etk::UString createData;
|
||||||
if (false == Generate(createData)) {
|
if (false == generate(createData)) {
|
||||||
JSON_ERROR("Error while creating the XML : " << _file);
|
JSON_ERROR("Error while creating the XML : " << _file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
etk::FSNode tmpFile(_file);
|
etk::FSNode tmpFile(_file);
|
||||||
if (false == tmpFile.FileOpenWrite()) {
|
if (false == tmpFile.fileOpenWrite()) {
|
||||||
JSON_ERROR("Can not open (w) the file : " << _file);
|
JSON_ERROR("Can not open (w) the file : " << _file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
etk::Char endTable = createData.c_str();
|
etk::Char endTable = createData.c_str();
|
||||||
if (tmpFile.FileWrite(endTable, sizeof(char), endTable.Size()) != endTable.Size()) {
|
if (tmpFile.fileWrite(endTable, sizeof(char), endTable.size()) != endTable.size()) {
|
||||||
JSON_ERROR("Error while writing output XML file : " << _file);
|
JSON_ERROR("Error while writing output XML file : " << _file);
|
||||||
tmpFile.FileClose();
|
tmpFile.fileClose();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tmpFile.FileClose();
|
tmpFile.fileClose();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ejson::Document::Display(void)
|
void ejson::Document::display(void) {
|
||||||
{
|
|
||||||
etk::UString tmpp;
|
etk::UString tmpp;
|
||||||
IGenerate(tmpp, 0);
|
iGenerate(tmpp, 0);
|
||||||
JSON_INFO("Generated JSON : \n" << tmpp);
|
JSON_INFO("Generated JSON : \n" << tmpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos)
|
static etk::UString createPosPointer(const etk::UString& _line, int32_t _pos) {
|
||||||
{
|
|
||||||
etk::UString out;
|
etk::UString out;
|
||||||
int32_t iii;
|
int32_t iii;
|
||||||
for (iii=0; iii<_pos && iii<_line.Size(); iii++) {
|
for (iii=0; iii<_pos && iii<_line.size(); iii++) {
|
||||||
if (_line[iii] == '\t') {
|
if (_line[iii] == '\t') {
|
||||||
out += "\t";
|
out += "\t";
|
||||||
} else {
|
} else {
|
||||||
@ -145,60 +136,57 @@ static etk::UString CreatePosPointer(const etk::UString& _line, int32_t _pos)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ejson::Document::DisplayError(void)
|
void ejson::Document::displayError(void) {
|
||||||
{
|
if (m_comment.size() == 0) {
|
||||||
if (m_comment.Size()==0) {
|
|
||||||
JSON_ERROR("No error detected ???");
|
JSON_ERROR("No error detected ???");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSON_ERROR(m_filePos << " " << m_comment << "\n"
|
JSON_ERROR(m_filePos << " " << m_comment << "\n"
|
||||||
<< m_Line << "\n"
|
<< m_Line << "\n"
|
||||||
<< CreatePosPointer(m_Line, m_filePos.GetCol()) );
|
<< createPosPointer(m_Line, m_filePos.getCol()) );
|
||||||
#ifdef ENABLE_CRITICAL_WHEN_ERROR
|
#ifdef ENABLE_CRITICAL_WHEN_ERROR
|
||||||
JSON_CRITICAL("detect error");
|
JSON_CRITICAL("detect error");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ejson::Document::CreateError(const etk::UString& _data, int32_t _pos, const ejson::filePos& _filePos, const etk::UString& _comment)
|
void ejson::Document::createError(const etk::UString& _data, int32_t _pos, const ejson::filePos& _filePos, const etk::UString& _comment) {
|
||||||
{
|
|
||||||
m_comment = _comment;
|
m_comment = _comment;
|
||||||
m_Line = _data.ExtractLine(_pos);
|
m_Line = _data.extractLine(_pos);
|
||||||
m_filePos = _filePos;
|
m_filePos = _filePos;
|
||||||
if (true==m_writeErrorWhenDetexted) {
|
if (true == m_writeErrorWhenDetexted) {
|
||||||
DisplayError();
|
displayError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ejson::Document::IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc)
|
bool ejson::Document::iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
|
||||||
{
|
|
||||||
JSON_PARSE_ELEMENT("start parse : 'Document' ");
|
JSON_PARSE_ELEMENT("start parse : 'Document' ");
|
||||||
bool haveMainNode=false;
|
bool haveMainNode=false;
|
||||||
bool nodeParsed=false;
|
bool nodeParsed=false;
|
||||||
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
|
for (int32_t iii=_pos; 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
|
||||||
ejson::filePos tmpPos;
|
ejson::filePos tmpPos;
|
||||||
if( _data[iii]==' '
|
if( _data[iii] == ' '
|
||||||
|| _data[iii]=='\t'
|
|| _data[iii] == '\t'
|
||||||
|| _data[iii]=='\n'
|
|| _data[iii] == '\n'
|
||||||
|| _data[iii]=='\r') {
|
|| _data[iii] == '\r') {
|
||||||
// white space ==> nothing to do ...
|
// white space == > nothing to do ...
|
||||||
} else if (_data[iii]=='{') {
|
} else if (_data[iii] == '{') {
|
||||||
if (nodeParsed==true) {
|
if (nodeParsed == true) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "element already parsed");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "element already parsed");
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
}
|
}
|
||||||
// find a main object:
|
// find a main object:
|
||||||
// ==> generic sub parsing
|
// == > generic sub parsing
|
||||||
iii++;
|
iii++;
|
||||||
haveMainNode=true;
|
haveMainNode=true;
|
||||||
nodeParsed=true;
|
nodeParsed=true;
|
||||||
ejson::Object::IParse(_data, iii, _filePos, _doc);
|
ejson::Object::iParse(_data, iii, _filePos, _doc);
|
||||||
} else if(_data[iii]=='}') {
|
} else if(_data[iii] == '}') {
|
||||||
_pos=iii; // ==> return the end element type ==> usefull to check end and check if adding element is needed
|
_pos=iii; // == > return the end element type ==> usefull to check end and check if adding element is needed
|
||||||
if (haveMainNode==true) {
|
if (haveMainNode == true) {
|
||||||
// find end of value:
|
// find end of value:
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -206,14 +194,14 @@ bool ejson::Document::IParse(const etk::UString& _data, int32_t& _pos, ejson::fi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (nodeParsed==true) {
|
if (nodeParsed == true) {
|
||||||
_pos=iii;
|
_pos=iii;
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "element already parsed");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "element already parsed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nodeParsed=true;
|
nodeParsed=true;
|
||||||
// this might not have the '{' start element !!!
|
// this might not have the '{' start element !!!
|
||||||
if (false==ejson::Object::IParse(_data, iii, _filePos, _doc)) {
|
if (false == ejson::Object::iParse(_data, iii, _filePos, _doc)) {
|
||||||
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Object sub parsing in error");
|
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, "Object sub parsing in error");
|
||||||
_pos = iii;
|
_pos = iii;
|
||||||
return false;
|
return false;
|
||||||
|
@ -32,61 +32,61 @@ namespace ejson
|
|||||||
virtual ~Document(void);
|
virtual ~Document(void);
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Parse a string that contain an XML
|
* @brief parse a string that contain an XML
|
||||||
* @param[in] _data Data to parse
|
* @param[in] _data Data to parse
|
||||||
* @return false : An error occured
|
* @return false : An error occured
|
||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
bool Parse(const etk::UString& _data);
|
bool parse(const etk::UString& _data);
|
||||||
/**
|
/**
|
||||||
* @brief Generate a string that contain the created XML
|
* @brief generate a string that contain the created XML
|
||||||
* @param[out] _data Data where the xml is stored
|
* @param[out] _data Data where the xml is stored
|
||||||
* @return false : An error occured
|
* @return false : An error occured
|
||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
bool Generate(etk::UString& _data);
|
bool generate(etk::UString& _data);
|
||||||
/**
|
/**
|
||||||
* @brief Load the file that might contain the xml
|
* @brief Load the file that might contain the xml
|
||||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||||
* @return false : An error occured
|
* @return false : An error occured
|
||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
bool Load(const etk::UString& _file);
|
bool load(const etk::UString& _file);
|
||||||
/**
|
/**
|
||||||
* @brief Store the Xml in the file
|
* @brief Store the Xml in the file
|
||||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||||
* @return false : An error occured
|
* @return false : An error occured
|
||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
bool Store(const etk::UString& _file);
|
bool store(const etk::UString& _file);
|
||||||
/**
|
/**
|
||||||
* @brief Display the Document on console
|
* @brief Display the Document on console
|
||||||
*/
|
*/
|
||||||
void Display(void);
|
void display(void);
|
||||||
private:
|
private:
|
||||||
bool m_writeErrorWhenDetexted;
|
bool m_writeErrorWhenDetexted;
|
||||||
etk::UString m_comment;
|
etk::UString m_comment;
|
||||||
etk::UString m_Line;
|
etk::UString m_Line;
|
||||||
ejson::filePos m_filePos;
|
ejson::filePos m_filePos;
|
||||||
public:
|
public:
|
||||||
void DisplayErrorWhenDetected(void) { m_writeErrorWhenDetexted=true; };
|
void displayErrorWhenDetected(void) { m_writeErrorWhenDetexted=true; };
|
||||||
void NotDisplayErrorWhenDetected(void) { m_writeErrorWhenDetexted=false; };
|
void notDisplayErrorWhenDetected(void) { m_writeErrorWhenDetexted=false; };
|
||||||
|
|
||||||
void CreateError(const etk::UString& _data, int32_t _pos, const ejson::filePos& _filePos, const etk::UString& _comment);
|
void createError(const etk::UString& _data, int32_t _pos, const ejson::filePos& _filePos, const etk::UString& _comment);
|
||||||
void DisplayError(void);
|
void displayError(void);
|
||||||
public: // herited function:
|
public: // herited function:
|
||||||
virtual nodeType_te GetType(void) const { return typeDocument; };
|
virtual nodeType_te getType(void) const { return typeDocument; };
|
||||||
virtual bool IParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
virtual bool iParse(const etk::UString& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||||
virtual bool IGenerate(etk::UString& _data, int32_t _indent) const;
|
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
|
||||||
virtual ejson::Document* ToDocument(void) { return this; };
|
virtual ejson::Document* toDocument(void) { return this; };
|
||||||
virtual const ejson::Document* ToDocument(void) const { return this; };
|
virtual const ejson::Document* toDocument(void) const { return this; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EJSON_CREATE_ERROR(doc,data,pos,filePos,comment) \
|
#define EJSON_CREATE_ERROR(doc,data,pos,filePos,comment) \
|
||||||
do { \
|
do { \
|
||||||
JSON_ERROR(comment); \
|
JSON_ERROR(comment); \
|
||||||
(doc).CreateError((data),(pos),(filePos),(comment)); \
|
(doc).createError((data),(pos),(filePos),(comment)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
//__LINE__, __class__, __func__
|
//__LINE__, __class__, __func__
|
||||||
|
204
ejson/test.cpp
204
ejson/test.cpp
@ -15,15 +15,13 @@
|
|||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "ejson::test"
|
#define __class__ "ejson::test"
|
||||||
|
|
||||||
class testCheck
|
class testCheck {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
etk::UString m_ref;
|
etk::UString m_ref;
|
||||||
etk::UString m_input;
|
etk::UString m_input;
|
||||||
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
||||||
testCheck(void) {};
|
testCheck(void) {};
|
||||||
void Set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input)
|
void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input) {
|
||||||
{
|
|
||||||
m_ref = _ref;
|
m_ref = _ref;
|
||||||
m_input = _input;
|
m_input = _input;
|
||||||
m_errorPos = _pos;
|
m_errorPos = _pos;
|
||||||
@ -32,137 +30,136 @@ class testCheck
|
|||||||
|
|
||||||
etk::Vector<testCheck> l_list;
|
etk::Vector<testCheck> l_list;
|
||||||
|
|
||||||
void Init(void)
|
void Init(void) {
|
||||||
{
|
|
||||||
etk::UString reference;
|
etk::UString reference;
|
||||||
etk::UString input;
|
etk::UString input;
|
||||||
testCheck check;
|
testCheck check;
|
||||||
|
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
check.Set("test ejson::Doc", -2, "");
|
check.set("test ejson::Doc", -2, "");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
reference = "{\n}\n";
|
reference = "{\n}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{}\n");
|
"{}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ \t\r }\n");
|
"{ \t\r }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
check.Set("test ejson::null", -2, "");
|
check.set("test ejson::null", -2, "");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n\t\"tmpElement\": null\n}\n";
|
reference = "{\n\t\"tmpElement\": null\n}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ tmpElement:null }\n");
|
"{ tmpElement:null }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ \t\ntmpElement:null \t\n }\n");
|
"{ \t\ntmpElement:null \t\n }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"tmpElement:null\n");
|
"tmpElement:null\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
check.Set("test ejson::boolean", -2, "");
|
check.set("test ejson::boolean", -2, "");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n\t\"tmpElement\": true\n}\n";
|
reference = "{\n\t\"tmpElement\": true\n}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ tmpElement:true }\n");
|
"{ tmpElement:true }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ \t\ntmpElement:true \t\n }\n");
|
"{ \t\ntmpElement:true \t\n }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"tmpElement:true\n");
|
"tmpElement:true\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n\t\"tmpElement\": false\n}\n";
|
reference = "{\n\t\"tmpElement\": false\n}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ tmpElement:false }\n");
|
"{ tmpElement:false }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ \t\ntmpElement:false \t\n }\n");
|
"{ \t\ntmpElement:false \t\n }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"tmpElement:false\n");
|
"tmpElement:false\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
check.Set("test ejson::number", -2, "");
|
check.set("test ejson::number", -2, "");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n\t\"tmpElement\": 956256\n}\n";
|
reference = "{\n\t\"tmpElement\": 956256\n}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ tmpElement:956256 }\n");
|
"{ tmpElement:956256 }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{ \t\ntmpElement:956256 \t\n }\n");
|
"{ \t\ntmpElement:956256 \t\n }\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"tmpElement:956256\n");
|
"tmpElement:956256\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": 956256\n}\n",
|
check.set("{\n\t\"tmpElement\": 956256\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:956256}\n");
|
"{tmpElement:956256}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": -956256\n}\n",
|
check.set("{\n\t\"tmpElement\": -956256\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:-956256}\n");
|
"{tmpElement:-956256}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": -956256\n}\n",
|
check.set("{\n\t\"tmpElement\": -956256\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:-956256}\n");
|
"{tmpElement:-956256}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": -956.256\n}\n",
|
check.set("{\n\t\"tmpElement\": -956.256\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:-956.256}\n");
|
"{tmpElement:-956.256}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
/*
|
/*
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": -956956544454621184\n}\n",
|
check.set("{\n\t\"tmpElement\": -956956544454621184\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:-956956544454621354.256}\n");
|
"{tmpElement:-956956544454621354.256}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set("{\n\t\"tmpElement\": 0.000002\n}\n",
|
check.set("{\n\t\"tmpElement\": 0.000002\n}\n",
|
||||||
-1,
|
-1,
|
||||||
"{tmpElement:+.000001565464}\n");
|
"{tmpElement:+.000001565464}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
check.Set("test ejson::all", -2, "");
|
check.set("test ejson::all", -2, "");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ======================================================
|
// == ====================================================
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"menu\": {\n"
|
" \"menu\": {\n"
|
||||||
" \"id\": \"file\",\n"
|
" \"id\": \"file\",\n"
|
||||||
@ -172,10 +169,10 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"menu\": {\n"
|
" \"menu\": {\n"
|
||||||
@ -191,12 +188,12 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"{\n"
|
"{\n"
|
||||||
" menu: {\n"
|
" menu: {\n"
|
||||||
@ -224,9 +221,9 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
"menu: {\n"
|
"menu: {\n"
|
||||||
" id: \"file\",\n"
|
" id: \"file\",\n"
|
||||||
@ -252,7 +249,7 @@ void Init(void)
|
|||||||
" ]\n"
|
" ]\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
@ -277,10 +274,10 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"menu\": {\n"
|
" \"menu\": {\n"
|
||||||
@ -295,10 +292,10 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"widget\": {\n"
|
" \"widget\": {\n"
|
||||||
@ -328,10 +325,10 @@ void Init(void)
|
|||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"web-app\": {\n"
|
" \"web-app\": {\n"
|
||||||
@ -424,10 +421,10 @@ void Init(void)
|
|||||||
" \"taglib\": { \"taglib-uri\": \"cofax.tld\", \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\" }\n"
|
" \"taglib\": { \"taglib-uri\": \"cofax.tld\", \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
reference = "{\n"
|
reference = "{\n"
|
||||||
" \"menu\": {\n"
|
" \"menu\": {\n"
|
||||||
@ -458,23 +455,22 @@ void Init(void)
|
|||||||
" ]\n"
|
" ]\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
check.Set(reference,
|
check.set(reference,
|
||||||
-1,
|
-1,
|
||||||
reference);
|
reference);
|
||||||
l_list.PushBack(check);
|
l_list.pushBack(check);
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[]) {
|
||||||
{
|
|
||||||
GeneralDebugSetLevel(etk::LOG_LEVEL_VERBOSE);
|
GeneralDebugSetLevel(etk::LOG_LEVEL_VERBOSE);
|
||||||
Init();
|
Init();
|
||||||
int32_t countError = 0;
|
int32_t countError = 0;
|
||||||
int32_t countSeparator = 0;
|
int32_t countSeparator = 0;
|
||||||
int32_t sectionID = 0;
|
int32_t sectionID = 0;
|
||||||
for (int32_t iii=0 ; iii<l_list.Size() ; iii++) {
|
for (int32_t iii=0 ; iii<l_list.size() ; iii++) {
|
||||||
int32_t jjj= iii-countSeparator+1;
|
int32_t jjj= iii-countSeparator+1;
|
||||||
if (l_list[iii].m_errorPos==-2) {
|
if (l_list[iii].m_errorPos == -2) {
|
||||||
countSeparator++;
|
countSeparator++;
|
||||||
sectionID = 0;
|
sectionID = 0;
|
||||||
JSON_INFO("-------------------------------------------------------------");
|
JSON_INFO("-------------------------------------------------------------");
|
||||||
@ -486,8 +482,8 @@ int main(int argc, const char *argv[])
|
|||||||
ejson::Document doc;
|
ejson::Document doc;
|
||||||
etk::UString out("");
|
etk::UString out("");
|
||||||
//JSON_DEBUG("parse : \n" << l_list[iii].m_input);
|
//JSON_DEBUG("parse : \n" << l_list[iii].m_input);
|
||||||
if (false==doc.Parse(l_list[iii].m_input)) {
|
if (false == doc.parse(l_list[iii].m_input)) {
|
||||||
if (l_list[iii].m_errorPos==1) {
|
if (l_list[iii].m_errorPos == 1) {
|
||||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Parsing in error (correct result)");
|
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Parsing in error (correct result)");
|
||||||
} else {
|
} else {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be OK");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be OK");
|
||||||
@ -496,30 +492,30 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (l_list[iii].m_errorPos==1) {
|
if (l_list[iii].m_errorPos == 1) {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be in error ...");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be in error ...");
|
||||||
JSON_ERROR("parse : \n" << l_list[iii].m_input);
|
JSON_ERROR("parse : \n" << l_list[iii].m_input);
|
||||||
doc.Display();
|
doc.Display();
|
||||||
countError++;
|
countError++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (false == doc.Generate(out)) {
|
if (false == doc.generate(out)) {
|
||||||
if (l_list[iii].m_errorPos==2) {
|
if (l_list[iii].m_errorPos == 2) {
|
||||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } generate in error (correct result)");
|
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } generate in error (correct result)");
|
||||||
} else {
|
} else {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Generate output might be OK");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } generate output might be OK");
|
||||||
JSON_ERROR("generate : \n" << out);
|
JSON_ERROR("generate : \n" << out);
|
||||||
countError++;
|
countError++;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (l_list[iii].m_errorPos==2) {
|
if (l_list[iii].m_errorPos == 2) {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Generating might be in error ...");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Generating might be in error ...");
|
||||||
countError++;
|
countError++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (l_list[iii].m_ref != out) {
|
if (l_list[iii].m_ref != out) {
|
||||||
if (l_list[iii].m_errorPos==3) {
|
if (l_list[iii].m_errorPos == 3) {
|
||||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Result in error (normal case)");
|
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Result in error (normal case)");
|
||||||
} else {
|
} else {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output");
|
||||||
@ -527,12 +523,12 @@ int main(int argc, const char *argv[])
|
|||||||
etk::Vector<etk::UString> tmpref = l_list[iii].m_ref.Split('\n');
|
etk::Vector<etk::UString> tmpref = l_list[iii].m_ref.Split('\n');
|
||||||
//JSON_ERROR("generate : \n" << out);
|
//JSON_ERROR("generate : \n" << out);
|
||||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||||
for (int32_t jjj=0; jjj<tmpout.Size() || jjj<tmpref.Size(); ++jjj) {
|
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.Size(); ++jjj) {
|
||||||
if (jjj<tmpref.Size()) {
|
if (jjj<tmpref.size()) {
|
||||||
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
||||||
}
|
}
|
||||||
if (jjj<tmpout.Size()) {
|
if (jjj<tmpout.size()) {
|
||||||
if (jjj>=tmpref.Size() || tmpref[jjj] != tmpout[jjj]) {
|
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
|
||||||
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,18 +537,18 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (l_list[iii].m_errorPos==3) {
|
if (l_list[iii].m_errorPos == 3) {
|
||||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR} checking result might be in error...");
|
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR} checking result might be in error...");
|
||||||
etk::Vector<etk::UString> tmpout = out.Split('\n');
|
etk::Vector<etk::UString> tmpout = out.Split('\n');
|
||||||
etk::Vector<etk::UString> tmpref = l_list[iii].m_ref.Split('\n');
|
etk::Vector<etk::UString> tmpref = l_list[iii].m_ref.Split('\n');
|
||||||
//JSON_ERROR("generate : \n" << out);
|
//JSON_ERROR("generate : \n" << out);
|
||||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||||
for (int32_t jjj=0; jjj<tmpout.Size() || jjj<tmpref.Size(); ++jjj) {
|
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.Size(); ++jjj) {
|
||||||
if (jjj<tmpref.Size()) {
|
if (jjj<tmpref.size()) {
|
||||||
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
JSON_INFO("[" << jjj << "] " << tmpref[jjj] );
|
||||||
}
|
}
|
||||||
if (jjj<tmpout.Size()) {
|
if (jjj<tmpout.size()) {
|
||||||
if (jjj>=tmpref.Size() || tmpref[jjj] != tmpout[jjj]) {
|
if (jjj>=tmpref.size() || tmpref[jjj] != tmpout[jjj]) {
|
||||||
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
JSON_ERROR("[" << jjj << "] " << tmpout[jjj] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -563,9 +559,9 @@ int main(int argc, const char *argv[])
|
|||||||
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK }");
|
JSON_INFO("[TEST] " << sectionID << ":" << jjj << " { OK }");
|
||||||
}
|
}
|
||||||
if (countError>0) {
|
if (countError>0) {
|
||||||
JSON_ERROR("[TEST] produce " << countError << " error on " << l_list.Size()-countSeparator << " test");
|
JSON_ERROR("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||||
} else {
|
} else {
|
||||||
JSON_INFO("[TEST] produce " << countError << " error on " << l_list.Size()-countSeparator << " test");
|
JSON_INFO("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user