[DEV] update exml with std::shared_ptr and gtest interface
This commit is contained in:
parent
479921d347
commit
d58d0e7943
@ -13,6 +13,14 @@
|
||||
#undef __class__
|
||||
#define __class__ "Attribute"
|
||||
|
||||
std::shared_ptr<exml::Attribute> exml::Attribute::create() {
|
||||
return std::shared_ptr<exml::Attribute>(new exml::Attribute());
|
||||
}
|
||||
std::shared_ptr<exml::Attribute> exml::Attribute::create(const std::string& _name, const std::string& _value) {
|
||||
return std::shared_ptr<exml::Attribute>(new exml::Attribute(_name, _value));
|
||||
}
|
||||
|
||||
|
||||
exml::Attribute::Attribute(const std::string& _name, const std::string& _value) :
|
||||
exml::Node(_value),
|
||||
m_name(_name) {
|
||||
@ -29,14 +37,14 @@ bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
||||
drawElementParsed(_data[iii], _filePos);
|
||||
#endif
|
||||
if (true == checkAvaillable(_data[iii], false) ) {
|
||||
if (checkAvaillable(_data[iii], false) == true) {
|
||||
lastElementName = iii;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_name = std::string(_data, _pos, lastElementName+1-(_pos));
|
||||
if (true == _caseSensitive) {
|
||||
if (_caseSensitive == true) {
|
||||
m_name = etk::tolower(m_name);
|
||||
}
|
||||
// count white space :
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
namespace exml {
|
||||
class Attribute : public exml::Node {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
@ -25,6 +25,9 @@ namespace exml {
|
||||
* @param[in] _value Value of the attribute.
|
||||
*/
|
||||
Attribute(const std::string& _name, const std::string& _value);
|
||||
public:
|
||||
static std::shared_ptr<Attribute> create();
|
||||
static std::shared_ptr<Attribute> create(const std::string& _name, const std::string& _value);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
@ -52,11 +55,11 @@ namespace exml {
|
||||
};
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual exml::Attribute* toAttribute() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Attribute> toAttribute() {
|
||||
return std::static_pointer_cast<exml::Attribute>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Attribute* toAttribute() const {
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Attribute> toAttribute() const {
|
||||
return std::static_pointer_cast<const exml::Attribute>(shared_from_this());
|
||||
};
|
||||
virtual void clear();
|
||||
};
|
||||
|
@ -13,23 +13,17 @@
|
||||
#define __class__ "AttributeList"
|
||||
|
||||
exml::AttributeList::~AttributeList() {
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if (NULL!=m_listAttribute[iii]) {
|
||||
delete(m_listAttribute[iii]);
|
||||
m_listAttribute[iii]=nullptr;
|
||||
}
|
||||
}
|
||||
m_listAttribute.clear();
|
||||
}
|
||||
|
||||
exml::Attribute* exml::AttributeList::getAttr(int32_t _id) {
|
||||
std::shared_ptr<exml::Attribute> exml::AttributeList::getAttr(int32_t _id) {
|
||||
if (_id <0 || (size_t)_id>m_listAttribute.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_listAttribute[_id];
|
||||
}
|
||||
|
||||
const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const {
|
||||
std::shared_ptr<const exml::Attribute> exml::AttributeList::getAttr(int32_t _id) const {
|
||||
if (_id <0 || (size_t)_id>m_listAttribute.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -37,7 +31,7 @@ const exml::Attribute* exml::AttributeList::getAttr(int32_t _id) const {
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> exml::AttributeList::getAttrPair(int32_t _id) const {
|
||||
const exml::Attribute* att = getAttr(_id);
|
||||
std::shared_ptr<const exml::Attribute> att = getAttr(_id);
|
||||
if (att == nullptr) {
|
||||
return std::make_pair<std::string, std::string>("","");
|
||||
}
|
||||
@ -45,7 +39,7 @@ std::pair<std::string, std::string> exml::AttributeList::getAttrPair(int32_t _id
|
||||
}
|
||||
|
||||
|
||||
void exml::AttributeList::appendAttribute(exml::Attribute* _attr) {
|
||||
void exml::AttributeList::appendAttribute(const std::shared_ptr<exml::Attribute>& _attr) {
|
||||
if (_attr == nullptr) {
|
||||
EXML_ERROR("Try to set an empty node");
|
||||
return;
|
||||
@ -65,7 +59,7 @@ const std::string& exml::AttributeList::getAttribute(const std::string& _name) c
|
||||
return errorReturn;
|
||||
}
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if( NULL != m_listAttribute[iii]
|
||||
if( m_listAttribute[iii] != nullptr
|
||||
&& m_listAttribute[iii]->getName() == _name) {
|
||||
return m_listAttribute[iii]->getValue();
|
||||
}
|
||||
@ -79,7 +73,7 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
|
||||
return false;
|
||||
}
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if( NULL != m_listAttribute[iii]
|
||||
if( m_listAttribute[iii] != nullptr
|
||||
&& m_listAttribute[iii]->getName() == _name) {
|
||||
return true;
|
||||
}
|
||||
@ -90,15 +84,15 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const {
|
||||
void exml::AttributeList::setAttribute(const std::string& _name, const std::string& _value) {
|
||||
// check if attribute already det :
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if( NULL != m_listAttribute[iii]
|
||||
if( m_listAttribute[iii] != nullptr
|
||||
&& m_listAttribute[iii]->getName() == _name) {
|
||||
// update the value :
|
||||
m_listAttribute[iii]->setValue(_value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
exml::Attribute* attr = new exml::Attribute(_name, _value);
|
||||
if (NULL == attr) {
|
||||
std::shared_ptr<exml::Attribute> attr = exml::Attribute::create(_name, _value);
|
||||
if (attr == nullptr) {
|
||||
EXML_ERROR("memory allocation error...");
|
||||
}
|
||||
m_listAttribute.push_back(attr);
|
||||
@ -106,7 +100,7 @@ void exml::AttributeList::setAttribute(const std::string& _name, const std::stri
|
||||
|
||||
bool exml::AttributeList::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if (NULL!=m_listAttribute[iii]) {
|
||||
if (m_listAttribute[iii] != nullptr) {
|
||||
m_listAttribute[iii]->iGenerate(_data, _indent);
|
||||
}
|
||||
}
|
||||
@ -115,12 +109,6 @@ bool exml::AttributeList::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
|
||||
void exml::AttributeList::clear() {
|
||||
exml::Node::clear();
|
||||
for (size_t iii=0; iii<m_listAttribute.size(); iii++) {
|
||||
if (NULL!=m_listAttribute[iii]) {
|
||||
delete(m_listAttribute[iii]);
|
||||
m_listAttribute[iii]=NULL;
|
||||
}
|
||||
}
|
||||
m_listAttribute.clear();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace exml {
|
||||
*/
|
||||
virtual ~AttributeList();
|
||||
protected:
|
||||
std::vector<exml::Attribute*> m_listAttribute; //!< list of all attribute
|
||||
std::vector<std::shared_ptr<exml::Attribute>> m_listAttribute; //!< list of all attribute
|
||||
public:
|
||||
/**
|
||||
* @brief get the number of attribute in the Node
|
||||
@ -47,14 +47,14 @@ namespace exml {
|
||||
* @brief add attribute on the List
|
||||
* @param[in] _attr Pointer on the attribute
|
||||
*/
|
||||
void appendAttribute(exml::Attribute* _attr);
|
||||
void appendAttribute(const std::shared_ptr<exml::Attribute>& _attr);
|
||||
/**
|
||||
* @brief get attribute whith his ID
|
||||
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
|
||||
* @return Pointer on the attribute or NULL
|
||||
*/
|
||||
Attribute* getAttr(int32_t _id);
|
||||
const Attribute* getAttr(int32_t _id) const;
|
||||
std::shared_ptr<Attribute> getAttr(int32_t _id);
|
||||
std::shared_ptr<const Attribute> getAttr(int32_t _id) const;
|
||||
std::pair<std::string, std::string> getAttrPair(int32_t _id) const;
|
||||
/**
|
||||
* @brief get the attribute value with searching in the List with his name
|
||||
|
@ -24,7 +24,9 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<exml::Comment> exml::Comment::create() {
|
||||
return std::shared_ptr<exml::Comment>(new exml::Comment());
|
||||
}
|
||||
|
||||
bool exml::Comment::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
|
||||
EXML_VERBOSE("start parse : 'comment'");
|
||||
@ -47,7 +49,7 @@ bool exml::Comment::iParse(const std::string& _data, int32_t& _pos, bool _caseSe
|
||||
// search whitespace :
|
||||
int32_t newEnd=iii;
|
||||
for( int32_t jjj=iii-1; jjj>_pos; jjj--) {
|
||||
if(true == isWhiteChar(_data[jjj])) {
|
||||
if(isWhiteChar(_data[jjj]) == true) {
|
||||
newEnd = jjj;
|
||||
} else {
|
||||
break;
|
||||
|
@ -14,11 +14,13 @@
|
||||
|
||||
namespace exml {
|
||||
class Comment : public exml::Node {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Comment() { };
|
||||
public:
|
||||
static std::shared_ptr<Comment> create();
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _value comment value
|
||||
@ -37,11 +39,11 @@ namespace exml {
|
||||
};
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual exml::Comment* toComment() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Comment> toComment() {
|
||||
return std::static_pointer_cast<exml::Comment>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Comment* toComment() const {
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Comment> toComment() const {
|
||||
return std::static_pointer_cast<const exml::Comment>(shared_from_this());
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -20,6 +20,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
*/
|
||||
|
||||
|
||||
std::shared_ptr<exml::Declaration> exml::Declaration::create() {
|
||||
return std::shared_ptr<exml::Declaration>(new exml::Declaration());
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Declaration> exml::Declaration::create(const std::string& _name) {
|
||||
return std::shared_ptr<exml::Declaration>(new exml::Declaration(_name));
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::DeclarationXML> exml::DeclarationXML::create(const std::string& _version, const std::string& _format, bool _standalone) {
|
||||
return std::shared_ptr<exml::DeclarationXML>(new exml::DeclarationXML(_version, _format, _standalone));
|
||||
}
|
||||
|
||||
exml::DeclarationXML::DeclarationXML(const std::string& _version, const std::string& _format, bool _standalone) :
|
||||
exml::Declaration("xml") {
|
||||
if (_version.size()!=0) {
|
||||
@ -71,16 +84,15 @@ bool exml::Declaration::iParse(const std::string& _data, int32_t& _pos, bool _ca
|
||||
_pos = iii+1;
|
||||
return true;
|
||||
}
|
||||
if (true == checkAvaillable(_data[iii], true)) {
|
||||
if (checkAvaillable(_data[iii], true) == true) {
|
||||
// we find an attibute == > create a new and parse it :
|
||||
exml::Attribute* attribute = new exml::Attribute();
|
||||
if (NULL == attribute) {
|
||||
std::shared_ptr<exml::Attribute> attribute = exml::Attribute::create();
|
||||
if (attribute == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = iii;
|
||||
if (false == attribute->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(attribute);
|
||||
if (attribute->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
namespace exml {
|
||||
class Declaration : public exml::AttributeList {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
@ -26,6 +26,9 @@ namespace exml {
|
||||
exml::AttributeList(_name) {
|
||||
|
||||
};
|
||||
public:
|
||||
static std::shared_ptr<Declaration> create();
|
||||
static std::shared_ptr<Declaration> create(const std::string& _name);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
@ -36,11 +39,11 @@ namespace exml {
|
||||
};
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual exml::Declaration* toDeclaration() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Declaration> toDeclaration() {
|
||||
return std::static_pointer_cast<exml::Declaration>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Declaration* toDeclaration() const {
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Declaration> toDeclaration() const {
|
||||
return std::static_pointer_cast<const exml::Declaration>(shared_from_this());
|
||||
};
|
||||
};
|
||||
class DeclarationXML : public exml::Declaration {
|
||||
@ -52,6 +55,8 @@ namespace exml {
|
||||
* @param[in] _standalone this document is standalone
|
||||
*/
|
||||
DeclarationXML(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
|
||||
public:
|
||||
static std::shared_ptr<DeclarationXML> create(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
|
@ -13,6 +13,11 @@
|
||||
#undef __class__
|
||||
#define __class__ "Document"
|
||||
|
||||
|
||||
std::shared_ptr<exml::Document> exml::Document::create() {
|
||||
return std::shared_ptr<exml::Document>(new exml::Document());
|
||||
}
|
||||
|
||||
exml::Document::Document() :
|
||||
m_caseSensitive(false),
|
||||
m_writeErrorWhenDetexted(true),
|
||||
@ -25,7 +30,7 @@ exml::Document::Document() :
|
||||
|
||||
bool exml::Document::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
if (m_listSub[iii] != nullptr) {
|
||||
m_listSub[iii]->iGenerate(_data, _indent);
|
||||
}
|
||||
}
|
||||
@ -52,35 +57,29 @@ bool exml::Document::load(const std::string& _file) {
|
||||
EXML_VERBOSE("open file (xml) \"" << _file << "\"");
|
||||
clear();
|
||||
etk::FSNode tmpFile(_file);
|
||||
if (false == tmpFile.exist()) {
|
||||
if (tmpFile.exist() == false) {
|
||||
EXML_ERROR("File Does not exist : " << _file);
|
||||
return false;
|
||||
}
|
||||
int64_t fileSize = tmpFile.fileSize();
|
||||
if (0 == fileSize) {
|
||||
if (fileSize == 0) {
|
||||
EXML_ERROR("This file is empty : " << _file);
|
||||
return false;
|
||||
}
|
||||
if (false == tmpFile.fileOpenRead()) {
|
||||
if (tmpFile.fileOpenRead() == false) {
|
||||
EXML_ERROR("Can not open (r) the file : " << _file);
|
||||
return false;
|
||||
}
|
||||
// allocate data
|
||||
char * fileBuffer = new char[fileSize+5];
|
||||
if (NULL == fileBuffer) {
|
||||
EXML_ERROR("Error Memory allocation size=" << fileSize);
|
||||
return false;
|
||||
}
|
||||
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
|
||||
std::vector<char> fileBuffer;
|
||||
fileBuffer.resize(fileSize+5, 0);
|
||||
// load data from the file :
|
||||
tmpFile.fileRead(fileBuffer, 1, fileSize);
|
||||
tmpFile.fileRead(&fileBuffer[0], 1, fileSize);
|
||||
// close the file:
|
||||
tmpFile.fileClose();
|
||||
|
||||
// convert in UTF8 :
|
||||
std::string tmpDataUnicode(fileBuffer);
|
||||
// remove temporary buffer:
|
||||
delete[] fileBuffer;
|
||||
std::string tmpDataUnicode(&fileBuffer[0]);
|
||||
// parse the data :
|
||||
bool ret = parse(tmpDataUnicode);
|
||||
//Display();
|
||||
@ -89,12 +88,12 @@ bool exml::Document::load(const std::string& _file) {
|
||||
|
||||
bool exml::Document::store(const std::string& _file) {
|
||||
std::string createData;
|
||||
if (false == generate(createData)) {
|
||||
if (generate(createData) == false) {
|
||||
EXML_ERROR("Error while creating the XML : " << _file);
|
||||
return false;
|
||||
}
|
||||
etk::FSNode tmpFile(_file);
|
||||
if (false == tmpFile.fileOpenWrite()) {
|
||||
if (tmpFile.fileOpenWrite() == false) {
|
||||
EXML_ERROR("Can not open (w) the file : " << _file);
|
||||
return false;
|
||||
}
|
||||
@ -147,7 +146,7 @@ void exml::Document::createError(const std::string& _data, int32_t _pos, const e
|
||||
m_comment = _comment;
|
||||
m_Line = etk::extract_line(_data, _pos);
|
||||
m_filePos = _filePos;
|
||||
if (true == m_writeErrorWhenDetexted) {
|
||||
if (m_writeErrorWhenDetexted== true) {
|
||||
displayError();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace exml {
|
||||
* @brief Constructor
|
||||
*/
|
||||
Document();
|
||||
static std::shared_ptr<Document> create();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
@ -93,11 +94,11 @@ namespace exml {
|
||||
return typeDocument;
|
||||
};
|
||||
bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual exml::Document* toDocument() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Document> toDocument() {
|
||||
return std::static_pointer_cast<exml::Document>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Document* toDocument() const {
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Document> toDocument() const {
|
||||
return std::static_pointer_cast<const exml::Document>(shared_from_this());
|
||||
};
|
||||
};
|
||||
};
|
||||
|
148
exml/Element.cpp
148
exml/Element.cpp
@ -28,98 +28,100 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<exml::Element> exml::Element::create() {
|
||||
return std::shared_ptr<exml::Element>(new exml::Element());
|
||||
}
|
||||
std::shared_ptr<exml::Element> exml::Element::create(const std::string& _value) {
|
||||
return std::shared_ptr<exml::Element>(new exml::Element(_value));
|
||||
}
|
||||
|
||||
|
||||
exml::Element::~Element() {
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
delete(m_listSub[iii]);
|
||||
m_listSub[iii]=NULL;
|
||||
}
|
||||
}
|
||||
m_listSub.clear();
|
||||
}
|
||||
|
||||
enum exml::nodeType exml::Element::getType(int32_t _id) {
|
||||
exml::Node* tmpp = getNode(_id);
|
||||
if (NULL == tmpp) {
|
||||
std::shared_ptr<exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return exml::typeUnknow;
|
||||
}
|
||||
return tmpp->getType();
|
||||
}
|
||||
const enum exml::nodeType exml::Element::getType(int32_t _id) const {
|
||||
const exml::Node* tmpp = getNode(_id);
|
||||
if (NULL == tmpp) {
|
||||
std::shared_ptr<const exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return exml::typeUnknow;
|
||||
}
|
||||
return tmpp->getType();
|
||||
}
|
||||
|
||||
exml::Node* exml::Element::getNode(int32_t _id) {
|
||||
std::shared_ptr<exml::Node> exml::Element::getNode(int32_t _id) {
|
||||
if (_id <0 || (size_t)_id>m_listSub.size()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return m_listSub[_id];
|
||||
}
|
||||
|
||||
const exml::Node* exml::Element::getNode(int32_t _id) const {
|
||||
std::shared_ptr<const exml::Node> exml::Element::getNode(int32_t _id) const {
|
||||
if (_id <0 || (size_t)_id>m_listSub.size()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return m_listSub[_id];
|
||||
}
|
||||
|
||||
|
||||
exml::Element* exml::Element::getElement(int32_t _id) {
|
||||
exml::Node* tmpp = getNode(_id);
|
||||
if (NULL == tmpp) {
|
||||
return NULL;
|
||||
std::shared_ptr<exml::Element> exml::Element::getElement(int32_t _id) {
|
||||
std::shared_ptr<exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return tmpp->toElement();
|
||||
}
|
||||
|
||||
const exml::Element* exml::Element::getElement(int32_t _id) const {
|
||||
const exml::Node* tmpp = getNode(_id);
|
||||
if (NULL == tmpp) {
|
||||
return NULL;
|
||||
std::shared_ptr<const exml::Element> exml::Element::getElement(int32_t _id) const {
|
||||
std::shared_ptr<const exml::Node> tmpp = getNode(_id);
|
||||
if (tmpp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return tmpp->toElement();
|
||||
}
|
||||
|
||||
exml::Element* exml::Element::getNamed(const std::string& _name) {
|
||||
std::shared_ptr<exml::Element> exml::Element::getNamed(const std::string& _name) {
|
||||
if (_name.size() == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if( NULL != m_listSub[iii]
|
||||
if( m_listSub[iii] != nullptr
|
||||
&& m_listSub[iii]->getType() == exml::typeElement
|
||||
&& m_listSub[iii]->getValue() == _name) {
|
||||
if (NULL == m_listSub[iii]) {
|
||||
return NULL;
|
||||
if (m_listSub[iii] == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_listSub[iii]->toElement();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const exml::Element* exml::Element::getNamed(const std::string& _name) const {
|
||||
std::shared_ptr<const exml::Element> exml::Element::getNamed(const std::string& _name) const {
|
||||
if (_name.size() == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if( NULL != m_listSub[iii]
|
||||
if( m_listSub[iii] != nullptr
|
||||
&& m_listSub[iii]->getType() == exml::typeElement
|
||||
&& m_listSub[iii]->getValue() == _name) {
|
||||
if (NULL == m_listSub[iii]) {
|
||||
return NULL;
|
||||
if (m_listSub[iii] == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_listSub[iii]->toElement();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void exml::Element::append(exml::Node* _node) {
|
||||
if (_node == NULL) {
|
||||
void exml::Element::append(const std::shared_ptr<exml::Node>& _node) {
|
||||
if (_node == nullptr) {
|
||||
EXML_ERROR("Try to set an empty node");
|
||||
return;
|
||||
}
|
||||
@ -146,7 +148,7 @@ std::string exml::Element::getText() {
|
||||
}
|
||||
} else {
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
if (m_listSub[iii] != nullptr) {
|
||||
m_listSub[iii]->iGenerate(res, 0);
|
||||
}
|
||||
}
|
||||
@ -162,16 +164,16 @@ bool exml::Element::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
|
||||
if (m_listSub.size()>0) {
|
||||
if( m_listSub.size() == 1
|
||||
&& m_listSub[0] != NULL
|
||||
&& m_listSub[0] != nullptr
|
||||
&& m_listSub[0]->getType() == exml::typeText
|
||||
&& static_cast<exml::Text*>(m_listSub[0])->countLines() == 1) {
|
||||
&& std::dynamic_pointer_cast<exml::Text>(m_listSub[0])->countLines() == 1) {
|
||||
_data += ">";
|
||||
m_listSub[0]->iGenerate(_data,0);
|
||||
} else {
|
||||
_data += ">\n";
|
||||
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
if (m_listSub[iii] != nullptr) {
|
||||
m_listSub[iii]->iGenerate(_data, _indent+1);
|
||||
}
|
||||
}
|
||||
@ -213,7 +215,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
if(_data[iii+white+1] == '?') {
|
||||
++tmpPos;
|
||||
// TODO : white space ...
|
||||
if( false == checkAvaillable(_data[iii+white+2], true) ) {
|
||||
if(checkAvaillable(_data[iii+white+2], true) == false) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find unavaillable name in the Declaration node...");
|
||||
_pos = iii+white+1;
|
||||
return false;
|
||||
@ -222,7 +224,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
size_t endPosName = iii+white+1;
|
||||
// generate element name ...
|
||||
for (size_t jjj=iii+white+2; jjj<_data.size(); jjj++) {
|
||||
if(true == checkAvaillable(_data[jjj], false) ) {
|
||||
if(checkAvaillable(_data[jjj], false) == true) {
|
||||
// we find the end ...
|
||||
endPosName = jjj;
|
||||
} else {
|
||||
@ -231,19 +233,18 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
tmpPos.check(_data[jjj]);
|
||||
}
|
||||
std::string tmpname = std::string(_data, iii+white+2, endPosName+1-(iii+white+2));
|
||||
if (true == _caseSensitive) {
|
||||
if (_caseSensitive == true) {
|
||||
tmpname = etk::tolower(tmpname);
|
||||
}
|
||||
// Find declaration balise
|
||||
exml::Declaration* declaration = new exml::Declaration(tmpname);
|
||||
if (NULL == declaration) {
|
||||
std::shared_ptr<exml::Declaration> declaration = exml::Declaration::create(tmpname);
|
||||
if (declaration == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation Error...");
|
||||
return false;
|
||||
}
|
||||
_filePos += tmpPos;
|
||||
_pos = endPosName+1;
|
||||
if (false == declaration->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(declaration);
|
||||
if (declaration->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
@ -269,15 +270,14 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
}
|
||||
++tmpPos;
|
||||
// find comment:
|
||||
exml::Comment* comment = new exml::Comment();
|
||||
if (NULL == comment) {
|
||||
std::shared_ptr<exml::Comment> comment = exml::Comment::create();
|
||||
if (comment == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = iii+white+4;
|
||||
_filePos += tmpPos;
|
||||
if (false == comment->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(comment);
|
||||
if (comment->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
@ -299,15 +299,14 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
}
|
||||
tmpPos+=6;
|
||||
// find text:
|
||||
exml::TextCDATA* text = new exml::TextCDATA();
|
||||
if (NULL == text) {
|
||||
std::shared_ptr<exml::TextCDATA> text = exml::TextCDATA::create();
|
||||
if (text == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = iii+9+white;
|
||||
_filePos += tmpPos;
|
||||
if (false == text->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(text);
|
||||
if (text->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
@ -324,7 +323,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
size_t endPosName = iii+white+1;
|
||||
// generate element name ...
|
||||
for (size_t jjj=iii+white+2; jjj<_data.size(); jjj++) {
|
||||
if(true == checkAvaillable(_data[jjj], false) ) {
|
||||
if(checkAvaillable(_data[jjj], false) == true) {
|
||||
// we find the end ...
|
||||
endPosName = jjj;
|
||||
} else {
|
||||
@ -333,7 +332,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
tmpPos.check(_data[jjj]);
|
||||
}
|
||||
std::string tmpname = std::string(_data, iii+white+2, endPosName+1-(iii+white+2));
|
||||
if (true == _caseSensitive) {
|
||||
if (_caseSensitive == true) {
|
||||
tmpname = etk::tolower(tmpname);
|
||||
}
|
||||
if( tmpname == m_value) {
|
||||
@ -343,7 +342,7 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
|
||||
drawElementParsed(_data[jjj], _filePos);
|
||||
#endif
|
||||
if (true == tmpPos.check(_data[jjj])) {
|
||||
if (tmpPos.check(_data[jjj]) == true) {
|
||||
continue;
|
||||
}
|
||||
if(_data[jjj] == '>') {
|
||||
@ -384,20 +383,19 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
tmpPos.check(_data[jjj]);
|
||||
}
|
||||
std::string tmpname = std::string(_data, iii+white+1, endPosName+1-(iii+white+1));
|
||||
if (true == _caseSensitive) {
|
||||
if (_caseSensitive == true) {
|
||||
etk::tolower(tmpname);
|
||||
}
|
||||
//EXML_INFO("find node named : '" << tmpname << "'");
|
||||
// find text:
|
||||
exml::Element* element = new exml::Element(tmpname);
|
||||
if (NULL == element) {
|
||||
std::shared_ptr<exml::Element> element = exml::Element::create(tmpname);
|
||||
if (element == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = endPosName+1;
|
||||
_filePos += tmpPos;
|
||||
if (false == element->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(element);
|
||||
if (element->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
@ -421,15 +419,14 @@ bool exml::Element::subParse(const std::string& _data, int32_t& _pos, bool _case
|
||||
// empty spaces == > nothing to do ....
|
||||
} else {
|
||||
// find data == > parse it...
|
||||
exml::Text* text = new exml::Text();
|
||||
if (NULL == text) {
|
||||
std::shared_ptr<exml::Text> text = exml::Text::create();
|
||||
if (text == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = iii;
|
||||
_filePos += tmpPos;
|
||||
if (false == text->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(text);
|
||||
if (text->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
@ -474,23 +471,22 @@ bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSe
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find / without > char ...");
|
||||
return false;
|
||||
}
|
||||
if (true == checkAvaillable(_data[iii], true)) {
|
||||
if (checkAvaillable(_data[iii], true) == true) {
|
||||
// we find an attibute == > create a new and parse it :
|
||||
exml::Attribute* attribute = new exml::Attribute();
|
||||
if (NULL == attribute) {
|
||||
std::shared_ptr<exml::Attribute> attribute = exml::Attribute::create();
|
||||
if (attribute == nullptr) {
|
||||
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
|
||||
return false;
|
||||
}
|
||||
_pos = iii;
|
||||
if (false == attribute->iParse(_data, _pos, _caseSensitive, _filePos, _doc)) {
|
||||
delete(attribute);
|
||||
if (attribute->iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
|
||||
return false;
|
||||
}
|
||||
iii = _pos;
|
||||
m_listAttribute.push_back(attribute);
|
||||
continue;
|
||||
}
|
||||
if (false == isWhiteChar(_data[iii])) {
|
||||
if (isWhiteChar(_data[iii]) == false) {
|
||||
CREATE_ERROR(_doc, _data, iii, _filePos, std::string("Find an unknow element : '") + _data[iii] + "'");
|
||||
return false;
|
||||
}
|
||||
@ -501,12 +497,6 @@ bool exml::Element::iParse(const std::string& _data, int32_t& _pos, bool _caseSe
|
||||
|
||||
void exml::Element::clear() {
|
||||
exml::AttributeList::clear();
|
||||
for (size_t iii=0; iii<m_listSub.size(); iii++) {
|
||||
if (NULL!=m_listSub[iii]) {
|
||||
delete(m_listSub[iii]);
|
||||
m_listSub[iii]=NULL;
|
||||
}
|
||||
}
|
||||
m_listSub.clear();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
namespace exml {
|
||||
class Element : public exml::AttributeList {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
@ -28,12 +28,15 @@ namespace exml {
|
||||
exml::AttributeList(_value) {
|
||||
|
||||
};
|
||||
public:
|
||||
static std::shared_ptr<Element> create();
|
||||
static std::shared_ptr<Element> create(const std::string& _value);
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Element();
|
||||
protected:
|
||||
std::vector<exml::Node*> m_listSub;
|
||||
std::vector<std::shared_ptr<exml::Node>> m_listSub;
|
||||
public:
|
||||
/**
|
||||
* @brief get the number of sub element in the node (can be exml::Comment ; exml::Element ; exml::Text :exml::Declaration).
|
||||
@ -46,35 +49,35 @@ namespace exml {
|
||||
* @brief add a node at the element (not exml::Attribute (move in the attribute automaticly).
|
||||
* @param[in] _node Pointer of the node to add.
|
||||
*/
|
||||
void append(Node* _node);
|
||||
void append(const std::shared_ptr<exml::Node>& _node);
|
||||
/**
|
||||
* @brief get the type of the element id.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return the Current type of the element or exml::typeUnknow.
|
||||
*/
|
||||
enum nodeType getType(int32_t _id);
|
||||
enum nodeType getType(int32_t _id);
|
||||
const enum nodeType getType(int32_t _id) const;
|
||||
/**
|
||||
* @brief get the Node pointer of the element id.
|
||||
* @param[in] _id Id of the element.
|
||||
* @return Pointer on node.
|
||||
*/
|
||||
Node* getNode(int32_t _id);
|
||||
const Node* getNode(int32_t _id) const;
|
||||
std::shared_ptr<Node> getNode(int32_t _id);
|
||||
std::shared_ptr<const Node> getNode(int32_t _id) const;
|
||||
/**
|
||||
* @brief get the element casted in Element (if the node is not an element return NULL).
|
||||
* @param[in] _id Id of the element.
|
||||
* @return Pointer on the element or NULL.
|
||||
*/
|
||||
Element* getElement(int32_t _id);
|
||||
const Element* getElement(int32_t _id) const;
|
||||
std::shared_ptr<Element> getElement(int32_t _id);
|
||||
std::shared_ptr<const Element> getElement(int32_t _id) const;
|
||||
/**
|
||||
* @brief get an element with his name (work only with exml::Element)
|
||||
* @param[in] _name Name of the element that is requested
|
||||
* @return Pointer on the element or NULL.
|
||||
*/
|
||||
Element* getNamed(const std::string& _name);
|
||||
const Element* getNamed(const std::string& _name) const;
|
||||
std::shared_ptr<Element> getNamed(const std::string& _name);
|
||||
std::shared_ptr<const Element> getNamed(const std::string& _name) const;
|
||||
/**
|
||||
* @brief get the internal data of the element (if the element has some sub node thay are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
|
||||
* @return the curent data string. if Only one text node, then we get the parssed data (no & ...) if more than one node, then we transform &,",',<,> in xml normal text...
|
||||
@ -88,11 +91,11 @@ namespace exml {
|
||||
};
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual exml::Element* toElement() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Element> toElement() {
|
||||
return std::static_pointer_cast<exml::Element>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Element* toElement() const {
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Element> toElement() const {
|
||||
return std::static_pointer_cast<const exml::Element>(shared_from_this());
|
||||
};
|
||||
virtual void clear();
|
||||
};
|
||||
|
@ -89,7 +89,7 @@ bool exml::Node::checkAvaillable(char32_t _val, bool _firstChar) const {
|
||||
|| _val == '\r') {
|
||||
return false;
|
||||
}
|
||||
if (true == _firstChar) {
|
||||
if (_firstChar == true) {
|
||||
if( _val == '-'
|
||||
|| _val == '.'
|
||||
|| ( _val >= '0'
|
||||
@ -106,7 +106,7 @@ int32_t exml::Node::countWhiteChar(const std::string& _data, int32_t _pos, exml:
|
||||
int32_t white=0;
|
||||
for (size_t iii=_pos; iii<_data.size(); iii++) {
|
||||
_filePos.check(_data[iii]);
|
||||
if(true == isWhiteChar(_data[iii])) {
|
||||
if(isWhiteChar(_data[iii]) == true) {
|
||||
white++;
|
||||
} else {
|
||||
break;
|
||||
|
68
exml/Node.h
68
exml/Node.h
@ -9,7 +9,7 @@
|
||||
#ifndef __ETK_XML_NODE_H__
|
||||
#define __ETK_XML_NODE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <memory>
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
|
||||
@ -118,8 +118,8 @@ namespace exml {
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, const filePos& _obj);
|
||||
|
||||
class Node {
|
||||
public:
|
||||
class Node : public std::enable_shared_from_this<Node>{
|
||||
protected:
|
||||
/**
|
||||
* @brief basic element of a xml structure
|
||||
*/
|
||||
@ -132,6 +132,8 @@ namespace exml {
|
||||
* @param[in] value of the node
|
||||
*/
|
||||
Node(const std::string& _value);
|
||||
public:
|
||||
//static std::shared_ptr<Node> create(const std::string& _value = "");
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
@ -219,63 +221,63 @@ namespace exml {
|
||||
public:
|
||||
/**
|
||||
* @brief Cast the element in a Document if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Document* toDocument() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Document> toDocument() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Document* toDocument() const {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Document> toDocument() const {
|
||||
return nullptr;
|
||||
};
|
||||
/**
|
||||
* @brief Cast the element in a Attribute if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Attribute* toAttribute() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Attribute> toAttribute() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Attribute* toAttribute() const {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Attribute> toAttribute() const {
|
||||
return nullptr;
|
||||
};
|
||||
/**
|
||||
* @brief Cast the element in a Comment if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Comment* toComment() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Comment> toComment() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Comment* toComment() const {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Comment> toComment() const {
|
||||
return nullptr;
|
||||
};
|
||||
/**
|
||||
* @brief Cast the element in a Declaration if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Declaration* toDeclaration() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Declaration> toDeclaration() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Declaration* toDeclaration() const {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Declaration> toDeclaration() const {
|
||||
return nullptr;
|
||||
};
|
||||
/**
|
||||
* @brief Cast the element in a Element if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Element* toElement() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Element> toElement() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Element* toElement() const {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Element> toElement() const {
|
||||
return nullptr;
|
||||
};
|
||||
/**
|
||||
* @brief Cast the element in a Text if it is possible.
|
||||
* @return pointer on the class or NULL.
|
||||
* @return pointer on the class or nullptr.
|
||||
*/
|
||||
virtual exml::Text* toText() {
|
||||
return NULL;
|
||||
virtual std::shared_ptr<exml::Text> toText() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const exml::Text* toText() const{
|
||||
return NULL;
|
||||
virtual std::shared_ptr<const exml::Text> toText() const{
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -63,6 +63,11 @@ static bool isWhiteChar(char32_t _val) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<exml::Text> exml::Text::create() {
|
||||
return std::shared_ptr<exml::Text>(new exml::Text());
|
||||
}
|
||||
|
||||
bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
_data += replaceSpecialCharOut(m_value);
|
||||
return true;
|
||||
@ -94,7 +99,7 @@ bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensi
|
||||
// search whitespace :
|
||||
size_t newEnd=iii;
|
||||
for (int64_t jjj=(int64_t)iii-1; jjj>(int64_t)_pos; --jjj) {
|
||||
if(true == isWhiteChar(_data[jjj])) {
|
||||
if(isWhiteChar(_data[jjj]) == true) {
|
||||
newEnd = jjj;
|
||||
} else {
|
||||
break;
|
||||
@ -113,6 +118,11 @@ bool exml::Text::iParse(const std::string& _data, int32_t& _pos, bool _caseSensi
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<exml::TextCDATA> exml::TextCDATA::create() {
|
||||
return std::shared_ptr<exml::TextCDATA>(new exml::TextCDATA());
|
||||
}
|
||||
|
||||
bool exml::TextCDATA::iGenerate(std::string& _data, int32_t _indent) const {
|
||||
_data += "<![CDATA[" + m_value +"]]>";
|
||||
return true;
|
||||
|
16
exml/Text.h
16
exml/Text.h
@ -14,11 +14,13 @@
|
||||
|
||||
namespace exml {
|
||||
class Text : public exml::Node {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Text() { };
|
||||
public:
|
||||
static std::shared_ptr<Text> create();
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _data String data of the current Text
|
||||
@ -39,19 +41,21 @@ namespace exml {
|
||||
};
|
||||
virtual bool iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
|
||||
virtual bool iGenerate(std::string& _data, int32_t _indent) const;
|
||||
virtual exml::Text* toText() {
|
||||
return this;
|
||||
virtual std::shared_ptr<exml::Text> toText() {
|
||||
return std::static_pointer_cast<exml::Text>(shared_from_this());
|
||||
};
|
||||
virtual const exml::Text* toText() const{
|
||||
return this;
|
||||
virtual std::shared_ptr<const exml::Text> toText() const{
|
||||
return std::static_pointer_cast<const exml::Text>(shared_from_this());
|
||||
};
|
||||
};
|
||||
class TextCDATA : public exml::Text {
|
||||
public:
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TextCDATA() { };
|
||||
public:
|
||||
static std::shared_ptr<TextCDATA> create();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
|
360
exml/test.cpp
360
exml/test.cpp
@ -1,360 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <exml/test.h>
|
||||
#include <exml/debug.h>
|
||||
#include <vector>
|
||||
#include <exml/debug.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "test"
|
||||
|
||||
class testCheck {
|
||||
public:
|
||||
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 set(const std::string& _ref, int32_t _pos, const std::string& _input) {
|
||||
m_ref = _ref;
|
||||
m_input = _input;
|
||||
m_errorPos = _pos;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<testCheck> l_list;
|
||||
|
||||
void init() {
|
||||
std::string reference;
|
||||
std::string input;
|
||||
testCheck check;
|
||||
|
||||
// == ====================================================
|
||||
check.set("test exml::Element", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
reference = "<exemple/>\n";
|
||||
check.set(reference,
|
||||
-1,
|
||||
"<exemple/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"< \t\r exemple/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
-1,
|
||||
"< \t\r exemple \t\r\r\r\n \t\t />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< exemple < >\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< exemple / />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< exemple ? />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< exemple * />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< . exemple < />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"<! exemple < />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"<!- exemple < />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set(reference,
|
||||
1,
|
||||
"< exemple < />\n");
|
||||
l_list.push_back(check);
|
||||
check.set("<exemple--/>\n",
|
||||
1,
|
||||
"<exemple-->\n");
|
||||
l_list.push_back(check);
|
||||
check.set("<exemple/>\n",
|
||||
1,
|
||||
"<exemple>\n</exemple sdfgsdfg>\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test element exml::Attribute ", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=\"plop\"/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=plop/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"234345@3452345_.'\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=234345@3452345_.' />\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr =\"plop\"/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr= \"plop\"/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr\n=\n\"plop\"/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=plop/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"plop\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr \n = \n\t plop/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=\"\"/>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<elementtt attr=\"\"/>\n",
|
||||
-1,
|
||||
"<elementtt attr=/>\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test exml::Declaration", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("<?testDeclaration?>\n",
|
||||
-1,
|
||||
"<?testDeclaration?>\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test Declaration exml::Attribute", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr=\"plop\"?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr=plop?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"234345@3452345_.'\"?>\n",
|
||||
-1,
|
||||
"<?xml attr=234345@3452345_.' ?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr =\"plop\"?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr= \"plop\"?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr\n=\n\"plop\"?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr=plop?>\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<?xml attr=\"plop\"?>\n",
|
||||
-1,
|
||||
"<?xml attr \n = \n\t plop?>\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test exml::Comment", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("<!--exemple-->\n",
|
||||
-1,
|
||||
"<!--exemple-->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!--exemple-->\n",
|
||||
-1,
|
||||
"<!-- \t \t\t exemple \n\n\n\t-->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!---- exemple-->\n",
|
||||
-1,
|
||||
"<!-- -- exemple -->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!--> exemple-->\n",
|
||||
-1,
|
||||
"<!--> exemple -->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!--exemple-->\n",
|
||||
1,
|
||||
"<!-- ---> exemple -->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!--exemple-->\n",
|
||||
1,
|
||||
"<!-- ssdfgdfg >\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!---->\n",
|
||||
-1,
|
||||
"<!---->\n");
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->\n",
|
||||
-1,
|
||||
"<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->\n");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
check.set("test all", -2, "");
|
||||
l_list.push_back(check);
|
||||
// == ====================================================
|
||||
reference= "<exemple>\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
|
||||
" <exlkjl-_dsfg./>\n"
|
||||
" <ex2>Text example ...</ex2>\n"
|
||||
"</exemple>\n";
|
||||
input ="< exemple\n >\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
|
||||
" <exlkjl-_dsfg./>\n"
|
||||
" <ex2>\n"
|
||||
" Text example ...\n"
|
||||
" </ex2>\n"
|
||||
"</exemple>\n";
|
||||
check.set(reference, -1, input);
|
||||
l_list.push_back(check);
|
||||
// ------------------------------------------------------
|
||||
check.set("", 1,
|
||||
"< exemple\n >\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
|
||||
" <exlkjl-_dsfg./> >\n"
|
||||
" <ex2>\n"
|
||||
" Text example ...\n"
|
||||
" </ex2>\n"
|
||||
"</exemple>\n");
|
||||
l_list.push_back(check);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
etk::log::setLevel(etk::log::logLevelVerbose);
|
||||
init();
|
||||
int32_t countError = 0;
|
||||
int32_t countSeparator = 0;
|
||||
int32_t sectionID = 0;
|
||||
for (int32_t iii=0 ; iii<l_list.size() ; iii++) {
|
||||
int32_t jjj= iii-countSeparator+1;
|
||||
if (l_list[iii].m_errorPos == -2) {
|
||||
countSeparator++;
|
||||
sectionID = 0;
|
||||
EXML_INFO("-------------------------------------------------------------");
|
||||
EXML_INFO("-- " << l_list[iii].m_ref);
|
||||
EXML_INFO("-------------------------------------------------------------");
|
||||
continue;
|
||||
}
|
||||
sectionID++;
|
||||
exml::Document doc;
|
||||
std::string out("");
|
||||
//EXML_DEBUG("parse : \n" << l_list[iii].m_input);
|
||||
if (false == doc.parse(l_list[iii].m_input)) {
|
||||
if (l_list[iii].m_errorPos == 1) {
|
||||
EXML_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Parsing in error (correct result)");
|
||||
} else {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be OK");
|
||||
EXML_ERROR("parse : \n" << l_list[iii].m_input);
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 1) {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Parsing might be in error ...");
|
||||
EXML_ERROR("parse : \n" << l_list[iii].m_input);
|
||||
doc.display();
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
if (false == doc.generate(out)) {
|
||||
if (l_list[iii].m_errorPos == 2) {
|
||||
EXML_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } generate in error (correct result)");
|
||||
} else {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } generate output might be OK");
|
||||
EXML_ERROR("generate : \n" << out);
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 2) {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } Generating might be in error ...");
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_ref != out) {
|
||||
if (l_list[iii].m_errorPos == 3) {
|
||||
EXML_INFO("[TEST] " << sectionID << ":" << jjj << " { OK } Result in error (normal case)");
|
||||
} else {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR } different output");
|
||||
EXML_ERROR("generate : \n" << out);
|
||||
EXML_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
countError++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (l_list[iii].m_errorPos == 3) {
|
||||
EXML_ERROR("[TEST] " << sectionID << ":" << jjj << " {ERROR} checking result might be in error...");
|
||||
EXML_ERROR("generate : \n" << out);
|
||||
EXML_ERROR("reference : \n" << l_list[iii].m_ref);
|
||||
countError++;
|
||||
continue;
|
||||
}
|
||||
EXML_INFO("[TEST] " << sectionID << ":" << jjj << " { OK }");
|
||||
}
|
||||
if (countError>0) {
|
||||
EXML_ERROR("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||
} else {
|
||||
EXML_INFO("[TEST] produce " << countError << " error on " << l_list.size()-countSeparator << " test");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
21
exml/test.h
21
exml/test.h
@ -1,21 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __ETK_XML_TEST_H__
|
||||
#define __ETK_XML_TEST_H__
|
||||
|
||||
#include <exml/Node.h>
|
||||
#include <exml/Document.h>
|
||||
|
||||
namespace exml {
|
||||
bool test();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -9,13 +9,13 @@ def get_desc():
|
||||
|
||||
def create(target):
|
||||
# module name is 'edn' and type binary.
|
||||
myModule = module.Module(__file__, 'exmltest', 'BINARY')
|
||||
myModule = module.Module(__file__, 'exml_test', 'BINARY')
|
||||
|
||||
# add the file to compile:
|
||||
myModule.add_src_file([
|
||||
'exml/test.cpp'])
|
||||
'test/main.cpp'])
|
||||
|
||||
myModule.add_module_depend(['exml'])
|
||||
myModule.add_module_depend(['exml', 'gtest'])
|
||||
|
||||
now = datetime.datetime.now()
|
||||
versionID=str(now.year-2012)+"."+str(now.month)+"."+str(now.day)
|
45
test/exmlTestAll.h
Normal file
45
test/exmlTestAll.h
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_ALL_H__
|
||||
#define __EXML_TEST_ALL_H__
|
||||
|
||||
#include "exmlTestCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(TestAll, testBase) {
|
||||
exmlLocalTest( "<exemple>\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
|
||||
" <exlkjl-_dsfg./>\n"
|
||||
" <ex2>Text example ...</ex2>\n"
|
||||
"</exemple>\n",
|
||||
"< exemple\n >\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
|
||||
" <exlkjl-_dsfg./>\n"
|
||||
" <ex2>\n"
|
||||
" Text example ...\n"
|
||||
" </ex2>\n"
|
||||
"</exemple>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAll, testError) {
|
||||
exmlLocalTest( "",
|
||||
"< exemple\n >\n"
|
||||
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
|
||||
" <exlkjl-_dsfg./> >\n"
|
||||
" <ex2>\n"
|
||||
" Text example ...\n"
|
||||
" </ex2>\n"
|
||||
"</exemple>\n",
|
||||
1);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
63
test/exmlTestAttribute.h
Normal file
63
test/exmlTestAttribute.h
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_ATTRIBUTE_H__
|
||||
#define __EXML_TEST_ATTRIBUTE_H__
|
||||
|
||||
#include "exmlTestCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(TestAttribute, testBase) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr=\"plop\"/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testNoQuote) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr=plop/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testNoQuoteNumber) {
|
||||
exmlLocalTest("<elementtt attr=\"234345@3452345_.'\"/>\n",
|
||||
"<elementtt attr=234345@3452345_.' />\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testSpace1) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr =\"plop\"/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testSpace2) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr= \"plop\"/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testMultiline) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr\n=\n\"plop\"/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testMultilineNoQuote) {
|
||||
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
|
||||
"<elementtt attr \n = \n\t plop/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testEmptyAttribute) {
|
||||
exmlLocalTest("<elementtt attr=\"\"/>\n",
|
||||
"<elementtt attr=\"\"/>\n",
|
||||
-1);
|
||||
}
|
||||
TEST(TestAttribute, testEmptyAttributeNoQuote) {
|
||||
exmlLocalTest("<elementtt attr=\"\"/>\n",
|
||||
"<elementtt attr=/>\n",
|
||||
-1);
|
||||
}
|
||||
|
||||
#endif
|
44
test/exmlTestComment.h
Normal file
44
test/exmlTestComment.h
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_COMMENT_H__
|
||||
#define __EXML_TEST_COMMENT_H__
|
||||
|
||||
#include "exmlTestCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(TestComment, testBase) {
|
||||
exmlLocalTest("<!--exemple-->\n", "<!--exemple-->\n", -1);
|
||||
}
|
||||
TEST(TestComment, testMultiline) {
|
||||
exmlLocalTest("<!--exemple-->\n", "<!-- \t \t\t exemple \n\n\n\t-->\n", -1);
|
||||
}
|
||||
TEST(TestComment, testTiretInComment) {
|
||||
exmlLocalTest("<!---- exemple-->\n", "<!-- -- exemple -->\n", -1);
|
||||
}
|
||||
TEST(TestComment, testWrongEndParsing) {
|
||||
exmlLocalTest("<!--> exemple-->\n", "<!--> exemple -->\n", -1);
|
||||
}
|
||||
TEST(TestComment, testMultipleEnd) {
|
||||
exmlLocalTest("<!--exemple-->\n", "<!-- ---> exemple -->\n", 1);
|
||||
}
|
||||
TEST(TestComment, testEndError) {
|
||||
exmlLocalTest("<!--exemple-->\n", "<!-- ssdfgdfg >\n", 1);
|
||||
}
|
||||
TEST(TestComment, testNoCharInComment) {
|
||||
exmlLocalTest("<!---->\n", "<!---->\n", -1);
|
||||
}
|
||||
TEST(TestComment, testAll) {
|
||||
exmlLocalTest("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->\n",
|
||||
"<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->\n",
|
||||
-1);
|
||||
}
|
||||
|
||||
#endif
|
44
test/exmlTestCommon.h
Normal file
44
test/exmlTestCommon.h
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_COMMON_H__
|
||||
#define __EXML_TEST_COMMON_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <exml/debug.h>
|
||||
#include <exml/exml.h>
|
||||
|
||||
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
|
||||
static void exmlLocalTest(const std::string& _ref, const std::string& _input, int32_t _errorPos) {
|
||||
exml::Document doc;
|
||||
//EXML_DEBUG("parse : \n" << l_list[iii].m_input);
|
||||
bool retParse = doc.parse(_input);
|
||||
if (_errorPos == 1) {
|
||||
EXPECT_EQ(retParse, false);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(retParse, true);
|
||||
}
|
||||
std::string out("");
|
||||
bool retGenerate = doc.generate(out);
|
||||
if (_errorPos == 2) {
|
||||
EXPECT_EQ(retGenerate, false);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(retGenerate, true);
|
||||
}
|
||||
if (_errorPos == 3) {
|
||||
EXPECT_NE(_ref, out);
|
||||
return;
|
||||
} else {
|
||||
EXPECT_EQ(_ref, out);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
42
test/exmlTestDeclaration.h
Normal file
42
test/exmlTestDeclaration.h
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_DECLARATION_H__
|
||||
#define __EXML_TEST_DECLARATION_H__
|
||||
|
||||
#include "exmlTestCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
TEST(TestDeclaration, testBase) {
|
||||
exmlLocalTest("<?testDeclaration?>\n", "<?testDeclaration?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testAttribute) {
|
||||
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr=\"plop\"?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testNoQuote) {
|
||||
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr=plop?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testNumberNoQuote) {
|
||||
exmlLocalTest("<?xml attr=\"234345@3452345_.'\"?>\n", "<?xml attr=234345@3452345_.' ?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testSpace1) {
|
||||
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr =\"plop\"?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testSpace2) {
|
||||
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr= \"plop\"?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testMultiline) {
|
||||
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr\n=\n\"plop\"?>\n", -1);
|
||||
}
|
||||
TEST(TestDeclaration, testAll) {
|
||||
exmlLocalTest("<?xml attr=\"p65421lop\"?>\n", "<?xml attr \n = \n\t p65421lop?>\n", -1);
|
||||
}
|
||||
|
||||
#endif
|
60
test/exmlTestElement.h
Normal file
60
test/exmlTestElement.h
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXML_TEST_ELEMENT_H__
|
||||
#define __EXML_TEST_ELEMENT_H__
|
||||
|
||||
#include "exmlTestCommon.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
static std::string refOutputElement("<exemple/>\n");
|
||||
|
||||
TEST(TestElement, testBase) {
|
||||
exmlLocalTest(refOutputElement, "<exemple/>\n", -1);
|
||||
}
|
||||
TEST(TestElement, testMultiline) {
|
||||
exmlLocalTest(refOutputElement, "< \t\r exemple/>\n", -1);
|
||||
}
|
||||
TEST(TestElement, testMultilineMultiTabbed) {
|
||||
exmlLocalTest(refOutputElement, "< \t\r exemple \t\r\r\r\n \t\t />\n", -1);
|
||||
}
|
||||
TEST(TestElement, testWrongStart) {
|
||||
exmlLocalTest(refOutputElement, "< exemple < >\n", 1);
|
||||
}
|
||||
TEST(TestElement, testMultipleSlash) {
|
||||
exmlLocalTest(refOutputElement, "< exemple / />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testExclamationPresence) {
|
||||
exmlLocalTest(refOutputElement, "< exemple ? />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testStarPresence) {
|
||||
exmlLocalTest(refOutputElement, "< exemple * />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testDotPresent) {
|
||||
exmlLocalTest(refOutputElement, "< . exemple < />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testWrong1) {
|
||||
exmlLocalTest(refOutputElement, "<! exemple < />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testWrong2) {
|
||||
exmlLocalTest(refOutputElement, "<!- exemple < />\n", 1);
|
||||
}
|
||||
TEST(TestElement, testWrong3) {
|
||||
exmlLocalTest(refOutputElement, "< exemple < />\n", 1);
|
||||
}
|
||||
|
||||
TEST(TestElement, testBase2) {
|
||||
exmlLocalTest("<exemple--/>\n", "<exemple-->\n", 1);
|
||||
}
|
||||
TEST(TestElement, testBase3) {
|
||||
exmlLocalTest("<exemple/>\n", "<exemple>\n</exemple sdfgsdfg>\n", 1);
|
||||
}
|
||||
|
||||
#endif
|
62
test/main.cpp
Normal file
62
test/main.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2014, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <exml/debug.h>
|
||||
#include <vector>
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
//#include "exmlTestDocument.h"
|
||||
#include "exmlTestElement.h"
|
||||
#include "exmlTestAttribute.h"
|
||||
#include "exmlTestDeclaration.h"
|
||||
#include "exmlTestAll.h"
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "exml::test"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
// init Google test :
|
||||
::testing::InitGoogleTest(&argc, const_cast<char **>(argv));
|
||||
// the only one init for etk:
|
||||
etk::log::setLevel(etk::log::logLevelNone);
|
||||
for (int32_t iii=0; iii<argc ; ++iii) {
|
||||
std::string data = argv[iii];
|
||||
if (data == "-l0") {
|
||||
etk::log::setLevel(etk::log::logLevelNone);
|
||||
} else if (data == "-l1") {
|
||||
etk::log::setLevel(etk::log::logLevelCritical);
|
||||
} else if (data == "-l2") {
|
||||
etk::log::setLevel(etk::log::logLevelError);
|
||||
} else if (data == "-l3") {
|
||||
etk::log::setLevel(etk::log::logLevelWarning);
|
||||
} else if (data == "-l4") {
|
||||
etk::log::setLevel(etk::log::logLevelInfo);
|
||||
} else if (data == "-l5") {
|
||||
etk::log::setLevel(etk::log::logLevelDebug);
|
||||
} else if (data == "-l6") {
|
||||
etk::log::setLevel(etk::log::logLevelVerbose);
|
||||
} else if ( data == "-h"
|
||||
|| data == "--help") {
|
||||
std::cout << "Help : " <<std::endl;
|
||||
std::cout << " ./xxx [options]" <<std::endl;
|
||||
std::cout << " -l0: debug None" <<std::endl;
|
||||
std::cout << " -l1: debug Critical" <<std::endl;
|
||||
std::cout << " -l2: debug Error" <<std::endl;
|
||||
std::cout << " -l3: debug Warning" <<std::endl;
|
||||
std::cout << " -l4: debug Info" <<std::endl;
|
||||
std::cout << " -l5: debug Debug" <<std::endl;
|
||||
std::cout << " -l6: debug Verbose" <<std::endl;
|
||||
std::cout << " -h/--help: this help" <<std::endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
etk::setArgZero(argv[0]);
|
||||
etk::initDefaultFolder("exml_test");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user