[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
{
class EXmlElement : public EXmlNode
class EXmlAttribute : public EXmlNode
{
public:
EXmlElement(void) { };
virtual ~EXmlElement(void) { };
virtual nodeType_te GetType(void) { return typeAttribute; };
EXmlAttribute(void) { };
virtual ~EXmlAttribute(void) { };
virtual nodeType_te GetType(void) { return exml::typeAttribute; };
};
};

View File

@ -10,32 +10,32 @@
exml::EXmlDocument::EXmlDocument(void) :
m_charset(unicode::EDN_CHARSET_UNKNOW),
m_charset(unicode::EDN_CHARSET_UTF8),
m_caseSensitive(false)
{
}
bool Parse(const etk::UString& _data)
bool exml::EXmlDocument::Parse(const etk::UString& _data)
{
// came from char ==> force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8;
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;
}
bool Generate(etk::UString& _data)
bool exml::EXmlDocument::Generate(etk::UString& _data)
{
return false;
}
bool Load(const etk::UString& _file)
bool exml::EXmlDocument::Load(const etk::UString& _file)
{
return false;
}
bool Store(const etk::UString& _file)
bool exml::EXmlDocument::Store(const etk::UString& _file)
{
return false;
}

View File

@ -7,9 +7,10 @@
*/
#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()) {
return NULL;
@ -17,7 +18,7 @@ EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
return m_listSub[_id];
}
void exml::EXmlElement::AppendSub(EXmlNode* _node)
void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
@ -32,14 +33,14 @@ void exml::EXmlElement::AppendSub(EXmlNode* _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()) {
return NULL;
}
return m_listAttribute[_id];
}
void exml::EXmlElement::AppendAttribute(EXmlAttribute* _node)
void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
@ -54,25 +55,25 @@ void exml::EXmlElement::AppendAttribute(EXmlAttribute* _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++) {
if (_data[iii] == "<") {
if (_data[iii] == '<') {
if (iii+1>=_data.Size()) {
// TODO : an error occured ...
return;
return iii;
}
// find the end of the balise :
int32_t endPos = iii;
for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) {
if(_data[jjj] == ">") {
if(_data[jjj] == '>') {
endPos = jjj;
break;
}
}
if (endPos == iii) {
// TODO : an error occured ...
return;
return iii;
}
int32_t sizeElement = endPos-iii;
if( sizeElement>2
@ -82,7 +83,7 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
// TODO : ...
iii = endPos
iii = endPos;
continue;
}
if( sizeElement>5
@ -97,13 +98,13 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
// TODO : ...
iii = endPos
iii = endPos;
continue;
}
// find a normal node ...
// TODO : ...
for (int32_t jjj=iii+1; jjj<_data.Size(); jjj++) {
if(_data[jjj] == ">") {
if(_data[jjj] == '>') {
// we find the end ...
iii = jjj;
break;
@ -111,13 +112,20 @@ int32_t exml::EXmlElement::Parse(const etk::UString& _data, int32_t _pos, bool _
}
} else {
// 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 <etk/Vector.h>
#include <exml/EXmlAttribute.h>
namespace exml
{
@ -32,8 +33,8 @@ namespace exml
int32_t SizeAttribute(void) const { return m_listSub.Size(); };
EXmlAttribute* GetAttribute(int32_t _id);
void AppendAttribute(EXmlAttribute* _node);
protected:
virtual int32_t Parse(const etk::UString& _data, int32_t _pos, bool _caseSensitive, ivec2& _filePos);
public:
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/UString.h>
#include <etk/math/Vector2D.h>
namespace exml
{
@ -18,7 +19,7 @@ namespace exml
typeNode, //!< might be an error ...
typeDocument, //!< all the file main access
typeDeclaration, //!< <?xml ... ?>
typeAttibute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" />
typeAttribute, //!< the <Element ATTRIBUTE="ATTRIBUTE_VALUE" />
typeElement, //!< the <XXX> ... </XXX>
typeComment, //!< comment node : <!-- -->
typeText, //!< <XXX> InsideText </XXX>
@ -29,11 +30,11 @@ namespace exml
public:
EXmlNode(void) { };
virtual ~EXmlNode(void) { };
protected:
public:
/**
* 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:
etk::UString m_name;
public:
@ -49,3 +50,5 @@ namespace exml
};
};
#endif