[DEV] rename files ==> simplify visibility and api

This commit is contained in:
Edouard Dupin 2013-06-21 22:25:24 +02:00
parent e1520b0515
commit 240147561d
21 changed files with 317 additions and 254 deletions

View File

@ -6,25 +6,27 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlAttribute.h>
#include <exml/Attribute.h>
#include <exml/debug.h>
exml::EXmlAttribute::EXmlAttribute(const etk::UString& _name, const etk::UString& _value) :
exml::EXmlNode(_value),
exml::Attribute::Attribute(const etk::UString& _name, const etk::UString& _value) :
exml::Node(_value),
m_name(_name)
{
}
bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::Attribute::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'attribute'");
// search end of the comment :
int32_t lastElementName = _pos;
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
EXML_ERROR("unexpected '\\n' in an attribute parsing");
@ -56,7 +58,9 @@ bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _
int32_t lastAttributePos = lastElementName+3;
for (int32_t iii=lastElementName+2; iii<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
EXML_ERROR("unexpected '\\n' in an attribute parsing");
@ -77,7 +81,9 @@ bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _
int32_t lastAttributePos = lastElementName+3;
for (int32_t iii=lastElementName+3; iii<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
EXML_ERROR("unexpected '\\n' in an attribute parsing");
@ -91,11 +97,11 @@ bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _
}
m_value = _data.Extract(lastElementName+3, lastAttributePos+1);
_pos = lastAttributePos+1;
_pos = lastAttributePos;
return true;
}
bool exml::EXmlAttribute::Generate(etk::UString& _data, int32_t _indent) const
bool exml::Attribute::Generate(etk::UString& _data, int32_t _indent) const
{
_data += " ";
_data += m_name;

View File

@ -9,17 +9,17 @@
#ifndef __ETK_XML_ATTRIBUTE_H__
#define __ETK_XML_ATTRIBUTE_H__
#include <exml/EXmlNode.h>
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlAttribute : public EXmlNode
class Attribute : public Node
{
public:
EXmlAttribute(void) { };
EXmlAttribute(const etk::UString& _name, const etk::UString& _value);
virtual ~EXmlAttribute(void) { };
Attribute(void) { };
Attribute(const etk::UString& _name, const etk::UString& _value);
virtual ~Attribute(void) { };
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) const;
@ -28,8 +28,8 @@ namespace exml
public:
virtual void SetName(etk::UString _name) { m_name = _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; };
virtual operator exml::Attribute* () { return this; };
virtual operator const exml::Attribute* () const { return this; };
};
};

View File

@ -6,16 +6,18 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlComment.h>
#include <exml/Comment.h>
#include <exml/debug.h>
bool exml::EXmlComment::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::Comment::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'comment'");
// search end of the comment :
for (int32_t iii=_pos; iii+2<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
continue;
@ -35,7 +37,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) const
bool exml::Comment::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<!--";

View File

@ -9,21 +9,21 @@
#ifndef __ETK_XML_COMMENT_H__
#define __ETK_XML_COMMENT_H__
#include <exml/EXmlNode.h>
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlComment : public EXmlNode
class Comment : public Node
{
public:
EXmlComment(void) { };
virtual ~EXmlComment(void) { };
Comment(void) { };
virtual ~Comment(void) { };
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) const;
virtual operator exml::EXmlComment* () { return this; };
virtual operator const exml::EXmlComment* () const { return this; };
virtual operator exml::Comment* () { return this; };
virtual operator const exml::Comment* () const { return this; };
};
};

View File

@ -6,10 +6,10 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlDeclaration.h>
#include <exml/Declaration.h>
#include <exml/debug.h>
bool exml::EXmlDeclaration::Generate(etk::UString& _data, int32_t _indent) const
bool exml::Declaration::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<?";
@ -24,13 +24,15 @@ bool exml::EXmlDeclaration::Generate(etk::UString& _data, int32_t _indent) const
return true;
}
bool exml::EXmlDeclaration::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::Declaration::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'declaration'");
// search end of the comment :
for (int32_t iii=_pos; iii+1<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
continue;
@ -46,7 +48,7 @@ bool exml::EXmlDeclaration::Parse(const etk::UString& _data, int32_t& _pos, bool
// find end of value:
m_value = _data.Extract(_pos, iii-1);
EXML_DEBUG(" find declaration '" << m_value << "'");
_pos = iii;
_pos = iii+1;
return true;
}
}

