[DEV] integarate std x11

This commit is contained in:
Edouard DUPIN 2013-11-11 20:19:09 +01:00
parent c9f7abcd96
commit 2325808997
17 changed files with 256 additions and 255 deletions

View File

@ -13,13 +13,13 @@
#undef __class__
#define __class__ "Attribute"
exml::Attribute::Attribute(const etk::UString& _name, const etk::UString& _value) :
exml::Attribute::Attribute(const std::u32string& _name, const std::u32string& _value) :
exml::Node(_value),
m_name(_name) {
}
bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::Attribute::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'attribute'");
m_pos = _filePos;
// search end of the comment :
@ -35,27 +35,27 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
break;
}
}
m_name = _data.extract(_pos, lastElementName+1);
m_name = std::u32string(_data, _pos, lastElementName+1);
if (true == _caseSensitive) {
m_name.lower();
m_name = to_lower(m_name);
}
// count white space :
exml::filePos tmpPos;
int32_t white = countWhiteChar(_data, lastElementName+1, tmpPos);
_filePos += tmpPos;
if (lastElementName+white+1>=_data.size()) {
CREATE_ERROR(_doc, _data, lastElementName+white+1, _filePos, " parse an xml end with an attribute parsing...");
if (lastElementName+white+1 >= _data.size()) {
CREATE_ERROR(_doc, _data, lastElementName+white+1, _filePos, U" parse an xml end with an attribute parsing...");
return false;
}
if (_data[lastElementName+white+1] != '=') {
CREATE_ERROR(_doc, _data, lastElementName+white+1, _filePos, " error attribute parsing == > missing '=' ...");
CREATE_ERROR(_doc, _data, lastElementName+white+1, _filePos, U" error attribute parsing == > missing '=' ...");
return false;
}
white += countWhiteChar(_data, lastElementName+white+2, tmpPos);
_filePos += tmpPos;
if (lastElementName+white+2>=_data.size()) {
CREATE_ERROR(_doc, _data, lastElementName+white+2, _filePos, " parse an xml end with an attribute parsing...");
CREATE_ERROR(_doc, _data, lastElementName+white+2, _filePos, U" parse an xml end with an attribute parsing...");
return false;
}
if (_data[lastElementName+white+2] != '"') {
@ -67,19 +67,19 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
drawElementParsed(_data[iii], _filePos);
#endif
if (_filePos.check(_data[iii]) == true) {
CREATE_ERROR(_doc, _data, iii, _filePos, "unexpected '\\n' in an attribute parsing");
CREATE_ERROR(_doc, _data, iii, _filePos, U"unexpected '\\n' in an attribute parsing");
return false;
}
if( _data[iii]!=' '
&& _data[iii]!='/'
&& _data[iii]!='?'
&& _data[iii]!='>') {
if( _data[iii] != ' '
&& _data[iii] != '/'
&& _data[iii] != '?'
&& _data[iii] != '>') {
lastAttributePos = iii+1;
} else {
break;
}
}
m_value = _data.extract(lastElementName+white+2, lastAttributePos);
m_value = std::u32string(_data, lastElementName+white+2, lastAttributePos);
EXML_PARSE_ATTRIBUTE(m_pos << " attribute : " << m_name << "=\"" << m_value << "\"");
@ -92,13 +92,13 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
drawElementParsed(_data[iii], _filePos);
#endif
_filePos.check(_data[iii]);
if(_data[iii]!='"') {
if(_data[iii] != '"') {
lastAttributePos = iii+1;
} else {
break;
}
}
m_value = _data.extract(lastElementName+white+3, lastAttributePos);
m_value = std::u32string(_data, lastElementName+white+3, lastAttributePos);
EXML_PARSE_ATTRIBUTE(m_pos << " attribute : " << m_name << "=\"" << m_value << "\"");
@ -106,16 +106,16 @@ bool exml::Attribute::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
return true;
}
bool exml::Attribute::iGenerate(etk::UString& _data, int32_t _indent) const {
_data += " ";
bool exml::Attribute::iGenerate(std::u32string& _data, int32_t _indent) const {
_data += U" ";
_data += m_name;
_data += "=\"";
_data += U"=\"";
_data += m_value;
_data += "\"";
_data += U"\"";
return true;
}
void exml::Attribute::clear(void) {
m_name="";
m_name = U"";
}

View File

@ -10,7 +10,7 @@
#define __ETK_XML_ATTRIBUTE_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <vector>
namespace exml {
class Attribute : public Node {
@ -24,34 +24,34 @@ namespace exml {
* @param[in] _name Name of the attribute.
* @param[in] _value Value of the attribute.
*/
Attribute(const etk::UString& _name, const etk::UString& _value);
Attribute(const std::u32string& _name, const std::u32string& _value);
/**
* @brief Destructor
*/
virtual ~Attribute(void) { };
protected:
etk::UString m_name;
std::u32string m_name;
public:
/**
* @brief set the name of the attribute
* @param[in] _name New name of the attribute
*/
virtual void setName(etk::UString _name) {
virtual void setName(std::u32string _name) {
m_name = _name;
};
/**
* @brief get the current name of the Attribute
* @return String of the attribute
*/
virtual const etk::UString& getName(void) const {
virtual const std::u32string& getName(void) const {
return m_name;
};
public: // herited function:
virtual enum nodeType getType(void) const {
return exml::typeAttribute;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual exml::Attribute* toAttribute(void) {
return this;
};

View File

@ -47,11 +47,11 @@ void exml::AttributeList::appendAttribute(exml::Attribute* _attr) {
return;
}
}
m_listAttribute.pushBack(_attr);
m_listAttribute.push_back(_attr);
}
const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name) const {
static const etk::UString errorReturn("");
const std::u32string& exml::AttributeList::getAttribute(const std::u32string& _name) const {
static const std::u32string errorReturn(U"");
if (_name.size() == 0) {
return errorReturn;
}
@ -64,7 +64,7 @@ const etk::UString& exml::AttributeList::getAttribute(const etk::UString& _name)
return errorReturn;
}
bool exml::AttributeList::existAttribute(const etk::UString& _name) const {
bool exml::AttributeList::existAttribute(const std::u32string& _name) const {
if (_name.size() == 0) {
return false;
}
@ -77,7 +77,7 @@ bool exml::AttributeList::existAttribute(const etk::UString& _name) const {
return false;
}
void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::UString& _value) {
void exml::AttributeList::setAttribute(const std::u32string& _name, const std::u32string& _value) {
// check if attribute already det :
for (int32_t iii=0; iii<m_listAttribute.size(); iii++) {
if( NULL != m_listAttribute[iii]
@ -91,10 +91,10 @@ void exml::AttributeList::setAttribute(const etk::UString& _name, const etk::USt
if (NULL == attr) {
EXML_ERROR("memory allocation error...");
}
m_listAttribute.pushBack(attr);
m_listAttribute.push_back(attr);
}
bool exml::AttributeList::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::AttributeList::iGenerate(std::u32string& _data, int32_t _indent) const {
for (int32_t iii=0; iii<m_listAttribute.size(); iii++) {
if (NULL!=m_listAttribute[iii]) {
m_listAttribute[iii]->iGenerate(_data, _indent);

View File

@ -10,7 +10,7 @@
#define __ETK_XML_ATTRIBUTE_LIST_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <vector>
#include <exml/Attribute.h>
namespace exml {
@ -24,7 +24,7 @@ namespace exml {
* @brief Constructor
* @param[in] _value Node value;
*/
AttributeList(const etk::UString& _value) :
AttributeList(const std::u32string& _value) :
exml::Node(_value) {
};
@ -33,7 +33,7 @@ namespace exml {
*/
virtual ~AttributeList(void);
protected:
etk::Vector<exml::Attribute*> m_listAttribute; //!< list of all attribute
std::vector<exml::Attribute*> m_listAttribute; //!< list of all attribute
public:
/**
* @brief get the number of attribute in the Node
@ -59,21 +59,21 @@ namespace exml {
* @param[in] _name Attribute Name.
* @return Value of the attribute or no data in the string
*/
const etk::UString& getAttribute(const etk::UString& _name) const;
const std::u32string& getAttribute(const std::u32string& _name) const;
/**
* @brief check if an attribute exist or not with his name.
* @param[in] _name Attribute Name.
* @return true if the attribute exist or False
*/
bool existAttribute(const etk::UString& _name) const;
bool existAttribute(const std::u32string& _name) const;
/**
* @brief Sen A new attribute or replace data of the previous one
* @param[in] _name Name of the attribute
* @param[in] _value Value of the attribute
*/
void setAttribute(const etk::UString& _name, const etk::UString& _value);
void setAttribute(const std::u32string& _name, const std::u32string& _value);
public: // herited function:
bool iGenerate(etk::UString& _data, int32_t _indent) const;
bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual void clear(void);
};
};

View File

@ -13,7 +13,7 @@
#undef __class__
#define __class__ "Comment"
bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::Comment::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'comment'");
m_pos = _filePos;
exml::filePos tmpPos;
@ -34,28 +34,28 @@ bool exml::Comment::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
// search whitespace :
int32_t newEnd=iii;
for( int32_t jjj=iii-1; jjj>_pos; jjj--) {
if(true == _data[jjj].isWhiteChar()) {
if(true == etk::isWhiteChar(_data[jjj])) {
newEnd = jjj;
} else {
break;
}
}
// find end of value:
m_value = _data.extract(_pos+white, newEnd);
m_value = std::u32string(_data, _pos+white, newEnd);
EXML_VERBOSE(" find comment '" << m_value << "'");
_pos = iii+2;
return true;
}
}
_pos = _data.size();
CREATE_ERROR(_doc, _data, _pos, _filePos, "comment got end of file without finding end node");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"comment got end of file without finding end node");
return false;
}
bool exml::Comment::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::Comment::iGenerate(std::u32string& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<!--";
_data += U"<!--";
_data += m_value;
_data += "-->\n";
_data += U"-->\n";
return true;
}

View File

@ -10,7 +10,7 @@
#define __ETK_XML_COMMENT_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <vector>
namespace exml {
class Comment : public Node {
@ -23,7 +23,7 @@ namespace exml {
* @brief Constructor
* @param[in] _value comment value
*/
Comment(const etk::UString& _value) :
Comment(const std::u32string& _value) :
exml::Node(_value) {
};
@ -35,8 +35,8 @@ namespace exml {
virtual enum nodeType getType(void) const {
return typeAttribute;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual exml::Comment* toComment(void) {
return this;
};

View File

@ -20,34 +20,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
*/
exml::DeclarationXML::DeclarationXML(const etk::UString& _version, enum unicode::charset _format, bool _standalone) :
exml::Declaration("xml") {
exml::DeclarationXML::DeclarationXML(const std::u32string& _version, enum unicode::charset _format, bool _standalone) :
exml::Declaration(U"xml") {
if (_version.size()!=0) {
setAttribute("version", _version);
setAttribute(U"version", _version);
}
if (_format!=unicode::charsetUTF8) {
setAttribute("encoding", "UTF-8");
setAttribute(U"encoding", U"UTF-8");
} else {
EXML_ERROR("Actually does not supported other charset than UTF8");
setAttribute("encoding", "UTF-8");
setAttribute(U"encoding", U"UTF-8");
}
if (_standalone == true) {
setAttribute("standalone", "true");
setAttribute(U"standalone", U"true");
} else {
setAttribute("standalone", "true");
setAttribute(U"standalone", U"true");
}
}
bool exml::Declaration::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::Declaration::iGenerate(std::u32string& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<?";
_data += U"<?";
_data += m_value;
exml::AttributeList::iGenerate(_data, _indent);
_data += "?>\n";
_data += U"?>\n";
return true;
}
bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::Declaration::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'declaration' : '" << m_value << "'");
m_pos = _filePos;
// search end of the comment :
@ -61,7 +61,7 @@ bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _c
if( _data[iii] == '>'
|| _data[iii] == '<') {
// an error occured :
CREATE_ERROR(_doc, _data, _pos, _filePos, " find '>' or '<' instead of '?>'");
CREATE_ERROR(_doc, _data, _pos, _filePos, U" find '>' or '<' instead of '?>'");
return false;
}
if( _data[iii] == '?'
@ -75,7 +75,7 @@ bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _c
// we find an attibute == > create a new and parse it :
exml::Attribute* attribute = new exml::Attribute();
if (NULL == attribute) {
CREATE_ERROR(_doc, _data, _pos, _filePos, " Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U" Allocation error ...");
return false;
}
_pos = iii;
@ -84,11 +84,11 @@ bool exml::Declaration::iParse(const etk::UString& _data, int32_t& _pos, bool _c
return false;
}
iii = _pos;
m_listAttribute.pushBack(attribute);
m_listAttribute.push_back(attribute);
continue;
}
}
CREATE_ERROR(_doc, _data, _pos, _filePos, "Text got end of file without finding end node");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Text got end of file without finding end node");
_pos = _data.size();
return false;
}

View File

@ -10,6 +10,7 @@
#define __ETK_XML_DECLARATION_H__
#include <exml/AttributeList.h>
#include <etk/unicode.h>
namespace exml {
class Declaration : public exml::AttributeList {
@ -22,7 +23,7 @@ namespace exml {
* @brief Constructor
* @param[in] _name name of the declaration (xml, xml:xxxx ...)
*/
Declaration(const etk::UString& _name) :
Declaration(const std::u32string& _name) :
exml::AttributeList(_name) {
};
@ -34,8 +35,8 @@ namespace exml {
virtual enum nodeType getType(void) const {
return typeAttribute;
};
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual exml::Declaration* toDeclaration(void) {
return this;
};
@ -51,7 +52,7 @@ namespace exml {
* @param[in] _format charset of the XML
* @param[in] _standalone this document is standalone
*/
DeclarationXML(const etk::UString& _version, enum unicode::charset _format=unicode::charsetUTF8, bool _standalone=true);
DeclarationXML(const std::u32string& _version, enum unicode::charset _format=unicode::charsetUTF8, bool _standalone=true);
/**
* @brief Destructor
*/

View File

@ -17,14 +17,14 @@ exml::Document::Document(void) :
m_charset(unicode::charsetUTF8),
m_caseSensitive(false),
m_writeErrorWhenDetexted(true),
m_comment(""),
m_Line(""),
m_comment(U""),
m_Line(U""),
m_filePos(0,0) {
}
bool exml::Document::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::Document::iGenerate(std::u32string& _data, int32_t _indent) const {
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if (NULL!=m_listSub[iii]) {
m_listSub[iii]->iGenerate(_data, _indent);
@ -33,7 +33,7 @@ bool exml::Document::iGenerate(etk::UString& _data, int32_t _indent) const {
return true;
}
bool exml::Document::parse(const etk::UString& _data) {
bool exml::Document::parse(const std::u32string& _data) {
EXML_VERBOSE("Start parsing document (type: string) size=" << _data.size());
clear();
// came from char == > force in utf8 ...
@ -44,12 +44,12 @@ bool exml::Document::parse(const etk::UString& _data) {
return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true);
}
bool exml::Document::generate(etk::UString& _data) {
_data = "";
bool exml::Document::generate(std::u32string& _data) {
_data = U"";
return iGenerate(_data,0);
}
bool exml::Document::load(const etk::UString& _file) {
bool exml::Document::load(const std::u32string& _file) {
// Start loading the XML :
EXML_VERBOSE("open file (xml) \"" << _file << "\"");
clear();
@ -81,7 +81,7 @@ bool exml::Document::load(const etk::UString& _file) {
tmpFile.fileClose();
// convert in UTF8 :
etk::UString tmpDataUnicode(fileBuffer, unicode::charsetUTF8);
std::u32string tmpDataUnicode(to_u32string(fileBuffer));
// remove temporary buffer:
delete(fileBuffer);
// parse the data :
@ -90,8 +90,8 @@ bool exml::Document::load(const etk::UString& _file) {
return ret;
}
bool exml::Document::store(const etk::UString& _file) {
etk::UString createData;
bool exml::Document::store(const std::u32string& _file) {
std::u32string createData;
if (false == generate(createData)) {
EXML_ERROR("Error while creating the XML : " << _file);
return false;
@ -101,8 +101,8 @@ bool exml::Document::store(const etk::UString& _file) {
EXML_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()) {
std::string endTable = to_u8string(createData);
if (tmpFile.fileWrite((char*)endTable.c_str(), sizeof(char), endTable.size()) != endTable.size()) {
EXML_ERROR("Error while writing output XML file : " << _file);
tmpFile.fileClose();
return false;
@ -112,25 +112,25 @@ bool exml::Document::store(const etk::UString& _file) {
}
void exml::Document::display(void) {
etk::UString tmpp;
std::u32string tmpp;
iGenerate(tmpp, 0);
EXML_INFO("Generated XML : \n" << tmpp);
}
etk::UString createPosPointer(const etk::UString& _line, int32_t _pos) {
etk::UString out;
std::u32string createPosPointer(const std::u32string& _line, int32_t _pos) {
std::u32string out;
int32_t iii;
for (iii=0; iii<_pos && iii<_line.size(); iii++) {
if (_line[iii] == '\t') {
out += "\t";
out += U"\t";
} else {
out += " ";
out += U" ";
}
}
for (; iii<_pos; iii++) {
out += " ";
out += U" ";
}
out += "^";
out += U"^";
return out;
}
@ -147,9 +147,9 @@ void exml::Document::displayError(void) {
#endif
}
void exml::Document::createError(const etk::UString& _data, int32_t _pos, const exml::filePos& _filePos, const etk::UString& _comment) {
void exml::Document::createError(const std::u32string& _data, int32_t _pos, const exml::filePos& _filePos, const std::u32string& _comment) {
m_comment = _comment;
m_Line = _data.extractLine(_pos);
m_Line = extract_line(_data, _pos);
m_filePos = _filePos;
if (true == m_writeErrorWhenDetexted) {
displayError();

View File

@ -11,7 +11,7 @@
#include <exml/Element.h>
#include <etk/unicode.h>
#include <etk/Vector.h>
#include <vector>
namespace exml {
class Document : public exml::Element {
@ -65,36 +65,36 @@ namespace exml {
* @return false : An error occured
* @return true : Parsing is OK
*/
bool parse(const etk::UString& _data);
bool parse(const std::u32string& _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(etk::UString& _data);
bool generate(std::u32string& _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 etk::UString& _file);
bool load(const std::u32string& _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 etk::UString& _file);
bool store(const std::u32string& _file);
/**
* @brief Display the Document on console
*/
void display(void);
private:
bool m_writeErrorWhenDetexted;
etk::UString m_comment;
etk::UString m_Line;
std::u32string m_comment;
std::u32string m_Line;
exml::filePos m_filePos;
public:
void displayErrorWhenDetected(void) {
@ -104,13 +104,13 @@ namespace exml {
m_writeErrorWhenDetexted = false;
};
void createError(const etk::UString& _data, int32_t _pos, const exml::filePos& _filePos, const etk::UString& _comment);
void createError(const std::u32string& _data, int32_t _pos, const exml::filePos& _filePos, const std::u32string& _comment);
void displayError(void);
public: // herited function:
virtual enum nodeType getType(void) const {
return typeDocument;
};
bool iGenerate(etk::UString& _data, int32_t _indent) const;
bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual exml::Document* toDocument(void) {
return this;
};

View File

@ -74,7 +74,7 @@ const exml::Element* exml::Element::getElement(int32_t _id) const {
return tmpp->toElement();
}
exml::Element* exml::Element::getNamed(const etk::UString& _name) {
exml::Element* exml::Element::getNamed(const std::u32string& _name) {
if (_name.size() == 0) {
return NULL;
}
@ -91,7 +91,7 @@ exml::Element* exml::Element::getNamed(const etk::UString& _name) {
return NULL;
}
const exml::Element* exml::Element::getNamed(const etk::UString& _name) const {
const exml::Element* exml::Element::getNamed(const std::u32string& _name) const {
if (_name.size() == 0) {
return NULL;
}
@ -123,12 +123,12 @@ void exml::Element::append(exml::Node* _node) {
return;
}
}
m_listSub.pushBack(_node);
m_listSub.push_back(_node);
}
etk::UString exml::Element::getText(void) {
std::u32string exml::Element::getText(void) {
// TODO : add more capabilities ...
etk::UString res;
std::u32string res;
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if (NULL!=m_listSub[iii]) {
m_listSub[iii]->iGenerate(res, 0);
@ -137,9 +137,9 @@ etk::UString exml::Element::getText(void) {
return res;
}
bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::Element::iGenerate(std::u32string& _data, int32_t _indent) const {
addIndent(_data, _indent);
_data += "<";
_data += U"<";
_data += m_value;
exml::AttributeList::iGenerate(_data, _indent);
@ -148,10 +148,10 @@ bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const {
&& m_listSub[0] != NULL
&& m_listSub[0]->getType() == exml::typeText
&& static_cast<exml::Text*>(m_listSub[0])->countLines() == 1) {
_data += ">";
_data += U">";
m_listSub[0]->iGenerate(_data,0);
} else {
_data += ">\n";
_data += U">\n";
for (int32_t iii=0; iii<m_listSub.size(); iii++) {
if (NULL!=m_listSub[iii]) {
@ -160,17 +160,17 @@ bool exml::Element::iGenerate(etk::UString& _data, int32_t _indent) const {
}
addIndent(_data, _indent);
}
_data += "</";
_data += U"</";
_data += m_value;
_data += ">\n";
_data += U">\n";
} else {
_data += "/>\n";
_data += U"/>\n";
}
return true;
}
bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode) {
bool exml::Element::subParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode) {
EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos);
for (int32_t iii=_pos; iii<_data.size(); iii++) {
_filePos.check(_data[iii]);
@ -182,14 +182,14 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
int32_t white = countWhiteChar(_data, iii+1, tmpPos);
if (iii+white+1>=_data.size()) {
_filePos+=tmpPos;
CREATE_ERROR(_doc, _data, _pos, _filePos, "End file with '<' char == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"End file with '<' char == > invalide XML");
_pos = iii+white;
return false;
}
// Detect type of the element:
if(_data[iii+white+1] == '>') {
_filePos+=tmpPos;
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find '>' with no element in the element...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find '>' with no element in the element...");
_pos = iii+white+1;
return false;
}
@ -197,7 +197,7 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
++tmpPos;
// TODO : white space ...
if( false == checkAvaillable(_data[iii+white+2], true) ) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find unavaillable name in the Declaration node...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find unavaillable name in the Declaration node...");
_pos = iii+white+1;
return false;
}
@ -213,14 +213,14 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
}
tmpPos.check(_data[jjj]);
}
etk::UString tmpname = _data.extract(iii+white+2, endPosName+1);
std::u32string tmpname = std::u32string(_data, iii+white+2, endPosName+1);
if (true == _caseSensitive) {
tmpname.lower();
tmpname = to_lower(tmpname);
}
// Find declaration balise
exml::Declaration* declaration = new exml::Declaration(tmpname);
if (NULL == declaration) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation Error...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation Error...");
return false;
}
_filePos += tmpPos;
@ -230,31 +230,31 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
iii = _pos;
m_listSub.pushBack(declaration);
m_listSub.push_back(declaration);
continue;
}
if(_data[iii+white+1] == '!') {
++tmpPos;
// Find special block element
if (iii+white+2>=_data.size()) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "End file with '<!' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"End file with '<!' chars == > invalide XML");
return false;
}
if(_data[iii+white+2] == '-') {
++tmpPos;
if (iii+white+3>=_data.size()) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "End file with '<!-' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"End file with '<!-' chars == > invalide XML");
return false;
}
if(_data[iii+white+3] != '-') {
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("Element parse with '<!-") + _data[iii+3] + "' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"Element parse with '<!-") + _data[iii+3] + U"' chars == > invalide XML");
return false;
}
++tmpPos;
// find comment:
exml::Comment* comment = new exml::Comment();
if (NULL == comment) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation error ...");
return false;
}
_pos = iii+white+4;
@ -264,11 +264,11 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
iii = _pos;
m_listSub.pushBack(comment);
m_listSub.push_back(comment);
} else if (_data[iii+white+2] == '[') {
++tmpPos;
if (iii+white+8>=_data.size()) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "End file with '<![' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"End file with '<![' chars == > invalide XML");
return false;
}
if( _data[iii+white+3] != 'C'
@ -277,14 +277,14 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
|| _data[iii+white+6] != 'T'
|| _data[iii+white+7] != 'A'
|| _data[iii+white+8] != '[') {
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("Element parse with '<![") + _data[iii+white+3] + _data[iii+white+4] + _data[iii+white+5] + _data[iii+white+6] + _data[iii+white+7] + _data[iii+white+8] + "' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"Element parse with '<![") + _data[iii+white+3] + _data[iii+white+4] + _data[iii+white+5] + _data[iii+white+6] + _data[iii+white+7] + _data[iii+white+8] + U"' chars == > invalide XML");
return false;
}
tmpPos+=6;
// find text:
exml::TextCDATA* text = new exml::TextCDATA();
if (NULL == text) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation error ...");
return false;
}
_pos = iii+9+white;
@ -294,9 +294,9 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
iii = _pos;
m_listSub.pushBack(text);
m_listSub.push_back(text);
} else {
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("End file with '<!") + _data[iii+white+2] + "' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"End file with '<!") + _data[iii+white+2] + U"' chars == > invalide XML");
return false;
}
@ -316,9 +316,9 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
}
tmpPos.check(_data[jjj]);
}
etk::UString tmpname = _data.extract(iii+white+2, endPosName+1);
std::u32string tmpname = std::u32string(_data, iii+white+2, endPosName+1);
if (true == _caseSensitive) {
tmpname.lower();
tmpname = to_lower(tmpname);
}
if( tmpname == m_value) {
// find end of node :
@ -338,18 +338,18 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
&& _data[jjj] != ' '
&& _data[jjj] != '\t') {
_filePos += tmpPos;
CREATE_ERROR(_doc, _data, jjj, _filePos, etk::UString("End node error : have data inside end node other than [ \\n\\t\\r] ") + m_value + "'");
CREATE_ERROR(_doc, _data, jjj, _filePos, std::u32string(U"End node error : have data inside end node other than [ \\n\\t\\r] ") + m_value + U"'");
return false;
}
}
} else {
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("End node error : '") + tmpname + "' != '" + m_value + "'");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"End node error : '") + tmpname + U"' != '" + m_value + U"'");
return false;
}
}
if (_data[iii+white+1] == '>') {
// end of something == > this is really bad
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find '>' chars == > invalide XML");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find '>' chars == > invalide XML");
return false;
}
@ -367,15 +367,15 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
}
tmpPos.check(_data[jjj]);
}
etk::UString tmpname = _data.extract(iii+white+1, endPosName+1);
std::u32string tmpname = std::u32string(_data, iii+white+1, endPosName+1);
if (true == _caseSensitive) {
tmpname.lower();
to_lower(tmpname);
}
//EXML_INFO("find node named : '" << tmpname << "'");
// find text:
exml::Element* element = new exml::Element(tmpname);
if (NULL == element) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation error ...");
return false;
}
_pos = endPosName+1;
@ -385,16 +385,16 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
iii = _pos;
m_listSub.pushBack(element);
m_listSub.push_back(element);
continue;
}
_filePos+=tmpPos;
// here we have an error :
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("Find an ununderstanding element : '") + _data[iii+white+1] + "'");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"Find an ununderstanding element : '") + _data[iii+white+1] + U"'");
return false;
} else {
if (_data[iii] == '>') {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find elemement '>' == > no reason to be here ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find elemement '>' == > no reason to be here ...");
return false;
}
// might to be data text ...
@ -407,7 +407,7 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
// find data == > parse it...
exml::Text* text = new exml::Text();
if (NULL == text) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation error ...");
return false;
}
_pos = iii;
@ -417,18 +417,18 @@ bool exml::Element::subParse(const etk::UString& _data, int32_t& _pos, bool _cas
return false;
}
iii = _pos;
m_listSub.pushBack(text);
m_listSub.push_back(text);
}
}
}
if (_mainNode == true) {
return true;
}
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("Did not find end of the exml::Element : '") + m_value + "'");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"Did not find end of the exml::Element : '") + m_value + U"'");
return false;
}
bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::Element::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_PARSE_ELEMENT("start parse : 'element' named='" << m_value << "'");
// note : When start parsing the upper element must have set the value of the element and set the position after this one
m_pos=_filePos;
@ -446,7 +446,7 @@ bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
if (_data[iii] == '/') {
// standalone node or error...
if (iii+1>=_data.size()) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find end of files ... == > bad case");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find end of files ... == > bad case");
return false;
}
// TODO : Can have white spaces ....
@ -455,14 +455,14 @@ bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
return true;
}
// error
CREATE_ERROR(_doc, _data, _pos, _filePos, "Find / without > char ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Find / without > char ...");
return false;
}
if (true == checkAvaillable(_data[iii], true)) {
// we find an attibute == > create a new and parse it :
exml::Attribute* attribute = new exml::Attribute();
if (NULL == attribute) {
CREATE_ERROR(_doc, _data, _pos, _filePos, "Allocation error ...");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Allocation error ...");
return false;
}
_pos = iii;
@ -471,15 +471,15 @@ bool exml::Element::iParse(const etk::UString& _data, int32_t& _pos, bool _caseS
return false;
}
iii = _pos;
m_listAttribute.pushBack(attribute);
m_listAttribute.push_back(attribute);
continue;
}
if (false == _data[iii].isWhiteChar()) {
CREATE_ERROR(_doc, _data, iii, _filePos, etk::UString("Find an unknow element : '") + _data[iii] + "'");
if (false == etk::isWhiteChar(_data[iii])) {
CREATE_ERROR(_doc, _data, iii, _filePos, std::u32string(U"Find an unknow element : '") + _data[iii] + U"'");
return false;
}
}
CREATE_ERROR(_doc, _data, _pos, _filePos, etk::UString("Unexpecting end of parsing exml::Element : '") + m_value + "' == > check if the '/>' is set or the end of element");
CREATE_ERROR(_doc, _data, _pos, _filePos, std::u32string(U"Unexpecting end of parsing exml::Element : '") + m_value + U"' == > check if the '/>' is set or the end of element");
return false;
}

View File

@ -10,7 +10,7 @@
#define __ETK_XML_ELEMENT_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <vector>
#include <exml/AttributeList.h>
namespace exml {
@ -24,7 +24,7 @@ namespace exml {
* @brief Constructor
* @param[in] _value Element name;
*/
Element(const etk::UString& _value) :
Element(const std::u32string& _value) :
exml::AttributeList(_value) {
};
@ -33,7 +33,7 @@ namespace exml {
*/
virtual ~Element(void);
protected:
etk::Vector<exml::Node*> m_listSub;
std::vector<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).
@ -73,21 +73,21 @@ namespace exml {
* @param[in] _name Name of the element that is requested
* @return Pointer on the element or NULL.
*/
Element* getNamed(const etk::UString& _name);
const Element* getNamed(const etk::UString& _name) const;
Element* getNamed(const std::u32string& _name);
const Element* getNamed(const std::u32string& _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.
*/
etk::UString getText(void);
std::u32string getText(void);
protected:
bool subParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode=false);
bool subParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc, bool _mainNode=false);
public: // herited function:
virtual enum nodeType getType(void) const {
return typeElement;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual exml::Element* toElement(void) {
return this;
};

View File

@ -14,27 +14,27 @@
etk::CCout& exml::operator <<(etk::CCout& _os, const exml::filePos& _obj) {
_os << "(l=";
_os << U"(l=";
_os << _obj.getLine();
_os << ",c=";
_os << U",c=";
_os << _obj.getCol();
_os << ")";
_os << U")";
return _os;
}
exml::Node::Node(const etk::UString& _value) :
exml::Node::Node(const std::u32string& _value) :
m_pos(0,0),
m_value(_value) {
// nothing to do.
}
void exml::Node::addIndent(etk::UString& _data, int32_t _indent) const {
void exml::Node::addIndent(std::u32string& _data, int32_t _indent) const {
for (int32_t iii=0; iii<_indent; iii++) {
_data+="\t";
_data += U"\t";
}
}
void exml::Node::drawElementParsed(const etk::UChar& _val, const exml::filePos& _filePos) const {
void exml::Node::drawElementParsed(char32_t _val, const exml::filePos& _filePos) const {
if (_val == '\n') {
EXML_DEBUG(_filePos << " parse '\\n'");
} else if (_val == '\t') {
@ -44,7 +44,7 @@ void exml::Node::drawElementParsed(const etk::UChar& _val, const exml::filePos&
}
}
bool exml::Node::checkAvaillable(const etk::UChar& _val, bool _firstChar) const {
bool exml::Node::checkAvaillable(char32_t _val, bool _firstChar) const {
if( _val == '!'
|| _val == '"'
|| _val == '#'
@ -91,12 +91,12 @@ bool exml::Node::checkAvaillable(const etk::UChar& _val, bool _firstChar) const
}
int32_t exml::Node::countWhiteChar(const etk::UString& _data, int32_t _pos, exml::filePos& _filePos) const {
int32_t exml::Node::countWhiteChar(const std::u32string& _data, int32_t _pos, exml::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;
@ -107,6 +107,6 @@ int32_t exml::Node::countWhiteChar(const etk::UString& _data, int32_t _pos, exml
}
void exml::Node::clear(void) {
m_value="";
m_value = U"";
m_pos.clear();
}

View File

@ -94,7 +94,7 @@ namespace exml
m_col=0;
m_line++;
};
bool check(const etk::UChar& _val) {
bool check(char32_t _val) {
m_col++;
if (_val == '\n') {
newLine();
@ -132,7 +132,7 @@ namespace exml
* @brief basic element of a xml structure
* @param[in] value of the node
*/
Node(const etk::UString& _value);
Node(const std::u32string& _value);
/**
* @brief destructor
*/
@ -146,14 +146,14 @@ namespace exml
* @param[in,out] file parsing position (line x col x)
* @return false if an error occured.
*/
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) = 0;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::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(etk::UString& _data, int32_t _indent) const {
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const {
return true;
};
protected:
@ -166,20 +166,20 @@ namespace exml
return m_pos;
};
protected:
etk::UString m_value; //!< value of the node (for element this is the name, for text it is the inside text ...)
std::u32string 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.
*/
virtual void setValue(etk::UString _value) {
virtual void setValue(std::u32string _value) {
m_value = _value;
};
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
virtual const etk::UString& getValue(void) const {
virtual const std::u32string& getValue(void) const {
return m_value;
};
public:
@ -196,19 +196,19 @@ namespace exml
* @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string.
*/
void addIndent(etk::UString& _data, int32_t _indent) const;
void addIndent(std::u32string& _data, int32_t _indent) const;
/**
* @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed.
* @param[in] _filePos Position of the char in the file.
*/
void drawElementParsed(const etk::UChar& _val, const exml::filePos& _filePos) const;
void drawElementParsed(char32_t _val, const exml::filePos& _filePos) const;
/**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \n\t\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity.
* @param[in] _firstChar True if the element check is the first char.
*/
bool checkAvaillable(const etk::UChar& _val, bool _firstChar) const;
bool checkAvaillable(char32_t _val, bool _firstChar) const;
/**
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
* @param[in] _data Data to parse.
@ -216,7 +216,7 @@ namespace exml
* @param[out] _filePos new poistion of te file to add.
* @return number of white element.
*/
int32_t countWhiteChar(const etk::UString& _data, int32_t _pos, exml::filePos& _filePos) const;
int32_t countWhiteChar(const std::u32string& _data, int32_t _pos, exml::filePos& _filePos) const;
public:
/**
* @brief Cast the element in a Document if it is possible.

View File

@ -13,7 +13,7 @@
#undef __class__
#define __class__ "Text"
bool exml::Text::iGenerate(etk::UString& _data, int32_t _indent) const {
bool exml::Text::iGenerate(std::u32string& _data, int32_t _indent) const {
_data += m_value;
return true;
}
@ -28,7 +28,7 @@ int32_t exml::Text::countLines(void) const {
return count;
}
bool exml::Text::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::Text::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'text'");
m_pos = _filePos;
// search end of the comment :
@ -44,25 +44,25 @@ bool exml::Text::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSens
// search whitespace :
int32_t newEnd=iii;
for( int32_t jjj=iii-1; jjj>_pos; jjj--) {
if(true == _data[jjj].isWhiteChar()) {
if(true == etk::isWhiteChar(_data[jjj])) {
newEnd = jjj;
} else {
break;
}
}
// find end of value:
m_value = _data.extract(_pos, newEnd);
m_value = std::u32string(_data, _pos, newEnd);
EXML_VERBOSE(" find text '" << m_value << "'");
_pos = iii-1;
return true;
}
}
CREATE_ERROR(_doc, _data, _pos, _filePos, "Text got end of file without finding end node");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"Text got end of file without finding end node");
_pos = _data.size();
return false;
}
bool exml::TextCDATA::iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
bool exml::TextCDATA::iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) {
EXML_VERBOSE("start parse : 'text::CDATA'");
m_pos = _filePos;
// search end of the comment :
@ -78,13 +78,13 @@ bool exml::TextCDATA::iParse(const etk::UString& _data, int32_t& _pos, bool _cas
&& _data[iii+2] == '>') {
// find end of value:
_filePos += 2;
m_value = _data.extract(_pos, iii);
m_value = std::u32string(_data, _pos, iii);
EXML_VERBOSE(" find text CDATA '" << m_value << "'");
_pos = iii+2;
return true;
}
}
CREATE_ERROR(_doc, _data, _pos, _filePos, "text CDATA got end of file without finding end node");
CREATE_ERROR(_doc, _data, _pos, _filePos, U"text CDATA got end of file without finding end node");
_pos = _data.size();
return false;
}

View File

@ -10,7 +10,7 @@
#define __ETK_XML_TEXT_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <vector>
namespace exml {
class Text : public Node {
@ -23,7 +23,7 @@ namespace exml {
* @brief Constructor
* @param[in] _data String data of the current Text
*/
Text(const etk::UString& _data) : exml::Node(_data) { };
Text(const std::u32string& _data) : exml::Node(_data) { };
/**
* @brief Destructor
*/
@ -37,8 +37,8 @@ namespace exml {
virtual enum nodeType getType(void) const {
return typeText;
};
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(etk::UString& _data, int32_t _indent) const;
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iGenerate(std::u32string& _data, int32_t _indent) const;
virtual exml::Text* toText(void) {
return this;
};
@ -57,7 +57,7 @@ namespace exml {
*/
virtual ~TextCDATA(void) { };
public: // herited function:
virtual bool iParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
virtual bool iParse(const std::u32string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc);
};
};

View File

@ -8,7 +8,7 @@
#include <exml/test.h>
#include <exml/debug.h>
#include <etk/Vector.h>
#include <vector>
#include <exml/debug.h>
#undef __class__
@ -16,241 +16,241 @@
class testCheck {
public:
etk::UString m_ref;
etk::UString m_input;
std::u32string m_ref;
std::u32string m_input;
int32_t m_errorPos; // -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
testCheck(void) {};
void set(const etk::UString& _ref, int32_t _pos, const etk::UString& _input) {
void set(const std::u32string& _ref, int32_t _pos, const std::u32string& _input) {
m_ref = _ref;
m_input = _input;
m_errorPos = _pos;
}
};
etk::Vector<testCheck> l_list;
std::vector<testCheck> l_list;
void init(void) {
etk::UString reference;
etk::UString input;
std::u32string reference;
std::u32string input;
testCheck check;
// == ====================================================
check.set("test exml::Element", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
reference = "<exemple/>\n";
check.set(reference,
-1,
"<exemple/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
-1,
"< \t\r exemple/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
-1,
"< \t\r exemple \t\r\r\r\n \t\t />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< exemple < >\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< exemple / />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< exemple ? />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< exemple * />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< . exemple < />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"<! exemple < />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"<!- exemple < />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set(reference,
1,
"< exemple < />\n");
l_list.pushBack(check);
l_list.push_back(check);
check.set("<exemple--/>\n",
1,
"<exemple-->\n");
l_list.pushBack(check);
l_list.push_back(check);
check.set("<exemple/>\n",
1,
"<exemple>\n</exemple sdfgsdfg>\n");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("test element exml::Attribute ", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr=\"plop\"/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr=plop/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"234345@3452345_.'\"/>\n",
-1,
"<elementtt attr=234345@3452345_.' />\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr =\"plop\"/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr= \"plop\"/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr\n=\n\"plop\"/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr=plop/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"plop\"/>\n",
-1,
"<elementtt attr \n = \n\t plop/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"\"/>\n",
-1,
"<elementtt attr=\"\"/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<elementtt attr=\"\"/>\n",
-1,
"<elementtt attr=/>\n");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("test exml::Declaration", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("<?testDeclaration?>\n",
-1,
"<?testDeclaration?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("test Declaration exml::Attribute", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr=\"plop\"?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr=plop?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"234345@3452345_.'\"?>\n",
-1,
"<?xml attr=234345@3452345_.' ?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr =\"plop\"?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr= \"plop\"?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr\n=\n\"plop\"?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr=plop?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<?xml attr=\"plop\"?>\n",
-1,
"<?xml attr \n = \n\t plop?>\n");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("test exml::Comment", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("<!--exemple-->\n",
-1,
"<!--exemple-->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!--exemple-->\n",
-1,
"<!-- \t \t\t exemple \n\n\n\t-->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!---- exemple-->\n",
-1,
"<!-- -- exemple -->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!--> exemple-->\n",
-1,
"<!--> exemple -->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!--exemple-->\n",
1,
"<!-- ---> exemple -->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!--exemple-->\n",
1,
"<!-- ssdfgdfg >\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!---->\n",
-1,
"<!---->\n");
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->\n",
-1,
"<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->\n");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
check.set("test all", -2, "");
l_list.pushBack(check);
l_list.push_back(check);
// == ====================================================
reference= "<exemple>\n"
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
@ -265,7 +265,7 @@ void init(void) {
" </ex2>\n"
"</exemple>\n";
check.set(reference, -1, input);
l_list.pushBack(check);
l_list.push_back(check);
// ------------------------------------------------------
check.set("", 1,
"< exemple\n >\n"
@ -275,11 +275,11 @@ void init(void) {
" Text example ...\n"
" </ex2>\n"
"</exemple>\n");
l_list.pushBack(check);
l_list.push_back(check);
}
int main(int argc, const char *argv[]) {
debug::setGeneralLevel(etk::LOG_LEVEL_VERBOSE);
debug::setGeneralLevel(etk::logLevelVerbose);
init();
int32_t countError = 0;
int32_t countSeparator = 0;
@ -296,7 +296,7 @@ int main(int argc, const char *argv[]) {
}
sectionID++;
exml::Document doc;
etk::UString out("");
std::u32string 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) {