[DEV] change idea std::u32string to std::string
This commit is contained in:
parent
43ddd2549c
commit
d24b545ba9
@ -31,7 +31,7 @@ void ejson::Array::clear(void) {
|
||||
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' ");
|
||||
for (int32_t iii=_pos+1; iii<_data.size(); 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;
|
||||
if (m_value.size()>3) {
|
||||
oneLine=false;
|
||||
@ -197,7 +197,7 @@ bool ejson::Array::add(ejson::Value* _element) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ejson::Array::addString(const std::u32string& _value) {
|
||||
bool ejson::Array::addString(const std::string& _value) {
|
||||
return add(new ejson::String(_value));
|
||||
}
|
||||
|
||||
@ -298,8 +298,8 @@ ejson::Boolean* ejson::Array::getBoolean(esize_t _id) {
|
||||
return tmpElement->toBoolean();
|
||||
}
|
||||
|
||||
const std::u32string& ejson::Array::getStringValue(esize_t _id) {
|
||||
static const std::u32string errorValue("");
|
||||
const std::string& ejson::Array::getStringValue(esize_t _id) {
|
||||
static const std::string errorValue("");
|
||||
ejson::String* tmpElement = getString(_id);
|
||||
if (NULL == tmpElement) {
|
||||
return errorValue;
|
||||
@ -307,7 +307,7 @@ const std::u32string& ejson::Array::getStringValue(esize_t _id) {
|
||||
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);
|
||||
if (NULL == tmpElement) {
|
||||
return _errorValue;
|
||||
|
@ -69,14 +69,14 @@ namespace ejson
|
||||
* @param[in] _id Id 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
|
||||
* @param[in] _id Id of the element.
|
||||
* @param[in] _errorValue The return value if an error occured.
|
||||
* @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).
|
||||
* @param[in] _id Id of the element.
|
||||
@ -126,7 +126,7 @@ namespace ejson
|
||||
* @param[in] _value string value to add
|
||||
* @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)
|
||||
* @return false if an error occured
|
||||
@ -146,8 +146,8 @@ namespace ejson
|
||||
bool addNumber(double _value);
|
||||
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeArray;
|
||||
};
|
||||
|
@ -13,7 +13,7 @@
|
||||
#undef __class__
|
||||
#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' ");
|
||||
m_value=false;
|
||||
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) {
|
||||
_data += "true";
|
||||
} else {
|
||||
|
@ -50,8 +50,8 @@ namespace ejson
|
||||
return m_value;
|
||||
};
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeString;
|
||||
};
|
||||
|
@ -14,7 +14,7 @@
|
||||
#undef __class__
|
||||
#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' ");
|
||||
if (_pos+3 >= _data.size()){
|
||||
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";
|
||||
return true;
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ namespace ejson
|
||||
*/
|
||||
virtual ~Null(void) { };
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeString;
|
||||
};
|
||||
|
@ -14,9 +14,9 @@
|
||||
#undef __class__
|
||||
#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' ");
|
||||
std::u32string tmpVal;
|
||||
std::string tmpVal;
|
||||
for (int32_t iii=_pos; iii<_data.size(); iii++) {
|
||||
_filePos.check(_data[iii]);
|
||||
#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];
|
||||
} else {
|
||||
_pos = iii-1;
|
||||
m_value = tmpVal.toDouble();
|
||||
m_value = std::stod(tmpVal);
|
||||
JSON_PARSE_ELEMENT("end parse : 'Number' ");
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ namespace ejson
|
||||
return (int64_t)m_value;
|
||||
};
|
||||
public: // herited function :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeString;
|
||||
};
|
||||
|
@ -37,9 +37,9 @@ enum statusParsing {
|
||||
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;
|
||||
std::u32string currentName;
|
||||
std::string currentName;
|
||||
JSON_PARSE_ELEMENT("start parse : 'Object' ");
|
||||
bool standalone = true;
|
||||
int32_t startPos = _pos+1;
|
||||
@ -188,7 +188,7 @@ bool ejson::Object::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
|
||||
currentName = "";
|
||||
} else {
|
||||
// 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
|
||||
_pos = iii+1;
|
||||
return false;
|
||||
@ -202,7 +202,7 @@ bool ejson::Object::iParse(const std::u32string& _data, int32_t& _pos, ejson::fi
|
||||
}
|
||||
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;
|
||||
if (m_value.size()>3) {
|
||||
oneLine=false;
|
||||
@ -263,18 +263,18 @@ bool ejson::Object::iGenerate(std::u32string& _data, int32_t _indent) const {
|
||||
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);
|
||||
}
|
||||
|
||||
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)) {
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -282,7 +282,7 @@ ejson::Object* ejson::Object::getObject(const std::u32string& _name) const {
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -290,7 +290,7 @@ ejson::Array* ejson::Object::getArray(const std::u32string& _name) const {
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -298,7 +298,7 @@ ejson::Null* ejson::Object::getNull(const std::u32string& _name) const {
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -306,8 +306,8 @@ ejson::String* ejson::Object::getString(const std::u32string& _name) const {
|
||||
return tmp->toString();
|
||||
}
|
||||
|
||||
const std::u32string& ejson::Object::getStringValue(const std::u32string& _name) const {
|
||||
static const std::u32string errorString("");
|
||||
const std::string& ejson::Object::getStringValue(const std::string& _name) const {
|
||||
static const std::string errorString("");
|
||||
ejson::String* tmpp = getString(_name);
|
||||
if (NULL == tmpp) {
|
||||
return errorString;
|
||||
@ -315,7 +315,7 @@ const std::u32string& ejson::Object::getStringValue(const std::u32string& _name)
|
||||
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);
|
||||
if (NULL == tmpp) {
|
||||
return _errorValue;
|
||||
@ -323,7 +323,7 @@ std::u32string ejson::Object::getStringValue(const std::u32string& _name, const
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -331,7 +331,7 @@ ejson::Boolean* ejson::Object::getBoolean(const std::u32string& _name) const {
|
||||
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);
|
||||
if (NULL == tmpp) {
|
||||
return _errorValue;
|
||||
@ -339,7 +339,7 @@ bool ejson::Object::getBooleanValue(const std::u32string& _name, bool _errorValu
|
||||
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);
|
||||
if (NULL == tmp) {
|
||||
return NULL;
|
||||
@ -347,7 +347,7 @@ ejson::Number* ejson::Object::getNumber(const std::u32string& _name) const {
|
||||
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);
|
||||
if (NULL == tmpp) {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
@ -373,19 +373,19 @@ bool ejson::Object::add(const std::u32string& _name, ejson::Value* _value) {
|
||||
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));
|
||||
}
|
||||
|
||||
bool ejson::Object::addNull(const std::u32string& _name) {
|
||||
bool ejson::Object::addNull(const std::string& _name) {
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@ -417,7 +417,7 @@ ejson::Value* ejson::Object::duplicate(void) const {
|
||||
}
|
||||
for (esize_t iii=0; iii<m_value.size(); ++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) {
|
||||
continue;
|
||||
}
|
||||
|
@ -36,76 +36,76 @@ namespace ejson
|
||||
* @param[in] _name name of the object.
|
||||
* @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)
|
||||
* @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
|
||||
*/
|
||||
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)
|
||||
* @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
|
||||
*/
|
||||
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)
|
||||
* @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
|
||||
*/
|
||||
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)
|
||||
* @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
|
||||
*/
|
||||
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)
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
* @param[in] _name name of the object
|
||||
* @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)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @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)
|
||||
* @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
|
||||
*/
|
||||
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.
|
||||
* @param[in] _name name of the object.
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @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)
|
||||
* @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
|
||||
*/
|
||||
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.
|
||||
* @param[in] _name name of the object.
|
||||
* @param[in] _errorValue The return value if the element does not exist.
|
||||
* @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:
|
||||
/**
|
||||
* @brief add an element in the Object
|
||||
@ -113,37 +113,37 @@ namespace ejson
|
||||
* @param[in] _value Element to add
|
||||
* @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)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value string value to add
|
||||
* @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)
|
||||
* @param[in] _name name of the object
|
||||
* @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)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value boolean value to add
|
||||
* @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)
|
||||
* @param[in] _name name of the object
|
||||
* @param[in] _value double value to add
|
||||
* @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 :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeObject;
|
||||
};
|
||||
|
@ -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' ");
|
||||
for (int32_t iii=_pos+1; iii<_data.size(); 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 += m_value;
|
||||
_data += "\"";;
|
||||
|
@ -22,27 +22,27 @@ namespace ejson
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
virtual ~String(void) { };
|
||||
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:
|
||||
/**
|
||||
* @brief set the 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.
|
||||
* @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 :
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeString;
|
||||
};
|
||||
|
@ -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++) {
|
||||
_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();
|
||||
int32_t white=0;
|
||||
for (int32_t iii=_pos; iii<_data.size(); iii++) {
|
||||
_filePos.check(_data[iii]);
|
||||
if(true == _data[iii].isWhiteChar()) {
|
||||
if(true == etk::isWhiteChar(_data[iii])) {
|
||||
white++;
|
||||
} else {
|
||||
break;
|
||||
|
@ -138,14 +138,14 @@ namespace ejson {
|
||||
* @param[in,out] file parsing position (line x col x)
|
||||
* @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
|
||||
* @param[in,out] _data string where to add the elements
|
||||
* @param[in] current indentation of the file
|
||||
* @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:
|
||||
/**
|
||||
* @brief get the node type.
|
||||
@ -160,7 +160,7 @@ namespace ejson {
|
||||
* @param[in,out] _data String where the indentation is done.
|
||||
* @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.
|
||||
* @param[in] _val Char that is parsed.
|
||||
@ -184,7 +184,7 @@ namespace ejson {
|
||||
* @param[out] _filePos new poistion of te file to add.
|
||||
* @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:
|
||||
/**
|
||||
* @brief Cast the element in a Value if it is possible.
|
||||
|
@ -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);
|
||||
_data += "\n";
|
||||
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());
|
||||
clear();
|
||||
ejson::filePos filePos(1,0);
|
||||
@ -46,12 +46,12 @@ bool ejson::Document::parse(const std::u32string& _data) {
|
||||
return iParse(_data, parsePos, filePos, *this);
|
||||
}
|
||||
|
||||
bool ejson::Document::generate(std::u32string& _data) {
|
||||
bool ejson::Document::generate(std::string& _data) {
|
||||
_data = "";
|
||||
return iGenerate(_data,0);
|
||||
}
|
||||
|
||||
bool ejson::Document::load(const std::u32string& _file) {
|
||||
bool ejson::Document::load(const std::string& _file) {
|
||||
// Start loading the XML :
|
||||
JSON_VERBOSE("open file (xml) \"" << _file << "\"");
|
||||
clear();
|
||||
@ -83,7 +83,7 @@ bool ejson::Document::load(const std::u32string& _file) {
|
||||
tmpFile.fileClose();
|
||||
|
||||
// convert in UTF8 :
|
||||
std::u32string tmpDataUnicode(fileBuffer, unicode::charsetUTF8);
|
||||
std::string tmpDataUnicode(fileBuffer, unicode::charsetUTF8);
|
||||
// remove temporary buffer:
|
||||
delete(fileBuffer);
|
||||
// parse the data :
|
||||
@ -92,8 +92,8 @@ bool ejson::Document::load(const std::u32string& _file) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ejson::Document::store(const std::u32string& _file) {
|
||||
std::u32string createData;
|
||||
bool ejson::Document::store(const std::string& _file) {
|
||||
std::string createData;
|
||||
if (false == generate(createData)) {
|
||||
JSON_ERROR("Error while creating the XML : " << _file);
|
||||
return false;
|
||||
@ -103,8 +103,7 @@ bool ejson::Document::store(const std::u32string& _file) {
|
||||
JSON_ERROR("Can not open (w) the file : " << _file);
|
||||
return false;
|
||||
}
|
||||
etk::Char endTable = createData.c_str();
|
||||
if (tmpFile.fileWrite(endTable, sizeof(char), endTable.size()) != endTable.size()) {
|
||||
if (tmpFile.fileWrite((char*)createData.c_str(), sizeof(char), createData.size()) != createData.size()) {
|
||||
JSON_ERROR("Error while writing output XML file : " << _file);
|
||||
tmpFile.fileClose();
|
||||
return false;
|
||||
@ -114,13 +113,13 @@ bool ejson::Document::store(const std::u32string& _file) {
|
||||
}
|
||||
|
||||
void ejson::Document::display(void) {
|
||||
std::u32string tmpp;
|
||||
std::string tmpp;
|
||||
iGenerate(tmpp, 0);
|
||||
JSON_INFO("Generated JSON : \n" << tmpp);
|
||||
}
|
||||
|
||||
static std::u32string createPosPointer(const std::u32string& _line, int32_t _pos) {
|
||||
std::u32string out;
|
||||
static std::string createPosPointer(const std::string& _line, int32_t _pos) {
|
||||
std::string out;
|
||||
int32_t iii;
|
||||
for (iii=0; iii<_pos && iii<_line.size(); iii++) {
|
||||
if (_line[iii] == '\t') {
|
||||
@ -149,16 +148,16 @@ void ejson::Document::displayError(void) {
|
||||
#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_Line = _data.extractLine(_pos);
|
||||
m_Line = extract_line(_data, _pos);
|
||||
m_filePos = _filePos;
|
||||
if (true == m_writeErrorWhenDetexted) {
|
||||
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' ");
|
||||
bool haveMainNode=false;
|
||||
bool nodeParsed=false;
|
||||
|
@ -37,36 +37,36 @@ namespace ejson
|
||||
* @return false : An error occured
|
||||
* @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
|
||||
* @param[out] _data Data where the xml is stored
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool generate(std::u32string& _data);
|
||||
bool generate(std::string& _data);
|
||||
/**
|
||||
* @brief Load the file that might contain the xml
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool load(const std::u32string& _file);
|
||||
bool load(const std::string& _file);
|
||||
/**
|
||||
* @brief Store the Xml in the file
|
||||
* @param[in] _file Filename of the xml (compatible with etk FSNode naming)
|
||||
* @return false : An error occured
|
||||
* @return true : Parsing is OK
|
||||
*/
|
||||
bool store(const std::u32string& _file);
|
||||
bool store(const std::string& _file);
|
||||
/**
|
||||
* @brief Display the Document on console
|
||||
*/
|
||||
void display(void);
|
||||
private:
|
||||
bool m_writeErrorWhenDetexted;
|
||||
std::u32string m_comment;
|
||||
std::u32string m_Line;
|
||||
std::string m_comment;
|
||||
std::string m_Line;
|
||||
ejson::filePos m_filePos;
|
||||
public:
|
||||
void displayErrorWhenDetected(void) {
|
||||
@ -76,14 +76,14 @@ namespace ejson
|
||||
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);
|
||||
public: // herited function:
|
||||
virtual enum nodeType getType(void) const {
|
||||
return typeDocument;
|
||||
};
|
||||
virtual bool iParse(const std::u32string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, ejson::filePos& _filePos, ejson::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual ejson::Document* toDocument(void) {
|
||||
return this;
|
||||
};
|
||||
|
@ -16,11 +16,11 @@
|
||||
|
||||
class testCheck {
|
||||
public:
|
||||
std::u32string m_ref;
|
||||
std::u32string m_input;
|
||||
std::string m_ref;
|
||||
std::string m_input;
|
||||
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
||||
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_input = _input;
|
||||
m_errorPos = _pos;
|
||||
@ -30,8 +30,8 @@ class testCheck {
|
||||
std::vector<testCheck> l_list;
|
||||
|
||||
void init(void) {
|
||||
std::u32string reference;
|
||||
std::u32string input;
|
||||
std::string reference;
|
||||
std::string input;
|
||||
testCheck check;
|
||||
|
||||
// == ====================================================
|
||||
@ -479,7 +479,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
sectionID++;
|
||||
ejson::Document doc;
|
||||
std::u32string out("");
|
||||
std::string out("");
|
||||
//JSON_DEBUG("parse : \n" << l_list[iii].m_input);
|
||||
if (false == doc.parse(l_list[iii].m_input)) {
|
||||
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)");
|
||||
} else {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output");
|
||||
std::vector<std::u32string> tmpout = out.split('\n');
|
||||
std::vector<std::u32string> tmpref = l_list[iii].m_ref.split('\n');
|
||||
std::vector<std::string> tmpout = out.split('\n');
|
||||
std::vector<std::string> tmpref = l_list[iii].m_ref.split('\n');
|
||||
//JSON_ERROR("generate : \n" << out);
|
||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
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) {
|
||||
JSON_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR} checking result might be in error...");
|
||||
std::vector<std::u32string> tmpout = out.split('\n');
|
||||
std::vector<std::u32string> tmpref = l_list[iii].m_ref.split('\n');
|
||||
std::vector<std::string> tmpout = out.split('\n');
|
||||
std::vector<std::string> tmpref = l_list[iii].m_ref.split('\n');
|
||||
//JSON_ERROR("generate : \n" << out);
|
||||
//JSON_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
for (int32_t jjj=0; jjj<tmpout.size() || jjj<tmpref.size(); ++jjj) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user