View File

@ -9,21 +9,21 @@
#ifndef __ETK_XML_DECLARATION_H__
#define __ETK_XML_DECLARATION_H__
#include <exml/EXmlNode.h>
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlDeclaration : public EXmlNode
class Declaration : public exml::Node
{
public:
EXmlDeclaration(void) { };
virtual ~EXmlDeclaration(void) { };
Declaration(void) { };
virtual ~Declaration(void) { };
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; };
virtual operator exml::Declaration* () { return this; };
virtual operator const exml::Declaration* () const { return this; };
};
};

112
exml/Document.cpp Normal file
View File

@ -0,0 +1,112 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <exml/Document.h>
#include <exml/debug.h>
#include <etk/os/FSNode.h>
exml::Document::Document(void) :
m_charset(unicode::EDN_CHARSET_UTF8),
m_caseSensitive(false)
{
}
bool exml::Document::Generate(etk::UString& _data, int32_t _indent) const
{
for (int32_t iii=0; iii<m_listSub.Size(); iii++) {
if (NULL!=m_listSub[iii]) {
m_listSub[iii]->Generate(_data, _indent);
}
}
return true;
}
bool exml::Document::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'document'");
// in this case : no main node ...
SubParse(_data, _pos, _caseSensitive, _filePos, true);
return true;
}
bool exml::Document::Parse(const etk::UString& _data)
{
EXML_DEBUG("Start parsing document (type: string) size=" << _data.Size());
// came from char ==> force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8;
ivec2 filePos(0,1);
int32_t parsePos = 0;
return Parse(_data, parsePos, m_caseSensitive, filePos);
}
bool exml::Document::Generate(etk::UString& _data)
{
return false;
}
bool exml::Document::Load(const etk::UString& _file)
{
// Start loading the XML :
EXML_DEBUG("open file (xml) \"" << _file << "\"");
etk::FSNode tmpFile(_file);
if (false == tmpFile.Exist()) {
EXML_ERROR("File Does not exist : " << _file);
return false;
}
int64_t fileSize = tmpFile.FileSize();
if (0==fileSize) {
EXML_ERROR("This file is empty : " << _file);
return false;
}
if (false == tmpFile.FileOpenRead()) {
EXML_ERROR("Can not open the file : " << _file);
return false;
}
// allocate data
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
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);
// close the file:
tmpFile.FileClose();
// convert in UTF8 :
etk::UString tmpDataUnicode(fileBuffer, unicode::EDN_CHARSET_UTF8);
// remove temporary buffer:
delete(fileBuffer);
// parse the data :
bool ret = Parse(tmpDataUnicode);
Display();
if (0==Size()) {
EXML_CRITICAL("lkjlkj");
}
return ret;
}
bool exml::Document::Store(const etk::UString& _file)
{
return false;
}
void exml::Document::Display(void)
{
etk::UString tmpp;
Generate(tmpp, 0);
EXML_INFO("Generated XML : \n" << tmpp);
}

View File

@ -9,17 +9,17 @@
#ifndef __ETK_XML_DOCUMENT_H__
#define __ETK_XML_DOCUMENT_H__
#include <exml/EXmlElement.h>
#include <exml/Element.h>
#include <etk/unicode.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlDocument : exml::EXmlElement
class Document : public exml::Element
{
public:
EXmlDocument(void);
virtual ~EXmlDocument(void) { };
Document(void);
virtual ~Document(void) { };
virtual nodeType_te GetType(void) const { return typeDocument; };
private:
unicode::charset_te m_charset;
@ -64,8 +64,8 @@ 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) const;
virtual operator exml::EXmlDocument* () { return this; };
virtual operator const exml::EXmlDocument* () const { return this; };
virtual operator exml::Document* () { return this; };
virtual operator const exml::Document* () const { return this; };
};
};

View File

