[DEV] parsing work corectly

This commit is contained in:
Edouard Dupin 2013-06-21 20:57:08 +02:00
parent 7b5c575bb0
commit e1520b0515
14 changed files with 116 additions and 119 deletions

View File

@ -95,7 +95,7 @@ bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _
return true;
}
bool exml::EXmlAttribute::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlAttribute::Generate(etk::UString& _data, int32_t _indent) const
{
_data += " ";
_data += m_name;

View File

@ -20,14 +20,16 @@ namespace exml
EXmlAttribute(void) { };
EXmlAttribute(const etk::UString& _name, const etk::UString& _value);
virtual ~EXmlAttribute(void) { };
virtual nodeType_te GetType(void) { return exml::typeAttribute; };
virtual nodeType_te GetType(void) const { return exml::typeAttribute; };
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual bool Generate(etk::UString& _data, int32_t _indent);
virtual bool Generate(etk::UString& _data, int32_t _indent) const;
protected:
etk::UString m_name;
public:
virtual void SetName(etk::UString _name) { m_name = _name; };
virtual const etk::UString& GetName(void) { return m_name; };
virtual const etk::UString& GetName(void) const { return m_name; };
virtual operator exml::EXmlAttribute* () { return this; };
virtual operator const exml::EXmlAttribute* () const { return this; };
};
};

View File

@ -35,7 +35,7 @@ bool exml::EXmlComment::Parse(const etk::UString& _data, int32_t& _pos, bool _ca
return false;
}
bool exml::EXmlComment::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlComment::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<!--";

View File

@ -19,9 +19,11 @@ namespace exml
public:
EXmlComment(void) { };
virtual ~EXmlComment(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
virtual nodeType_te GetType(void) const { return typeAttribute; };
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual bool Generate(etk::UString& _data, int32_t _indent);
virtual bool Generate(etk::UString& _data, int32_t _indent) const;
virtual operator exml::EXmlComment* () { return this; };
virtual operator const exml::EXmlComment* () const { return this; };
};
};

View File

@ -9,15 +9,17 @@
#include <exml/EXmlDeclaration.h>
#include <exml/debug.h>
bool exml::EXmlDeclaration::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlDeclaration::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<?";
_data += m_name;
_data += m_value;
/*
if (m_value.Size()!=0) {
_data += " ";
_data += m_value;
}
*/
_data += "?>\n";
return true;
}

View File

@ -19,10 +19,11 @@ namespace exml
public:
EXmlDeclaration(void) { };
virtual ~EXmlDeclaration(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
virtual bool Generate(etk::UString& _data, int32_t _indent);
virtual nodeType_te GetType(void) const { return typeAttribute; };
virtual bool Generate(etk::UString& _data, int32_t _indent) const;
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual operator exml::EXmlDeclaration* () { return this; };
virtual operator const exml::EXmlDeclaration* () const { return this; };
};
};

View File

