[DEV] change idea std::u32string to std::string

This commit is contained in:
Edouard DUPIN 2013-11-12 21:58:13 +01:00
parent 43ddd2549c
commit d24b545ba9
17 changed files with 115 additions and 116 deletions

View File

@ -31,7 +31,7 @@ void ejson::Array::clear(void) {
m_value.clear(); m_value.clear();
} }
bool ejson::Array::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Array::iParse(const std::string& _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]);
@ -131,7 +131,7 @@ bool ejson::Array::iParse(const std::u32string& _data, int32_t& _pos, ejson::fil
} }
bool ejson::Array::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Array::iGenerate(std::string& _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;
@ -197,7 +197,7 @@ bool ejson::Array::add(ejson::Value* _element) {
return true; return true;
} }
bool ejson::Array::addString(const std::u32string& _value) { bool ejson::Array::addString(const std::string& _value) {
return add(new ejson::String(_value)); return add(new ejson::String(_value));
} }
@ -298,8 +298,8 @@ ejson::Boolean* ejson::Array::getBoolean(esize_t _id) {
return tmpElement->toBoolean(); return tmpElement->toBoolean();
} }
const std::u32string& ejson::Array::getStringValue(esize_t _id) { const std::string& ejson::Array::getStringValue(esize_t _id) {
static const std::u32string errorValue(""); static const std::string errorValue("");
ejson::String* tmpElement = getString(_id); ejson::String* tmpElement = getString(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
return errorValue; return errorValue;
@ -307,7 +307,7 @@ const std::u32string& ejson::Array::getStringValue(esize_t _id) {
return tmpElement->get(); return tmpElement->get();
} }
std::u32string ejson::Array::getStringValue(esize_t _id, const std::u32string& _errorValue) { std::string ejson::Array::getStringValue(esize_t _id, const std::string& _errorValue) {
ejson::String* tmpElement = getString(_id); ejson::String* tmpElement = getString(_id);
if (NULL == tmpElement) { if (NULL == tmpElement) {
return _errorValue; return _errorValue;

View File

@ -69,14 +69,14 @@ namespace ejson
* @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 std::u32string& getStringValue(esize_t _id); const std::string& 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.
*/ */
std::u32string getStringValue(esize_t _id, const std::u32string& _errorValue); std::string getStringValue(esize_t _id, const std::string& _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.
@ -126,7 +126,7 @@ namespace ejson
* @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 std::u32string& _value); bool addString(const std::string& _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
@ -146,8 +146,8 @@ namespace ejson
bool addNumber(double _value); bool addNumber(double _value);
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeArray; return typeArray;
}; };

View File

@ -13,7 +13,7 @@
#undef __class__ #undef __class__
#define __class__ "Boolean" #define __class__ "Boolean"
bool ejson::Boolean::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Boolean::iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
JSON_PARSE_ELEMENT("start parse : 'Boolean' "); JSON_PARSE_ELEMENT("start parse : 'Boolean' ");
m_value=false; m_value=false;
if( _data[_pos] == 't' if( _data[_pos] == 't'
@ -42,7 +42,7 @@ bool ejson::Boolean::iParse(const std::u32string& _data, int32_t& _pos, ejson::f
} }
bool ejson::Boolean::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Boolean::iGenerate(std::string& _data, int32_t _indent) const {
if (true == m_value) { if (true == m_value) {
_data += "true"; _data += "true";
} else { } else {

View File

@ -50,8 +50,8 @@ namespace ejson
return m_value; return m_value;
}; };
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -14,7 +14,7 @@
#undef __class__ #undef __class__
#define __class__ "Null" #define __class__ "Null"
bool ejson::Null::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Null::iParse(const std::string& _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 !!! ");
@ -33,7 +33,7 @@ bool ejson::Null::iParse(const std::u32string& _data, int32_t& _pos, ejson::file
} }
bool ejson::Null::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Null::iGenerate(std::string& _data, int32_t _indent) const {
_data += "null"; _data += "null";
return true; return true;
} }

View File

@ -28,8 +28,8 @@ namespace ejson
*/ */
virtual ~Null(void) { }; virtual ~Null(void) { };
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -14,9 +14,9 @@
#undef __class__ #undef __class__
#define __class__ "Number" #define __class__ "Number"
bool ejson::Number::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Number::iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
JSON_PARSE_ELEMENT("start parse : 'Number' "); JSON_PARSE_ELEMENT("start parse : 'Number' ");
std::u32string tmpVal; std::string 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
@ -26,7 +26,7 @@ bool ejson::Number::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
tmpVal+=_data[iii]; tmpVal+=_data[iii];
} else { } else {
_pos = iii-1; _pos = iii-1;
m_value = tmpVal.toDouble(); m_value = std::stod(tmpVal);
JSON_PARSE_ELEMENT("end parse : 'Number' "); JSON_PARSE_ELEMENT("end parse : 'Number' ");
return true; return true;
} }
@ -37,7 +37,7 @@ bool ejson::Number::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
} }
bool ejson::Number::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Number::iGenerate(std::string& _data, int32_t _indent) const {
_data += m_value; _data += m_value;
return true; return true;
} }

View File

@ -62,8 +62,8 @@ namespace ejson
return (int64_t)m_value; return (int64_t)m_value;
}; };
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -37,9 +37,9 @@ enum statusParsing {
parseValue, parseValue,
}; };
bool ejson::Object::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Object::iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) {
enum statusParsing mode = parseName; enum statusParsing mode = parseName;
std::u32string currentName; std::string currentName;
JSON_PARSE_ELEMENT("start parse : 'Object' "); JSON_PARSE_ELEMENT("start parse : 'Object' ");
bool standalone = true; bool standalone = true;
int32_t startPos = _pos+1; int32_t startPos = _pos+1;
@ -188,7 +188,7 @@ bool ejson::Object::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
currentName = ""; currentName = "";
} else { } else {
// find an error .... // find an error ....
EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, std::u32string("Find '") + _data[iii] + "' with no element in the element..."); EJSON_CREATE_ERROR(_doc, _data, iii, _filePos, std::string("Find '") + _data[iii] + "' with no element in the element...");
// move the curent index // move the curent index
_pos = iii+1; _pos = iii+1;
return false; return false;
@ -202,7 +202,7 @@ bool ejson::Object::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
} }
return false; return false;
} }
bool ejson::Object::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Object::iGenerate(std::string& _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;
@ -263,18 +263,18 @@ bool ejson::Object::iGenerate(std::u32string& _data, int32_t _indent) const {
return true; return true;
} }
bool ejson::Object::exist(const std::u32string& _name) const { bool ejson::Object::exist(const std::string& _name) const {
return m_value.exist(_name); return m_value.exist(_name);
} }
ejson::Value* ejson::Object::get(const std::u32string& _name) const { ejson::Value* ejson::Object::get(const std::string& _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 std::u32string& _name) const { ejson::Object* ejson::Object::getObject(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -282,7 +282,7 @@ ejson::Object* ejson::Object::getObject(const std::u32string& _name) const {
return tmp->toObject(); return tmp->toObject();
} }
ejson::Array* ejson::Object::getArray(const std::u32string& _name) const { ejson::Array* ejson::Object::getArray(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -290,7 +290,7 @@ ejson::Array* ejson::Object::getArray(const std::u32string& _name) const {
return tmp->toArray(); return tmp->toArray();
} }
ejson::Null* ejson::Object::getNull(const std::u32string& _name) const { ejson::Null* ejson::Object::getNull(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -298,7 +298,7 @@ ejson::Null* ejson::Object::getNull(const std::u32string& _name) const {
return tmp->toNull(); return tmp->toNull();
} }
ejson::String* ejson::Object::getString(const std::u32string& _name) const { ejson::String* ejson::Object::getString(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -306,8 +306,8 @@ ejson::String* ejson::Object::getString(const std::u32string& _name) const {
return tmp->toString(); return tmp->toString();
} }
const std::u32string& ejson::Object::getStringValue(const std::u32string& _name) const { const std::string& ejson::Object::getStringValue(const std::string& _name) const {
static const std::u32string errorString(""); static const std::string errorString("");
ejson::String* tmpp = getString(_name); ejson::String* tmpp = getString(_name);
if (NULL == tmpp) { if (NULL == tmpp) {
return errorString; return errorString;
@ -315,7 +315,7 @@ const std::u32string& ejson::Object::getStringValue(const std::u32string& _name)
return tmpp->get(); return tmpp->get();
} }
std::u32string ejson::Object::getStringValue(const std::u32string& _name, const std::u32string& _errorValue) const { std::string ejson::Object::getStringValue(const std::string& _name, const std::string& _errorValue) const {
ejson::String* tmpp = getString(_name); ejson::String* tmpp = getString(_name);
if (NULL == tmpp) { if (NULL == tmpp) {
return _errorValue; return _errorValue;
@ -323,7 +323,7 @@ std::u32string ejson::Object::getStringValue(const std::u32string& _name, const
return tmpp->get(); return tmpp->get();
} }
ejson::Boolean* ejson::Object::getBoolean(const std::u32string& _name) const { ejson::Boolean* ejson::Object::getBoolean(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -331,7 +331,7 @@ ejson::Boolean* ejson::Object::getBoolean(const std::u32string& _name) const {
return tmp->toBoolean(); return tmp->toBoolean();
} }
bool ejson::Object::getBooleanValue(const std::u32string& _name, bool _errorValue) const { bool ejson::Object::getBooleanValue(const std::string& _name, bool _errorValue) const {
ejson::Boolean* tmpp = getBoolean(_name); ejson::Boolean* tmpp = getBoolean(_name);
if (NULL == tmpp) { if (NULL == tmpp) {
return _errorValue; return _errorValue;
@ -339,7 +339,7 @@ bool ejson::Object::getBooleanValue(const std::u32string& _name, bool _errorValu
return tmpp->get(); return tmpp->get();
} }
ejson::Number* ejson::Object::getNumber(const std::u32string& _name) const { ejson::Number* ejson::Object::getNumber(const std::string& _name) const {
ejson::Value* tmp = get(_name); ejson::Value* tmp = get(_name);
if (NULL == tmp) { if (NULL == tmp) {
return NULL; return NULL;
@ -347,7 +347,7 @@ ejson::Number* ejson::Object::getNumber(const std::u32string& _name) const {
return tmp->toNumber(); return tmp->toNumber();
} }
double ejson::Object::getNumberValue(const std::u32string& _name, double _errorValue) const { double ejson::Object::getNumberValue(const std::string& _name, double _errorValue) const {
ejson::Number* tmpp = getNumber(_name); ejson::Number* tmpp = getNumber(_name);
if (NULL == tmpp) { if (NULL == tmpp) {
return _errorValue; return _errorValue;
@ -356,7 +356,7 @@ double ejson::Object::getNumberValue(const std::u32string& _name, double _errorV
} }
bool ejson::Object::add(const std::u32string& _name, ejson::Value* _value) { bool ejson::Object::add(const std::string& _name, ejson::Value* _value) {
if (NULL == _value) { if (NULL == _value) {
return false; return false;
} }
@ -373,19 +373,19 @@ bool ejson::Object::add(const std::u32string& _name, ejson::Value* _value) {
return true; return true;
} }
bool ejson::Object::addString(const std::u32string& _name, const std::u32string& _value) { bool ejson::Object::addString(const std::string& _name, const std::string& _value) {
return add(_name, new ejson::String(_value)); return add(_name, new ejson::String(_value));
} }
bool ejson::Object::addNull(const std::u32string& _name) { bool ejson::Object::addNull(const std::string& _name) {
return add(_name, new ejson::Null()); return add(_name, new ejson::Null());
} }
bool ejson::Object::addBoolean(const std::u32string& _name, bool _value) { bool ejson::Object::addBoolean(const std::string& _name, bool _value) {
return add(_name, new ejson::Boolean(_value)); return add(_name, new ejson::Boolean(_value));
} }
bool ejson::Object::addNumber(const std::u32string& _name, double _value) { bool ejson::Object::addNumber(const std::string& _name, double _value) {
return add(_name, new ejson::Number(_value)); return add(_name, new ejson::Number(_value));
} }
@ -417,7 +417,7 @@ ejson::Value* ejson::Object::duplicate(void) const {
} }
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);
std::u32string key = m_value.getKey(iii); std::string key = m_value.getKey(iii);
if (NULL == val) { if (NULL == val) {
continue; continue;
} }

View File

@ -36,76 +36,76 @@ namespace ejson
* @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 std::u32string& _name) const; bool exist(const std::string& _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 std::u32string& _name) const; ejson::Value* get(const std::string& _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 std::u32string& _name) const; ejson::Object* getObject(const std::string& _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 std::u32string& _name) const; ejson::Array* getArray(const std::string& _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 std::u32string& _name) const; ejson::Null* getNull(const std::string& _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 std::u32string& _name) const; ejson::String* getString(const std::string& _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 std::u32string& getStringValue(const std::u32string& _name) const; const std::string& getStringValue(const std::string& _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)
*/ */
std::u32string getStringValue(const std::u32string& _name, const std::u32string& _errorValue) const; std::string getStringValue(const std::string& _name, const std::string& _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 std::u32string& _name) const; ejson::Boolean* getBoolean(const std::string& _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 std::u32string& _name, bool _errorValue=false) const; bool getBooleanValue(const std::string& _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 std::u32string& _name) const; ejson::Number* getNumber(const std::string& _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 std::u32string& _name, double _errorValue=false) const; double getNumberValue(const std::string& _name, double _errorValue=false) const;
public: public:
/** /**
* @brief add an element in the Object * @brief add an element in the Object
@ -113,37 +113,37 @@ namespace ejson
* @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 std::u32string& _name, ejson::Value* _value); bool add(const std::string& _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 std::u32string& _name, const std::u32string& _value); bool addString(const std::string& _name, const std::string& _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 std::u32string& _name); bool addNull(const std::string& _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 std::u32string& _name, bool _value); bool addBoolean(const std::string& _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 std::u32string& _name, double _value); bool addNumber(const std::string& _name, double _value);
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeObject; return typeObject;
}; };

View File

@ -18,7 +18,7 @@
bool ejson::String::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::String::iParse(const std::string& _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]);
@ -40,7 +40,7 @@ bool ejson::String::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
} }
bool ejson::String::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::String::iGenerate(std::string& _data, int32_t _indent) const {
_data += "\"";; _data += "\"";;
_data += m_value; _data += m_value;
_data += "\"";; _data += "\"";;

View File

@ -22,27 +22,27 @@ namespace ejson
/** /**
* @brief basic element of a xml structure * @brief basic element of a xml structure
*/ */
String(const std::u32string& _value="") : m_value(_value) { }; String(const std::string& _value="") : m_value(_value) { };
/** /**
* @brief destructor * @brief destructor
*/ */
virtual ~String(void) { }; virtual ~String(void) { };
protected: protected:
std::u32string m_value; //!< value of the node (for element this is the name, for text it is the inside text ...) std::string 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 std::u32string& _value) { m_value = _value; }; void set(const std::string& _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 std::u32string& get(void) const { return m_value; }; const std::string& get(void) const { return m_value; };
public: // herited function : public: // herited function :
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeString; return typeString;
}; };

View File

@ -28,7 +28,7 @@ etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj) {
} }
void ejson::Value::addIndent(std::u32string& _data, int32_t _indent) const { void ejson::Value::addIndent(std::string& _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";
} }
@ -44,12 +44,12 @@ void ejson::Value::drawElementParsed(char32_t _val, const ejson::filePos& _fileP
} }
} }
int32_t ejson::Value::countWhiteChar(const std::u32string& _data, int32_t _pos, ejson::filePos& _filePos) const { int32_t ejson::Value::countWhiteChar(const std::string& _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 == etk::isWhiteChar(_data[iii])) {
white++; white++;
} else { } else {
break; break;

View File

@ -138,14 +138,14 @@ namespace ejson {
* @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 std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) = 0; virtual bool iParse(const std::string& _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(std::u32string& _data, int32_t _indent) const = 0; virtual bool iGenerate(std::string& _data, int32_t _indent) const = 0;
public: public:
/** /**
* @brief get the node type. * @brief get the node type.
@ -160,7 +160,7 @@ namespace ejson {
* @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(std::u32string& _data, int32_t _indent) const; void addIndent(std::string& _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.
@ -184,7 +184,7 @@ 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 std::u32string& _data, int32_t _pos, ejson::filePos& _filePos) const; int32_t countWhiteChar(const std::string& _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.

View File

@ -32,13 +32,13 @@ ejson::Document::~Document(void) {
} }
bool ejson::Document::iGenerate(std::u32string& _data, int32_t _indent) const { bool ejson::Document::iGenerate(std::string& _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 std::u32string& _data) { bool ejson::Document::parse(const std::string& _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);
@ -46,12 +46,12 @@ bool ejson::Document::parse(const std::u32string& _data) {
return iParse(_data, parsePos, filePos, *this); return iParse(_data, parsePos, filePos, *this);
} }
bool ejson::Document::generate(std::u32string& _data) { bool ejson::Document::generate(std::string& _data) {
_data = ""; _data = "";
return iGenerate(_data,0); return iGenerate(_data,0);
} }
bool ejson::Document::load(const std::u32string& _file) { bool ejson::Document::load(const std::string& _file) {
// Start loading the XML : // Start loading the XML :
JSON_VERBOSE("open file (xml) \"" << _file << "\""); JSON_VERBOSE("open file (xml) \"" << _file << "\"");
clear(); clear();
@ -83,7 +83,7 @@ bool ejson::Document::load(const std::u32string& _file) {
tmpFile.fileClose(); tmpFile.fileClose();
// convert in UTF8 : // convert in UTF8 :
std::u32string tmpDataUnicode(fileBuffer, unicode::charsetUTF8); std::string tmpDataUnicode(fileBuffer, unicode::charsetUTF8);
// remove temporary buffer: // remove temporary buffer:
delete(fileBuffer); delete(fileBuffer);
// parse the data : // parse the data :
@ -92,8 +92,8 @@ bool ejson::Document::load(const std::u32string& _file) {
return ret; return ret;
} }
bool ejson::Document::store(const std::u32string& _file) { bool ejson::Document::store(const std::string& _file) {
std::u32string createData; std::string 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;
@ -103,8 +103,7 @@ bool ejson::Document::store(const std::u32string& _file) {
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(); if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != createData.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;
@ -114,13 +113,13 @@ bool ejson::Document::store(const std::u32string& _file) {
} }
void ejson::Document::display(void) { void ejson::Document::display(void) {
std::u32string tmpp; std::string tmpp;
iGenerate(tmpp, 0); iGenerate(tmpp, 0);
JSON_INFO("Generated JSON : \n" << tmpp); JSON_INFO("Generated JSON : \n" << tmpp);
} }
static std::u32string createPosPointer(const std::u32string& _line, int32_t _pos) { static std::string createPosPointer(const std::string& _line, int32_t _pos) {
std::u32string out; std::string 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') {
@ -149,16 +148,16 @@ void ejson::Document::displayError(void) {
#endif #endif
} }
void ejson::Document::createError(const std::u32string& _data, int32_t _pos, const ejson::filePos& _filePos, const std::u32string& _comment) { void ejson::Document::createError(const std::string& _data, int32_t _pos, const ejson::filePos& _filePos, const std::string& _comment) {
m_comment = _comment; m_comment = _comment;
m_Line = _data.extractLine(_pos); m_Line = extract_line(_data, _pos);
m_filePos = _filePos; m_filePos = _filePos;
if (true == m_writeErrorWhenDetexted) { if (true == m_writeErrorWhenDetexted) {
displayError(); displayError();
} }
} }
bool ejson::Document::iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc) { bool ejson::Document::iParse(const std::string& _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;

View File

@ -37,36 +37,36 @@ namespace ejson
* @return false : An error occured * @return false : An error occured
* @return true : Parsing is OK * @return true : Parsing is OK
*/ */
bool parse(const std::u32string& _data); bool parse(const std::string& _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(std::u32string& _data); bool generate(std::string& _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 std::u32string& _file); bool load(const std::string& _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 std::u32string& _file); bool store(const std::string& _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;
std::u32string m_comment; std::string m_comment;
std::u32string m_Line; std::string m_Line;
ejson::filePos m_filePos; ejson::filePos m_filePos;
public: public:
void displayErrorWhenDetected(void) { void displayErrorWhenDetected(void) {
@ -76,14 +76,14 @@ namespace ejson
m_writeErrorWhenDetexted=false; m_writeErrorWhenDetexted=false;
}; };
void createError(const std::u32string& _data, int32_t _pos, const ejson::filePos& _filePos, const std::u32string& _comment); void createError(const std::string& _data, int32_t _pos, const ejson::filePos& _filePos, const std::string& _comment);
void displayError(void); void displayError(void);
public: // herited function: public: // herited function:
virtual enum nodeType getType(void) const { virtual enum nodeType getType(void) const {
return typeDocument; return typeDocument;
}; };
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc); virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const; virtual bool iGenerate(std::string& _data, int32_t _indent) const;
virtual ejson::Document* toDocument(void) { virtual ejson::Document* toDocument(void) {
return this; return this;
}; };

View File

@ -16,11 +16,11 @@
class testCheck { class testCheck {
public: public:
std::u32string m_ref; std::string m_ref;
std::u32string m_input; std::string 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 std::u32string& _ref, int32_t _pos, const std::u32string& _input) { void set(const std::string& _ref, int32_t _pos, const std::string& _input) {
m_ref = _ref; m_ref = _ref;
m_input = _input; m_input = _input;
m_errorPos = _pos; m_errorPos = _pos;
@ -30,8 +30,8 @@ class testCheck {
std::vector<testCheck> l_list; std::vector<testCheck> l_list;
void init(void) { void init(void) {
std::u32string reference; std::string reference;
std::u32string input; std::string input;
testCheck check; testCheck check;
// == ==================================================== // == ====================================================
@ -479,7 +479,7 @@ int main(int argc, const char *argv[]) {
} }
sectionID++; sectionID++;
ejson::Document doc; ejson::Document doc;
std::u32string out(""); std::string 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) {
@ -518,8 +518,8 @@ int main(int argc, const char *argv[]) {
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");
std::vector<std::u32string> tmpout = out.split('\n'); std::vector<std::string> tmpout = out.split('\n');
std::vector<std::u32string> tmpref = l_list[iii].m_ref.split('\n'); std::vector<std::string> 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) {
@ -538,8 +538,8 @@ int main(int argc, const char *argv[]) {
} }
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...");
std::vector<std::u32string> tmpout = out.split('\n'); std::vector<std::string> tmpout = out.split('\n');
std::vector<std::u32string> tmpref = l_list[iii].m_ref.split('\n'); std::vector<std::string> 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) {