@ -1,72 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <exml/EXmlDocument.h>
#include <exml/debug.h>
exml::EXmlDocument::EXmlDocument(void) :
m_charset(unicode::EDN_CHARSET_UTF8),
m_caseSensitive(false)
{
}
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]) {
m_listSub[iii]->Generate(_data, _indent);
}
}
return true;
}
bool exml::EXmlDocument::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'document'");
// in this case : no main node ...
SubParse(_data, _pos, _caseSensitive, _filePos, true);
return true;
}
bool exml::EXmlDocument::Parse(const etk::UString& _data)
{
EXML_DEBUG("Start parsing document (type: string) size=" << _data.Size());
// came from char ==> force in utf8 ...
m_charset = unicode::EDN_CHARSET_UTF8;
ivec2 filePos(0,1);
int32_t parsePos = 0;
return Parse(_data, parsePos, m_caseSensitive, filePos);
}
bool exml::EXmlDocument::Generate(etk::UString& _data)
{
return false;
}
bool exml::EXmlDocument::Load(const etk::UString& _file)
{
return false;
}
bool exml::EXmlDocument::Store(const etk::UString& _file)
{
return false;
}
void exml::EXmlDocument::Display(void)
{
etk::UString tmpp;
Generate(tmpp, 0);
EXML_INFO("Generated XML : \n" << tmpp);
}

View File

@ -1,54 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_ELEMENT_H__
#define __ETK_XML_ELEMENT_H__
#include <exml/EXmlNode.h>
#include <etk/Vector.h>
#include <exml/EXmlAttribute.h>
namespace exml
{
class EXmlElement : public EXmlNode
{
public:
EXmlElement(void) { };
EXmlElement(const etk::UString& _value) : exml::EXmlNode(_value) { };
virtual ~EXmlElement(void) { };
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(); };
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(); };
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) const;
protected:
bool SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode=false);
virtual operator exml::EXmlElement* () { return this; };
virtual operator const exml::EXmlElement* () const { return this; };
};
};
#endif

View File