@ -18,7 +18,7 @@ exml::EXmlDocument::EXmlDocument(void) :
}
bool exml::EXmlDocument::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlDocument::Generate(etk::UString& _data, int32_t _indent) const
{
for (int32_t iii=0; iii<m_listSub.Size(); iii++) {
if (NULL!=m_listSub[iii]) {

View File

@ -20,17 +20,17 @@ namespace exml
public:
EXmlDocument(void);
virtual ~EXmlDocument(void) { };
virtual nodeType_te GetType(void) { return typeDocument; };
virtual nodeType_te GetType(void) const { return typeDocument; };
private:
unicode::charset_te m_charset;
public:
virtual void SetCharset(unicode::charset_te _charset) { m_charset = _charset; };
virtual unicode::charset_te GetCharset(void) { return m_charset; };
virtual unicode::charset_te GetCharset(void) const { return m_charset; };
private:
bool m_caseSensitive;
public:
virtual void SetCaseSensitive(bool _val) { m_caseSensitive = _val; };
virtual bool GetCaseSensitive(void) { return m_caseSensitive; };
virtual bool GetCaseSensitive(void) const { return m_caseSensitive; };
public:
/**
* @brief Parse a string that contain an XML
@ -63,7 +63,9 @@ namespace exml
void Display(void);
bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
bool Generate(etk::UString& _data, int32_t _indent);
bool Generate(etk::UString& _data, int32_t _indent) const;
virtual operator exml::EXmlDocument* () { return this; };
virtual operator const exml::EXmlDocument* () const { return this; };
};
};

View File

@ -22,6 +22,14 @@ exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
return m_listSub[_id];
}
const exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id) const
{
if (_id <0 || _id>m_listSub.Size()) {
return NULL;
}
return m_listSub[_id];
}
void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
{
if (_node == NULL) {
@ -51,8 +59,29 @@ exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name)
}
return NULL;
}
const exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name) const
{
if (_name.Size()==0) {
return NULL;
}
for (int32_t iii=0; iii<m_listSub.Size(); iii++) {
if( NULL != m_listSub[iii]
&& m_listSub[iii]->GetType() == exml::typeElement
&& m_listSub[iii]->GetValue() == _name) {
return m_listSub[iii];
}
}
return NULL;
}
exml::EXmlAttribute* exml::EXmlElement::GetAttribute(int32_t _id)
exml::EXmlAttribute* exml::EXmlElement::GetAttr(int32_t _id)
{
if (_id <0 || _id>m_listAttribute.Size()) {
return NULL;
}
return m_listAttribute[_id];
}
const exml::EXmlAttribute* exml::EXmlElement::GetAttr(int32_t _id) const
{
if (_id <0 || _id>m_listAttribute.Size()) {
return NULL;
@ -74,9 +103,9 @@ void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
m_listAttribute.PushBack(_node);
}
const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name)
const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name) const
{
static const etk::Ustring errorReturn("");
static const etk::UString errorReturn("");
if (_name.Size()==0) {
return errorReturn;
}
@ -89,11 +118,11 @@ const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name)
return errorReturn;
}
bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<";
_data += m_name;
_data += m_value;
for (int32_t iii=0; iii<m_listAttribute.Size(); iii++) {
if (NULL!=m_listAttribute[iii]) {
m_listAttribute[iii]->Generate(_data, _indent);
@ -118,7 +147,7 @@ bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent)
AddIndent(_data, _indent);
}
_data += "</";
_data += m_name;
_data += m_value;
_data += ">\n";
} else {
_data += "/>\n";
@ -255,7 +284,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
}
}
} else {
EXML_ERROR(_filePos << " ==> end node error : '" << tmpname << "' != '" << m_name << "'");
EXML_ERROR(_filePos << " ==> end node error : '" << tmpname << "' != '" << m_value << "'");
return false;
}
}
@ -334,7 +363,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
bool exml::EXmlElement::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'element' named='" << m_name << "'");
EXML_DEBUG("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
// find a normal node ...

View File

@ -21,26 +21,31 @@ namespace exml
EXmlElement(void) { };
EXmlElement(const etk::UString& _value) : exml::EXmlNode(_value) { };
virtual ~EXmlElement(void) { };
virtual nodeType_te GetType(void) { return typeElement; };
virtual nodeType_te GetType(void) const { return typeElement; };
protected:
etk::Vector<exml::EXmlNode*> m_listSub;
public:
int32_t SizeSub(void) const { return m_listSub.Size(); };
EXmlNode* GetSub(int32_t _id);
void AppendSub(EXmlNode* _node);
EXmlNode* GetSub(int32_t _id);
const EXmlNode* GetSub(int32_t _id) const;
EXmlNode* GetNode(const etk::UString& _name);
const EXmlNode* GetNode(const etk::UString& _name) const;
protected:
etk::Vector<exml::EXmlAttribute*> m_listAttribute;
public:
int32_t SizeAttribute(void) const { return m_listSub.Size(); };
EXmlAttribute* GetAttribute(int32_t _id);
void AppendAttribute(EXmlAttribute* _node);
EXmlAttribute* GetAttr(int32_t _id);
const EXmlAttribute* GetAttr(int32_t _id) const;
const etk::UString& GetAttribute(const etk::UString& _name) const;
public:
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual bool Generate(etk::UString& _data, int32_t _indent);
virtual bool Generate(etk::UString& _data, int32_t _indent) const;
protected:
bool SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode=false);
const etk::UString& GetAttribute(const etk::UString& _name);
virtual operator exml::EXmlElement* () { return this; };
virtual operator const exml::EXmlElement* () const { return this; };
};
};

View File

@ -11,19 +11,20 @@
exml::EXmlNode::EXmlNode(const etk::UString& _value) :
m_pos(0,0),
m_value(_value)
{
}
void exml::EXmlNode::AddIndent(etk::UString& _data, int32_t _indent)
void exml::EXmlNode::AddIndent(etk::UString& _data, int32_t _indent) const
{
for (int32_t iii=0; iii<_indent; iii++) {
_data+="\t";
}
}
void exml::EXmlNode::DrawElementParsed(const etk::UniChar& _val, const ivec2& _filePos)
void exml::EXmlNode::DrawElementParsed(const etk::UniChar& _val, const ivec2& _filePos) const
{
if (_val=='\n') {
EXML_DEBUG(_filePos << " Parse '\\n'");
@ -36,7 +37,7 @@ void exml::EXmlNode::DrawElementParsed(const etk::UniChar& _val, const ivec2& _f
// !"#$%&'()*+,/;<=>?@[\]^`{|}~ ou une espace et ne peut pas commencer par -. ou un chiffre.
bool exml::EXmlNode::CheckAvaillable(const etk::UniChar& _val, bool _firstChar)
bool exml::EXmlNode::CheckAvaillable(const etk::UniChar& _val, bool _firstChar) const
{
if( _val == '!'
|| _val == '"'
@ -83,7 +84,7 @@ bool exml::EXmlNode::CheckAvaillable(const etk::UniChar& _val, bool _firstChar)
return true;
}
int32_t exml::EXmlNode::CountWhiteChar(const etk::UString& _data, int32_t _pos)
int32_t exml::EXmlNode::CountWhiteChar(const etk::UString& _data, int32_t _pos) const
{
int32_t white=0;
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
@ -99,62 +100,3 @@ int32_t exml::EXmlNode::CountWhiteChar(const etk::UString& _data, int32_t _pos)
return white;
}
bool IsDocument(void) { return GetType()==exml::typeDocument; };
bool IsAttribute(void) { return GetType()==exml::typeAttribute; };
bool IsComment(void) { return GetType()==exml::typeComment; };
bool IsDeclaration(void) { return GetType()==exml::typeDeclaration; };
bool IsElement(void) { return GetType()==exml::typeElement; };
bool IsText(void) { return GetType()==exml::typeText; };
exml::EXmlDocument* exml::EXmlNode::ToDocument(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::*>(*this);
}
return NULL;
}
exml::EXmlAttribute* exml::EXmlNode::ToAttribute(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::EXmlAttribute*>(*this);
}
return NULL;
}
exml::EXmlComment* exml::EXmlNode::ToComment(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::EXmlComment*>(*this);
}
return NULL;
}
exml::EXmlDeclaration* exml::EXmlNode::ToDeclaration(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::EXmlDeclaration*>(*this);
}
return NULL;
}
exml::EXmlElement* exml::EXmlNode::ToElement(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::EXmlElement*>(*this);
}
return NULL;
}
exml::EXmlText* exml::EXmlNode::ToText(void)
{
if (GetType()==exml::typeDocument) {
return static_cast<exml::EXmlText*>(*this);
}
return NULL;
}

View File

@ -35,42 +35,52 @@ namespace exml
class EXmlNode
{
public:
EXmlNode(void) { };
EXmlNode(void) : m_pos(0,0) { };
EXmlNode(const etk::UString& _value);
virtual ~EXmlNode(void) { };
protected:
void AddIndent(etk::UString& _data, int32_t _indent);
void AddIndent(etk::UString& _data, int32_t _indent) const;
public:
/**
* Parse the sub nodes and current nodes ...
*/
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos) = 0;
virtual bool Generate(etk::UString& _data, int32_t _indent) { return true; };
virtual bool Generate(etk::UString& _data, int32_t _indent) const { return true; };
private:
ivec2 m_pos; // position in the readed file
public:
const ivec2& Pos(void) { return m_pos; };
protected:
etk::UString m_value;
public:
virtual void SetValue(etk::UString _value) { m_value = _value; };
virtual const etk::UString& GetValue(void) { return m_value; };
virtual const etk::UString& GetValue(void) const { return m_value; };
public:
virtual nodeType_te GetType(void) { return typeNode; };
virtual nodeType_te GetType(void) const { return typeNode; };
protected:
void DrawElementParsed(const etk::UniChar& _val, const ivec2& _firstChar);
bool CheckAvaillable(const etk::UniChar& _val, bool _firstChar);
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos);
void DrawElementParsed(const etk::UniChar& _val, const ivec2& _firstChar) const;
bool CheckAvaillable(const etk::UniChar& _val, bool _firstChar) const;
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos) const;
public:
exml::EXmlDocument* ToDocument(void);
exml::EXmlAttribute* ToAttribute(void);
exml::EXmlComment* ToComment(void);
exml::EXmlDeclaration* ToDeclaration(void);
exml::EXmlElement* ToElement(void);
exml::EXmlText* ToText(void);
virtual operator exml::EXmlDocument* () { return NULL; };
virtual operator const exml::EXmlDocument* () const { return NULL; };
virtual operator exml::EXmlAttribute* () { return NULL; };
virtual operator const exml::EXmlAttribute* () const { return NULL; };
virtual operator exml::EXmlComment* () { return NULL; };
virtual operator const exml::EXmlComment* () const { return NULL; };
virtual operator exml::EXmlDeclaration* () { return NULL; };
virtual operator const exml::EXmlDeclaration* () const { return NULL; };
virtual operator exml::EXmlElement* () { return NULL; };
virtual operator const exml::EXmlElement* () const { return NULL; };
virtual operator exml::EXmlText* () { return NULL; };
virtual operator const exml::EXmlText* () const{ return NULL; };
bool IsDocument(void) { return GetType()==exml::typeDocument; };
bool IsAttribute(void) { return GetType()==exml::typeAttribute; };
bool IsComment(void) { return GetType()==exml::typeComment; };
bool IsDeclaration(void) { return GetType()==exml::typeDeclaration; };
bool IsElement(void) { return GetType()==exml::typeElement; };
bool IsText(void) { return GetType()==exml::typeText; };
bool IsDocument(void) const { return GetType()==exml::typeDocument; };
bool IsAttribute(void) const { return GetType()==exml::typeAttribute; };
bool IsComment(void) const { return GetType()==exml::typeComment; };
bool IsDeclaration(void) const { return GetType()==exml::typeDeclaration; };
bool IsElement(void) const { return GetType()==exml::typeElement; };
bool IsText(void) const { return GetType()==exml::typeText; };
};
};

View File

@ -9,13 +9,13 @@
#include <exml/EXmlText.h>
#include <exml/debug.h>
bool exml::EXmlText::Generate(etk::UString& _data, int32_t _indent)
bool exml::EXmlText::Generate(etk::UString& _data, int32_t _indent) const
{
_data += m_value;
return true;
}
int32_t exml::EXmlText::CountLines(void)
int32_t exml::EXmlText::CountLines(void) const
{
int32_t count = 1;
for (int32_t iii=0; iii<m_value.Size(); iii++) {

View File

@ -19,10 +19,12 @@ namespace exml
public:
EXmlText(void) { };
virtual ~EXmlText(void) { };
virtual nodeType_te GetType(void) { return typeText; };
virtual nodeType_te GetType(void) const { return typeText; };
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
virtual bool Generate(etk::UString& _data, int32_t _indent);
int32_t CountLines(void);
virtual bool Generate(etk::UString& _data, int32_t _indent) const;
int32_t CountLines(void) const;
virtual operator exml::EXmlText* () { return this; };
virtual operator const exml::EXmlText* () const { return this; };
};
class EXmlTextCDATA : public EXmlText
{