[DEV] better parse function and compile

This commit is contained in:
Edouard Dupin 2013-06-20 07:51:48 +02:00
parent 5167ae2332
commit 4600e688b4
5 changed files with 41 additions and 29 deletions

View File

@ -14,12 +14,12 @@
namespace exml namespace exml
{ {
class EXmlElement : public EXmlNode class EXmlAttribute : public EXmlNode
{ {
public: public:
EXmlElement(void) { }; EXmlAttribute(void) { };
virtual ~EXmlElement(void) { }; virtual ~EXmlAttribute(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; }; virtual nodeType_te GetType(void) { return exml::typeAttribute; };
}; };
}; };

View File

@ -10,32 +10,32 @@
exml::EXmlDocument::EXmlDocument(void) : exml::EXmlDocument::EXmlDocument(void) :
m_charset(unicode::EDN_CHARSET_UNKNOW), m_charset(unicode::EDN_CHARSET_UTF8),
m_caseSensitive(false) m_caseSensitive(false)
{ {
} }
bool Parse(const etk::UString& _data) bool exml::EXmlDocument::Parse(const etk::UString& _data)
{ {
// came from char ==> force in utf8 ... // came from char ==> force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8; m_charset = unicode::EDN_CHARSET_UTF8;
ivec2 filePos(1,1); ivec2 filePos(1,1);
int32_t ret = Parse(_data, 0, m_caseSensitive, filePos); int32_t ret = exml::EXmlElement::Parse(_data, 0, m_caseSensitive, filePos);
return false; return false;
} }
bool Generate(etk::UString& _data) bool exml::EXmlDocument::Generate(etk::UString& _data)
{ {
return false; return false;
} }
bool Load(const etk::UString& _file) bool exml::EXmlDocument::Load(const etk::UString& _file)
{ {
return false; return false;
} }
bool Store(const etk::UString& _file) bool exml::EXmlDocument::Store(const etk::UString& _file)
{ {
return false; return false;
} }

View File

