diff --git a/exml/Attribute.cpp b/exml/Attribute.cpp index 01baf52..62905a0 100644 --- a/exml/Attribute.cpp +++ b/exml/Attribute.cpp @@ -19,18 +19,6 @@ exml::Attribute::Attribute(const std::string& _name, const std::string& _value) } -exml::Attribute::Attribute(const std::u32string& _name, const std::u32string& _value) : - exml::Node(_value) { - m_name = to_u8string(_name); -} - -void exml::Attribute::setName(const std::u32string& _name) { - m_name = to_u8string(_name); -}; - -std::u32string exml::Attribute::getUName(void) const { - return to_u32string(m_name); -}; bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { EXML_VERBOSE("start parse : 'attribute'"); m_pos = _filePos; @@ -49,7 +37,7 @@ bool exml::Attribute::iParse(const std::string& _data, int32_t& _pos, bool _case } m_name = std::string(_data, _pos, lastElementName+1-(_pos)); if (true == _caseSensitive) { - m_name = to_lower(m_name); + m_name = std::tolower(m_name); } // count white space : exml::filePos tmpPos; diff --git a/exml/Attribute.h b/exml/Attribute.h index 65384f0..673da5a 100644 --- a/exml/Attribute.h +++ b/exml/Attribute.h @@ -13,7 +13,7 @@ #include namespace exml { - class Attribute : public Node { + class Attribute : public exml::Node { public: /** * @brief Constructor @@ -25,7 +25,6 @@ namespace exml { * @param[in] _value Value of the attribute. */ Attribute(const std::string& _name, const std::string& _value); - Attribute(const std::u32string& _name, const std::u32string& _value); /** * @brief Destructor */ @@ -40,7 +39,6 @@ namespace exml { virtual void setName(const std::string& _name) { m_name = _name; }; - virtual void setName(const std::u32string& _name); /** * @brief get the current name of the Attribute * @return String of the attribute @@ -48,7 +46,6 @@ namespace exml { virtual const std::string& getName(void) const { return m_name; }; - virtual std::u32string getUName(void) const; public: // herited function: virtual enum nodeType getType(void) const { return exml::typeAttribute; diff --git a/exml/AttributeList.cpp b/exml/AttributeList.cpp index 8e2df6c..ae1245f 100644 --- a/exml/AttributeList.cpp +++ b/exml/AttributeList.cpp @@ -64,19 +64,6 @@ const std::string& exml::AttributeList::getAttribute(const std::string& _name) c return errorReturn; } -std::u32string exml::AttributeList::getAttribute(const std::u32string& _name) const { - static const std::u32string errorReturn(U""); - if (_name.size() == 0) { - return errorReturn; - } - for (size_t iii=0; iiigetUName() == _name) { - return m_listAttribute[iii]->getUValue(); - } - } - return errorReturn; -} bool exml::AttributeList::existAttribute(const std::string& _name) const { if (_name.size() == 0) { @@ -91,19 +78,6 @@ bool exml::AttributeList::existAttribute(const std::string& _name) const { return false; } -bool exml::AttributeList::existAttribute(const std::u32string& _name) const { - if (_name.size() == 0) { - return false; - } - for (size_t iii=0; iiigetUName() == _name) { - return true; - } - } - return false; -} - void exml::AttributeList::setAttribute(const std::string& _name, const std::string& _value) { // check if attribute already det : for (size_t iii=0; iiigetUName() == _name) { - // update the value : - m_listAttribute[iii]->setValue(_value); - return; - } - } - exml::Attribute* attr = new exml::Attribute(_name, _value); - if (NULL == attr) { - EXML_ERROR("memory allocation error..."); - } - m_listAttribute.push_back(attr); -} - bool exml::AttributeList::iGenerate(std::string& _data, int32_t _indent) const { for (size_t iii=0; iii namespace exml { - class AttributeList : public Node { + class AttributeList : public exml::Node { public: /** * @brief Constructor @@ -27,10 +27,6 @@ namespace exml { AttributeList(const std::string& _value) : exml::Node(_value) { - }; - AttributeList(const std::u32string& _value) : - exml::Node(_value) { - }; /** * @brief Destructor @@ -64,21 +60,18 @@ namespace exml { * @return Value of the attribute or no data in the string */ const std::string& getAttribute(const std::string& _name) 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 std::string& _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 std::string& _name, const std::string& _value); - void setAttribute(const std::u32string& _name, const std::u32string& _value); public: // herited function: bool iGenerate(std::string& _data, int32_t _indent) const; virtual void clear(void); diff --git a/exml/Comment.cpp b/exml/Comment.cpp index 0a3dd14..38cf7c5 100644 --- a/exml/Comment.cpp +++ b/exml/Comment.cpp @@ -13,6 +13,19 @@ #undef __class__ #define __class__ "Comment" + +static bool isWhiteChar(char32_t _val) { + if( _val == ' ' + || _val == '\t' + || _val == '\n' + || _val == '\r') { + return true; + } + return false; +} + + + bool exml::Comment::iParse(const std::string& _data, int32_t& _pos, bool _caseSensitive, exml::filePos& _filePos, exml::Document& _doc) { EXML_VERBOSE("start parse : 'comment'"); m_pos = _filePos; @@ -34,7 +47,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 == etk::isWhiteChar(_data[jjj])) { + if(true == isWhiteChar(_data[jjj])) { newEnd = jjj; } else { break; diff --git a/exml/Comment.h b/exml/Comment.h index 55e5796..376ed43 100644 --- a/exml/Comment.h +++ b/exml/Comment.h @@ -13,7 +13,7 @@ #include namespace exml { - class Comment : public Node { + class Comment : public exml::Node { public: /** * @brief Constructor @@ -26,10 +26,6 @@ namespace exml { Comment(const std::string& _value) : exml::Node(_value) { - }; - Comment(const std::u32string& _value) : - exml::Node(_value) { - }; /** * @brief Destructor diff --git a/exml/Declaration.cpp b/exml/Declaration.cpp index a58df81..442152c 100644 --- a/exml/Declaration.cpp +++ b/exml/Declaration.cpp @@ -20,30 +20,12 @@ */ -exml::DeclarationXML::DeclarationXML(const std::string& _version, enum unicode::charset _format, bool _standalone) : +exml::DeclarationXML::DeclarationXML(const std::string& _version, const std::string& _format, bool _standalone) : exml::Declaration("xml") { if (_version.size()!=0) { setAttribute("version", _version); } - if (_format!=unicode::charsetUTF8) { - setAttribute("encoding", "UTF-8"); - } else { - EXML_ERROR("Actually does not supported other charset than UTF8"); - setAttribute("encoding", "UTF-8"); - } - if (_standalone == true) { - setAttribute("standalone", "true"); - } else { - setAttribute("standalone", "true"); - } -} - -exml::DeclarationXML::DeclarationXML(const std::u32string& _version, enum unicode::charset _format, bool _standalone) : - exml::Declaration("xml") { - if (_version.size()!=0) { - setAttribute("version", to_u8string(_version)); - } - if (_format!=unicode::charsetUTF8) { + if (_format!="UTF-8") { setAttribute("encoding", "UTF-8"); } else { EXML_ERROR("Actually does not supported other charset than UTF8"); diff --git a/exml/Declaration.h b/exml/Declaration.h index af20452..5570a57 100644 --- a/exml/Declaration.h +++ b/exml/Declaration.h @@ -10,7 +10,6 @@ #define __ETK_XML_DECLARATION_H__ #include -#include namespace exml { class Declaration : public exml::AttributeList { @@ -26,10 +25,6 @@ namespace exml { Declaration(const std::string& _name) : exml::AttributeList(_name) { - }; - Declaration(const std::u32string& _name) : - exml::AttributeList(_name) { - }; /** * @brief Destructor @@ -56,8 +51,7 @@ namespace exml { * @param[in] _format charset of the XML * @param[in] _standalone this document is standalone */ - DeclarationXML(const std::string& _version, enum unicode::charset _format=unicode::charsetUTF8, bool _standalone=true); - DeclarationXML(const std::u32string& _version, enum unicode::charset _format=unicode::charsetUTF8, bool _standalone=true); + DeclarationXML(const std::string& _version, const std::string& _format = "UTF-8", bool _standalone = true); /** * @brief Destructor */ diff --git a/exml/Document.cpp b/exml/Document.cpp index 3d5a361..87885d5 100644 --- a/exml/Document.cpp +++ b/exml/Document.cpp @@ -14,7 +14,6 @@ #define __class__ "Document" exml::Document::Document(void) : - m_charset(unicode::charsetUTF8), m_caseSensitive(false), m_writeErrorWhenDetexted(true), m_comment(""), @@ -33,34 +32,21 @@ bool exml::Document::iGenerate(std::string& _data, int32_t _indent) const { return true; } -bool exml::Document::parse(const std::u32string& _data) { - return parse(to_u8string(_data)); -} bool exml::Document::parse(const std::string& _data) { EXML_VERBOSE("Start parsing document (type: string) size=" << _data.size()); clear(); // came from char == > force in utf8 ... - m_charset = unicode::charsetUTF8; exml::filePos filePos(1,0); m_pos = filePos; int32_t parsePos = 0; return subParse(_data, parsePos, m_caseSensitive, filePos, *this, true); } -bool exml::Document::generate(std::u32string& _data) { - std::string data; - bool ret = generate(data); - _data = to_u32string(data); - return ret; -} bool exml::Document::generate(std::string& _data) { _data = ""; return iGenerate(_data,0); } -bool exml::Document::load(const std::u32string& _data) { - return load(to_u8string(_data)); -} bool exml::Document::load(const std::string& _file) { // Start loading the XML : EXML_VERBOSE("open file (xml) \"" << _file << "\""); @@ -85,7 +71,6 @@ bool exml::Document::load(const std::string& _file) { EXML_ERROR("Error Memory allocation size=" << fileSize); return false; } - // TODO : change this ... get the charset from the Declaration element ... memset(fileBuffer, 0, (fileSize+5)*sizeof(char)); // load data from the file : tmpFile.fileRead(fileBuffer, 1, fileSize); @@ -102,9 +87,6 @@ bool exml::Document::load(const std::string& _file) { return ret; } -bool exml::Document::store(const std::u32string& _data) { - return store(to_u8string(_data)); -} bool exml::Document::store(const std::string& _file) { std::string createData; if (false == generate(createData)) { diff --git a/exml/Document.h b/exml/Document.h index 9c16ab0..24632db 100644 --- a/exml/Document.h +++ b/exml/Document.h @@ -10,7 +10,6 @@ #define __ETK_XML_DOCUMENT_H__ #include -#include #include namespace exml { @@ -24,23 +23,6 @@ namespace exml { * @brief Destructor */ virtual ~Document(void) { }; - private: - enum unicode::charset m_charset; - public: - /** - * @brief get the current charset of the Parsing - * @param[in] _charset The new charset - */ - virtual void setCharset(enum unicode::charset _charset) { - m_charset = _charset; - }; - /** - * @brief get the current charset of the Parsing - * @return The current charset - */ - virtual enum unicode::charset getCharset(void) const { - return m_charset; - }; private: bool m_caseSensitive; // check the case sensitive of the nodes and attribute public: @@ -66,7 +48,6 @@ namespace exml { * @return true : Parsing is OK */ bool parse(const std::string& _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 @@ -74,7 +55,6 @@ namespace exml { * @return true : Parsing is OK */ bool generate(std::string& _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) @@ -82,7 +62,6 @@ namespace exml { * @return true : Parsing is OK */ bool load(const std::string& _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) @@ -90,7 +69,6 @@ namespace exml { * @return true : Parsing is OK */ bool store(const std::string& _file); - bool store(const std::u32string& _file); /** * @brief Display the Document on console */ diff --git a/exml/Element.cpp b/exml/Element.cpp index de04b9d..8392851 100644 --- a/exml/Element.cpp +++ b/exml/Element.cpp @@ -18,6 +18,16 @@ #define __class__ "Element" +static bool isWhiteChar(char32_t _val) { + if( _val == ' ' + || _val == '\t' + || _val == '\n' + || _val == '\r') { + return true; + } + return false; +} + exml::Element::~Element(void) { for (size_t iii=0; iii namespace exml { - class Element : public AttributeList { + class Element : public exml::AttributeList { public: /** * @brief Constructor @@ -27,10 +27,6 @@ namespace exml { Element(const std::string& _value) : exml::AttributeList(_value) { - }; - Element(const std::u32string& _value) : - exml::AttributeList(_value) { - }; /** * @brief Destructor @@ -79,8 +75,6 @@ namespace exml { */ Element* getNamed(const std::string& _name); const Element* getNamed(const std::string& _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 * @return the curent data string. diff --git a/exml/Node.cpp b/exml/Node.cpp index 2a00a50..4e2c12e 100644 --- a/exml/Node.cpp +++ b/exml/Node.cpp @@ -12,6 +12,15 @@ #undef __class__ #define __class__ "Node" +static bool isWhiteChar(char32_t _val) { + if( _val == ' ' + || _val == '\t' + || _val == '\n' + || _val == '\r') { + return true; + } + return false; +} etk::CCout& exml::operator <<(etk::CCout& _os, const exml::filePos& _obj) { _os << "(l="; @@ -27,10 +36,6 @@ exml::Node::Node(const std::string& _value) : m_value(_value) { // nothing to do. } -exml::Node::Node(const std::u32string& _value) : - m_pos(0,0) { - m_value = to_u8string(_value); -} void exml::Node::addIndent(std::string& _data, int32_t _indent) const { @@ -101,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 == etk::isWhiteChar(_data[iii])) { + if(true == isWhiteChar(_data[iii])) { white++; } else { break; @@ -116,10 +121,3 @@ void exml::Node::clear(void) { m_pos.clear(); } -void exml::Node::setValue(std::u32string _value) { - m_value = to_u8string(_value); -} - -std::u32string exml::Node::getUValue(void) const { - return to_u32string(m_value); -} diff --git a/exml/Node.h b/exml/Node.h index 9d0ef62..bb4f3cd 100644 --- a/exml/Node.h +++ b/exml/Node.h @@ -10,11 +10,10 @@ #define __ETK_XML_NODE_H__ #include -#include +#include #include -namespace exml -{ +namespace exml { //#define ENABLE_DISPLAY_PARSED_ELEMENT //#define ENABLE_CRITICAL_WHEN_ERROR #if 1 @@ -133,7 +132,6 @@ namespace exml * @param[in] value of the node */ Node(const std::string& _value); - Node(const std::u32string& _value); /** * @brief destructor */ @@ -176,7 +174,6 @@ namespace exml virtual void setValue(std::string _value) { m_value = _value; }; - virtual void setValue(std::u32string _value); /** * @brief get the current element Value. * @return the reference of the string value. @@ -184,7 +181,6 @@ namespace exml virtual const std::string& getValue(void) const { return m_value; }; - virtual std::u32string getUValue(void) const; public: /** * @brief get the node type. diff --git a/exml/Text.cpp b/exml/Text.cpp index ed66705..3d17ac1 100644 --- a/exml/Text.cpp +++ b/exml/Text.cpp @@ -13,6 +13,17 @@ #undef __class__ #define __class__ "Text" + +static bool isWhiteChar(char32_t _val) { + if( _val == ' ' + || _val == '\t' + || _val == '\n' + || _val == '\r') { + return true; + } + return false; +} + bool exml::Text::iGenerate(std::string& _data, int32_t _indent) const { _data += m_value; return true; @@ -44,7 +55,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 == etk::isWhiteChar(_data[jjj])) { + if(true == isWhiteChar(_data[jjj])) { newEnd = jjj; } else { break; diff --git a/exml/Text.h b/exml/Text.h index 4d49ea8..8e81d0f 100644 --- a/exml/Text.h +++ b/exml/Text.h @@ -13,7 +13,7 @@ #include namespace exml { - class Text : public Node { + class Text : public exml::Node { public: /** * @brief Constructor @@ -46,7 +46,7 @@ namespace exml { return this; }; }; - class TextCDATA : public Text { + class TextCDATA : public exml::Text { public: /** * @brief Constructor