@ -6,15 +6,15 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlElement.h>
#include <exml/Element.h>
#include <exml/debug.h>
#include <exml/EXmlText.h>
#include <exml/EXmlComment.h>
#include <exml/EXmlAttribute.h>
#include <exml/EXmlDeclaration.h>
#include <exml/Text.h>
#include <exml/Comment.h>
#include <exml/Attribute.h>
#include <exml/Declaration.h>
exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
exml::Node* exml::Element::Get(int32_t _id)
{
if (_id <0 || _id>m_listSub.Size()) {
return NULL;
@ -22,7 +22,7 @@ exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id)
return m_listSub[_id];
}
const exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id) const
const exml::Node* exml::Element::Get(int32_t _id) const
{
if (_id <0 || _id>m_listSub.Size()) {
return NULL;
@ -30,7 +30,7 @@ const exml::EXmlNode* exml::EXmlElement::GetSub(int32_t _id) const
return m_listSub[_id];
}
void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
void exml::Element::Append(exml::Node* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
@ -45,7 +45,7 @@ void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
m_listSub.PushBack(_node);
}
exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name)
exml::Node* exml::Element::GetNamed(const etk::UString& _name)
{
if (_name.Size()==0) {
return NULL;
@ -59,7 +59,7 @@ exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name)
}
return NULL;
}
const exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name) const
const exml::Node* exml::Element::GetNamed(const etk::UString& _name) const
{
if (_name.Size()==0) {
return NULL;
@ -74,21 +74,21 @@ const exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name) cons
return NULL;
}
exml::EXmlAttribute* exml::EXmlElement::GetAttr(int32_t _id)
exml::Attribute* exml::Element::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
const exml::Attribute* exml::Element::GetAttr(int32_t _id) const
{
if (_id <0 || _id>m_listAttribute.Size()) {
return NULL;
}
return m_listAttribute[_id];
}
void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
void exml::Element::AppendAttribute(exml::Attribute* _node)
{
if (_node == NULL) {
EXML_ERROR("Try to set an empty node");
@ -103,7 +103,7 @@ void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
m_listAttribute.PushBack(_node);
}
const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name) const
const etk::UString& exml::Element::GetAttribute(const etk::UString& _name) const
{
static const etk::UString errorReturn("");
if (_name.Size()==0) {
@ -118,7 +118,7 @@ const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name) c
return errorReturn;
}
bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent) const
bool exml::Element::Generate(etk::UString& _data, int32_t _indent) const
{
AddIndent(_data, _indent);
_data += "<";
@ -133,7 +133,7 @@ bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent) const
if( m_listSub.Size()==1
&& m_listSub[0] != NULL
&& m_listSub[0]->GetType() == exml::typeText
&& static_cast<exml::EXmlText*>(m_listSub[0])->CountLines()==1) {
&& static_cast<exml::Text*>(m_listSub[0])->CountLines()==1) {
_data += ">";
m_listSub[0]->Generate(_data,0);
} else {
@ -156,12 +156,14 @@ bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent) const
}
bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode)
bool exml::Element::SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode)
{
EXML_DEBUG(" start subParse ... " << _pos << " " << _filePos);
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '<') {
int32_t white = CountWhiteChar(_data, iii+1);
if (iii+white+1>=_data.Size()) {
@ -177,7 +179,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
}
if(_data[iii+white+1] == '?') {
// Find declaration balise
exml::EXmlDeclaration* declaration = new exml::EXmlDeclaration();
exml::Declaration* declaration = new exml::Declaration();
if (NULL==declaration) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;
@ -188,6 +190,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
delete(declaration);
return false;
}
iii = _pos;
m_listSub.PushBack(declaration);
continue;
}
@ -207,7 +210,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
return false;
}
// find comment:
exml::EXmlComment* comment = new exml::EXmlComment();
exml::Comment* comment = new exml::Comment();
if (NULL==comment) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;
@ -235,7 +238,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
return false;
}
// find text:
exml::EXmlTextCDATA* text = new exml::EXmlTextCDATA();
exml::TextCDATA* text = new exml::TextCDATA();
if (NULL==text) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;
@ -273,7 +276,9 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
// find > element ...
for (int32_t jjj=endPosName+1; jjj<_data.Size(); jjj++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[jjj], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[jjj], _filePos);
#endif
if (_data[jjj] == '\n') {
_filePos.setValue(0, _filePos.y()+1);
continue;
@ -309,7 +314,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
etk::UString tmpname = _data.Extract(iii+white+1, endPosName+1);
//EXML_INFO("find node named : '" << tmpname << "'");
// find text:
exml::EXmlElement* element = new exml::EXmlElement();
exml::Element* element = new exml::Element();
if (NULL==element) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;
@ -342,7 +347,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
} else {
// find data ==> parse it...
exml::EXmlText* text = new exml::EXmlText();
exml::Text* text = new exml::Text();
if (NULL==text) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;
@ -361,7 +366,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
return false;
}
bool exml::EXmlElement::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::Element::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
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
@ -372,11 +377,13 @@ bool exml::EXmlElement::Parse(const etk::UString& _data, int32_t& _pos, bool _ca
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
}
EXML_DEBUG("parse : '" << _data[iii] << "'");
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if(_data[iii] == '>') {
// we find the end ...
_pos = iii+1;
return exml::EXmlElement::SubParse(_data, _pos, _caseSensitive, _filePos, false);
return exml::Element::SubParse(_data, _pos, _caseSensitive, _filePos, false);
}
if (_data[iii] == '/') {
// standalone node or error...
@ -394,7 +401,7 @@ bool exml::EXmlElement::Parse(const etk::UString& _data, int32_t& _pos, bool _ca
}
if (true == CheckAvaillable(_data[iii], true)) {
// we find an attibute ==> create a new and parse it :
exml::EXmlAttribute* attribute = new exml::EXmlAttribute();
exml::Attribute* attribute = new exml::Attribute();
if (NULL==attribute) {
EXML_ERROR(_filePos << " Allocation error ...");
return false;

54
exml/Element.h Normal file
View File

@ -0,0 +1,54 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __ETK_XML_ELEMENT_H__
#define __ETK_XML_ELEMENT_H__
#include <exml/Node.h>
#include <etk/Vector.h>
#include <exml/Attribute.h>
namespace exml
{
class Element : public Node
{
public:
Element(void) { };
Element(const etk::UString& _value) : exml::Node(_value) { };
virtual ~Element(void) { };
virtual nodeType_te GetType(void) const { return typeElement; };
protected:
etk::Vector<exml::Node*> m_listSub;
public:
int32_t Size(void) const { return m_listSub.Size(); };
void Append(Node* _node);
Node* Get(int32_t _id);
const Node* Get(int32_t _id) const;
Node* GetNamed(const etk::UString& _name);
const Node* GetNamed(const etk::UString& _name) const;
protected:
etk::Vector<exml::Attribute*> m_listAttribute;
public:
int32_t SizeAttribute(void) const { return m_listSub.Size(); };
void AppendAttribute(Attribute* _node);
Attribute* GetAttr(int32_t _id);
const Attribute* 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) const;
protected:
bool SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode=false);
virtual operator exml::Element* () { return this; };
virtual operator const exml::Element* () const { return this; };
};
};
#endif

View File

@ -6,26 +6,27 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlNode.h>
#include <exml/Node.h>
#include <exml/debug.h>
exml::EXmlNode::EXmlNode(const etk::UString& _value) :
exml::Node::Node(const etk::UString& _value) :
m_pos(0,0),
m_value(_value)
{
}
void exml::EXmlNode::AddIndent(etk::UString& _data, int32_t _indent) const
void exml::Node::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) const
void exml::Node::DrawElementParsed(const etk::UniChar& _val, const ivec2& _filePos) const
{
EXML_CRITICAL("lkjlkj");
if (_val=='\n') {
EXML_DEBUG(_filePos << " Parse '\\n'");
} else if (_val=='\t') {
@ -37,7 +38,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) const
bool exml::Node::CheckAvaillable(const etk::UniChar& _val, bool _firstChar) const
{
if( _val == '!'
|| _val == '"'
@ -84,7 +85,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) const
int32_t exml::Node::CountWhiteChar(const etk::UString& _data, int32_t _pos) const
{
int32_t white=0;
for (int32_t iii=_pos; iii<_data.Size(); iii++) {

View File

@ -15,12 +15,13 @@
namespace exml
{
class EXmlDocument;
class EXmlAttribute;
class EXmlComment;
class EXmlDeclaration;
class EXmlElement;
class EXmlText;
//#define ENABLE_DISPLAY_PARSED_ELEMENT
class Document;
class Attribute;
class Comment;
class Declaration;
class Element;
class Text;
typedef enum {
typeNode, //!< might be an error ...
@ -32,12 +33,12 @@ namespace exml
typeText, //!< <XXX> InsideText </XXX>
} nodeType_te;
class EXmlNode
class Node
{
public:
EXmlNode(void) : m_pos(0,0) { };
EXmlNode(const etk::UString& _value);
virtual ~EXmlNode(void) { };
Node(void) : m_pos(0,0) { };
Node(const etk::UString& _value);
virtual ~Node(void) { };
protected:
void AddIndent(etk::UString& _data, int32_t _indent) const;
public:
@ -62,18 +63,18 @@ namespace exml
bool CheckAvaillable(const etk::UniChar& _val, bool _firstChar) const;
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos) const;
public:
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; };
virtual operator exml::Document* () { return NULL; };
virtual operator const exml::Document* () const { return NULL; };
virtual operator exml::Attribute* () { return NULL; };
virtual operator const exml::Attribute* () const { return NULL; };
virtual operator exml::Comment* () { return NULL; };
virtual operator const exml::Comment* () const { return NULL; };
virtual operator exml::Declaration* () { return NULL; };
virtual operator const exml::Declaration* () const { return NULL; };
virtual operator exml::Element* () { return NULL; };
virtual operator const exml::Element* () const { return NULL; };
virtual operator exml::Text* () { return NULL; };
virtual operator const exml::Text* () const{ return NULL; };
bool IsDocument(void) const { return GetType()==exml::typeDocument; };
bool IsAttribute(void) const { return GetType()==exml::typeAttribute; };

View File

@ -6,16 +6,16 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlText.h>
#include <exml/Text.h>
#include <exml/debug.h>
bool exml::EXmlText::Generate(etk::UString& _data, int32_t _indent) const
bool exml::Text::Generate(etk::UString& _data, int32_t _indent) const
{
_data += m_value;
return true;
}
int32_t exml::EXmlText::CountLines(void) const
int32_t exml::Text::CountLines(void) const
{
int32_t count = 1;
for (int32_t iii=0; iii<m_value.Size(); iii++) {
@ -26,13 +26,15 @@ int32_t exml::EXmlText::CountLines(void) const
return count;
}
bool exml::EXmlText::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::Text::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'text'");
// search end of the comment :
for (int32_t iii=_pos; iii<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(0, _filePos.y()+1);
continue;
@ -63,13 +65,15 @@ bool exml::EXmlText::Parse(const etk::UString& _data, int32_t& _pos, bool _caseS
return false;
}
bool exml::EXmlTextCDATA::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
bool exml::TextCDATA::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
{
EXML_DEBUG("start parse : 'text::CDATA'");
// search end of the comment :
for (int32_t iii=_pos; iii+2<_data.Size(); iii++) {
_filePos += ivec2(1,0);
DrawElementParsed(_data[iii], _filePos);
#ifdef ENABLE_DISPLAY_PARSED_ELEMENT
DrawElementParsed(_data[iii], _filePos);
#endif
if (_data[iii] == '\n') {
_filePos.setValue(1, _filePos.y()+1);
continue;

View File

@ -9,28 +9,28 @@
#ifndef __ETK_XML_TEXT_H__
#define __ETK_XML_TEXT_H__
#include <exml/EXmlNode.h>
#include <exml/Node.h>
#include <etk/Vector.h>
namespace exml
{
class EXmlText : public EXmlNode
class Text : public Node
{
public:
EXmlText(void) { };
virtual ~EXmlText(void) { };
Text(void) { };
virtual ~Text(void) { };
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) const;
int32_t CountLines(void) const;
virtual operator exml::EXmlText* () { return this; };
virtual operator const exml::EXmlText* () const { return this; };
virtual operator exml::Text* () { return this; };
virtual operator const exml::Text* () const { return this; };
};
class EXmlTextCDATA : public EXmlText
class TextCDATA : public Text
{
public:
EXmlTextCDATA(void) { };
virtual ~EXmlTextCDATA(void) { };
TextCDATA(void) { };
virtual ~TextCDATA(void) { };
virtual nodeType_te GetType(void) { return typeText; };
virtual bool Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos);
};

View File

@ -9,7 +9,7 @@
#ifndef __ETK_XML_H__
#define __ETK_XML_H__
#include <exml/EXmlDocument.h>
#include <exml/Document.h>
#endif

View File

@ -6,14 +6,14 @@
* @license BSD v3 (see license file)
*/
#include <exml/EXmlTest.h>
#include <exml/test.h>
#include <etk/Debug.h>
#include <exml/debug.h>
int main(int argc, const char *argv[])
{
GeneralDebugSetLevel(etk::LOG_LEVEL_VERBOSE);
exml::EXmlDocument doc;
exml::Document doc;
etk::UString testString = ""
"< exemple\n >\n"
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"

View File

@ -9,8 +9,8 @@
#ifndef __ETK_XML_TEST_H__
#define __ETK_XML_TEST_H__
#include <exml/EXmlNode.h>
#include <exml/EXmlDocument.h>
#include <exml/Node.h>
#include <exml/Document.h>
namespace exml
{

View File

@ -9,13 +9,13 @@ def Create(target):
myModule.AddSrcFile([
'exml/debug.cpp',
'exml/EXmlAttribute.cpp',
'exml/EXmlComment.cpp',
'exml/EXmlDeclaration.cpp',
'exml/EXmlDocument.cpp',
'exml/EXmlElement.cpp',
'exml/EXmlNode.cpp',
'exml/EXmlText.cpp'])
'exml/Attribute.cpp',
'exml/Comment.cpp',
'exml/Declaration.cpp',
'exml/Document.cpp',
'exml/Element.cpp',
'exml/Node.cpp',
'exml/Text.cpp'])
myModule.AddExportPath(lutinTools.GetCurrentPath(__file__))

View File

@ -9,7 +9,7 @@ def Create(target):
# add the file to compile:
myModule.AddSrcFile([
'exml/EXmlTest.cpp'])
'exml/test.cpp'])
myModule.AddModuleDepend('exml')