@ -7,9 +7,10 @@
*/ */
#include <exml/EXmlElement.h> #include <exml/EXmlElement.h>
#include <exml/debug.h>
EXmlNode* exml::EXmlElement::GetSub(int32_t _id) exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
{ {
if (_id <0 || _id>m_listSub.Size()) { if (_id <0 || _id>m_listSub.Size()) {
return NULL; return NULL;
@ -17,7 +18,7 @@ EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
return m_listSub[_id]; return m_listSub[_id];
} }
void exml::EXmlElement::AppendSub(EXmlNode* _node) void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
{ {
if (_node == NULL) { if (_node == NULL) {
EXML_ERROR("Try to set an empty node"); EXML_ERROR("Try to set an empty node");
@ -32,14 +33,14 @@ void exml::EXmlElement::AppendSub(EXmlNode* _node)
m_listSub.PushBack(_node); m_listSub.PushBack(_node);
} }
EXmlAttribute* exml::EXmlElement::GetAttribute(int32_t _id) exml::EXmlAttribute* exml::EXmlElement::GetAttribute(int32_t _id)
{ {
if (_id <0 || _id>m_listAttribute.Size()) { if (_id <0 || _id>m_listAttribute.Size()) {
return NULL; return NULL;
} }
return m_listAttribute[_id]; return m_listAttribute[_id];
} }
void exml::EXmlElement::AppendAttribute(EXmlAttribute* _node) void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
{ {
if (_node == NULL) { if (_node == NULL) {
EXML_ERROR("Try to set an empty node"); EXML_ERROR("Try to set an empty node");
@ -54,25 +55,25 @@ void exml::EXmlElement::AppendAttribute(EXmlAttribute* _node)
m_listAttribute.PushBack(_node); m_listAttribute.PushBack(_node);
} }
int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos) bool exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos, int32_t& findLen)
{ {
for (int32_t iii=_pos; iii<_data.Size(); iii++) { for (int32_t iii=_pos; iii<_data.Size(); iii++) {
if (_data[iii] == "<") { if (_data[iii] == '<') {
if (iii+1>=_data.Size()) { if (iii+1>=_data.Size()) {
// TODO : an error occured ... // TODO : an error occured ...
return; return iii;
} }
// find the end of the balise : // find the end of the balise :
int32_t endPos = iii; int32_t endPos = iii;
for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) { for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) {
if(_data[jjj] == ">") { if(_data[jjj] == '>') {
endPos = jjj; endPos = jjj;
break; break;
} }
} }
if (endPos == iii) { if (endPos == iii) {
// TODO : an error occured ... // TODO : an error occured ...
return; return iii;
} }
int32_t sizeElement = endPos-iii; int32_t sizeElement = endPos-iii;
if( sizeElement>2 if( sizeElement>2
@ -82,7 +83,7 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
// TODO : ... // TODO : ...
iii = endPos iii = endPos;
continue; continue;
} }
if( sizeElement>5 if( sizeElement>5
@ -97,13 +98,13 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
// TODO : ... // TODO : ...
iii = endPos iii = endPos;
continue; continue;
} }
// find a normal node ... // find a normal node ...
// TODO : ... // TODO : ...
for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) { for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) {
if(_data[jjj] == ">") { if(_data[jjj] == '>') {
// we find the end ... // we find the end ...
iii = jjj; iii = jjj;
break; break;
@ -111,13 +112,20 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
} }
} else { } else {
// might to be data text ... // might to be data text ...
if( _data[iii] == ' '
&& _data[iii] == '\t'
&& _data[iii] == '\n'
&& _data[iii] == '\r') {
// empty spaces ==> nothing to do ....
} else {
// find data ==> parse it...
}
} }
} }
return _pos;
} }
#endif

View File

@ -11,6 +11,7 @@
#include <exml/EXmlNode.h> #include <exml/EXmlNode.h>
#include <etk/Vector.h> #include <etk/Vector.h>
#include <exml/EXmlAttribute.h>
namespace exml namespace exml
{ {
@ -32,8 +33,8 @@ namespace exml
int32_t SizeAttribute(void) const { return m_listSub.Size(); }; int32_t SizeAttribute(void) const { return m_listSub.Size(); };
EXmlAttribute* GetAttribute(int32_t _id); EXmlAttribute* GetAttribute(int32_t _id);
void AppendAttribute(EXmlAttribute* _node); void AppendAttribute(EXmlAttribute* _node);
protected: public:
virtual int32_t Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos); virtual bool Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos, int32_t& findLen);
}; };
}; };

View File

@ -11,6 +11,7 @@
#include <etk/types.h> #include <etk/types.h>
#include <etk/UString.h> #include <etk/UString.h>
#include <etk/math/Vector2D.h>
namespace exml namespace exml
{ {
@ -18,7 +19,7 @@ namespace exml
typeNode, //!< might be an error ... typeNode, //!< might be an error ...
typeDocument, //!< all the file main access typeDocument, //!< all the file main access
typeDeclaration, //!< <?xml ... ?> typeDeclaration, //!< <?xml ... ?>
typeAttibute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" /> typeAttribute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" />
typeElement, //!< the <XXX> ... </XXX> typeElement, //!< the <XXX> ... </XXX>
typeComment, //!< comment node : <!-- --> typeComment, //!< comment node : <!-- -->
typeText, //!< <XXX> InsideText </XXX> typeText, //!< <XXX> InsideText </XXX>
@ -29,11 +30,11 @@ namespace exml
public: public:
EXmlNode(void) { }; EXmlNode(void) { };
virtual ~EXmlNode(void) { }; virtual ~EXmlNode(void) { };
protected: public:
/** /**
* Parse the sub nodes and current nodes ... * Parse the sub nodes and current nodes ...
*/ */
virtual int32_t Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos) = 0; virtual bool Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos, int32_t& findLen) = 0;
protected: protected:
etk::UString m_name; etk::UString m_name;
public: public:
@ -49,3 +50,5 @@ namespace exml
}; };
}; };
#endif