[DEV] add some basic feature
This commit is contained in:
parent
31482734a7
commit
5158a7ae8e
@ -9,6 +9,14 @@
|
|||||||
#include <exml/EXmlAttribute.h>
|
#include <exml/EXmlAttribute.h>
|
||||||
#include <exml/debug.h>
|
#include <exml/debug.h>
|
||||||
|
|
||||||
|
exml::EXmlAttribute::EXmlAttribute(const etk::UString& _name, const etk::UString& _value) :
|
||||||
|
exml::EXmlNode(_value),
|
||||||
|
m_name(_name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
|
bool exml::EXmlAttribute::Parse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos)
|
||||||
{
|
{
|
||||||
EXML_DEBUG("start parse : 'attribute'");
|
EXML_DEBUG("start parse : 'attribute'");
|
||||||
|
@ -18,10 +18,16 @@ namespace exml
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EXmlAttribute(void) { };
|
EXmlAttribute(void) { };
|
||||||
|
EXmlAttribute(const etk::UString& _name, const etk::UString& _value);
|
||||||
virtual ~EXmlAttribute(void) { };
|
virtual ~EXmlAttribute(void) { };
|
||||||
virtual nodeType_te GetType(void) { return exml::typeAttribute; };
|
virtual nodeType_te GetType(void) { return exml::typeAttribute; };
|
||||||
virtual bool 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);
|
||||||
virtual bool Generate(etk::UString& _data, int32_t _indent);
|
virtual bool Generate(etk::UString& _data, int32_t _indent);
|
||||||
|
protected:
|
||||||
|
etk::UString m_name;
|
||||||
|
public:
|
||||||
|
virtual void SetName(etk::UString _name) { m_name = _name; };
|
||||||
|
virtual const etk::UString& GetName(void) { return m_name; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,6 +37,21 @@ void exml::EXmlElement::AppendSub(exml::EXmlNode* _node)
|
|||||||
m_listSub.PushBack(_node);
|
m_listSub.PushBack(_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exml::EXmlNode* exml::EXmlElement::GetNode(const etk::UString& _name)
|
||||||
|
{
|
||||||
|
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::GetAttribute(int32_t _id)
|
||||||
{
|
{
|
||||||
if (_id <0 || _id>m_listAttribute.Size()) {
|
if (_id <0 || _id>m_listAttribute.Size()) {
|
||||||
@ -59,6 +74,20 @@ void exml::EXmlElement::AppendAttribute(exml::EXmlAttribute* _node)
|
|||||||
m_listAttribute.PushBack(_node);
|
m_listAttribute.PushBack(_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const etk::UString& exml::EXmlElement::GetAttribute(const etk::UString& _name)
|
||||||
|
{
|
||||||
|
static const etk::Ustring errorReturn("");
|
||||||
|
if (_name.Size()==0) {
|
||||||
|
return errorReturn;
|
||||||
|
}
|
||||||
|
for (int32_t iii=0; iii<m_listAttribute.Size(); iii++) {
|
||||||
|
if( NULL != m_listAttribute[iii]
|
||||||
|
&& m_listAttribute[iii]->GetName() == _name) {
|
||||||
|
return m_listAttribute[iii]->GetValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errorReturn;
|
||||||
|
}
|
||||||
|
|
||||||
bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent)
|
bool exml::EXmlElement::Generate(etk::UString& _data, int32_t _indent)
|
||||||
{
|
{
|
||||||
@ -210,7 +239,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
etk::UString tmpname = _data.Extract(iii+white+2, endPosName+1);
|
etk::UString tmpname = _data.Extract(iii+white+2, endPosName+1);
|
||||||
if( tmpname == m_name) {
|
if( tmpname == m_value) {
|
||||||
// find end of node :
|
// find end of node :
|
||||||
// find > element ...
|
// find > element ...
|
||||||
for (int32_t jjj=endPosName+1; jjj<_data.Size(); jjj++) {
|
for (int32_t jjj=endPosName+1; jjj<_data.Size(); jjj++) {
|
||||||
@ -256,7 +285,7 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
|
|||||||
EXML_ERROR(_filePos << " Allocation error ...");
|
EXML_ERROR(_filePos << " Allocation error ...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
element->SetName(tmpname);
|
element->SetValue(tmpname);
|
||||||
_pos = endPosName+1;
|
_pos = endPosName+1;
|
||||||
_filePos += ivec2(endPosName,0);
|
_filePos += ivec2(endPosName,0);
|
||||||
if (false==element->Parse(_data, _pos, _caseSensitive, _filePos)) {
|
if (false==element->Parse(_data, _pos, _caseSensitive, _filePos)) {
|
||||||
@ -269,8 +298,6 @@ bool exml::EXmlElement::SubParse(const etk::UString& _data, int32_t& _pos, bool
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (_data[iii] == '>') {
|
if (_data[iii] == '>') {
|
||||||
EXML_ERROR(_filePos << " find elemement '>' ==> no reason to be here ...");
|
EXML_ERROR(_filePos << " find elemement '>' ==> no reason to be here ...");
|
||||||
|
@ -19,6 +19,7 @@ namespace exml
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EXmlElement(void) { };
|
EXmlElement(void) { };
|
||||||
|
EXmlElement(const etk::UString& _value) : exml::EXmlNode(_value) { };
|
||||||
virtual ~EXmlElement(void) { };
|
virtual ~EXmlElement(void) { };
|
||||||
virtual nodeType_te GetType(void) { return typeElement; };
|
virtual nodeType_te GetType(void) { return typeElement; };
|
||||||
protected:
|
protected:
|
||||||
@ -38,6 +39,8 @@ namespace exml
|
|||||||
virtual bool Generate(etk::UString& _data, int32_t _indent);
|
virtual bool Generate(etk::UString& _data, int32_t _indent);
|
||||||
protected:
|
protected:
|
||||||
bool SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode=false);
|
bool SubParse(const etk::UString& _data, int32_t& _pos, bool _caseSensitive, ivec2& _filePos, bool _mainNode=false);
|
||||||
|
|
||||||
|
const etk::UString& GetAttribute(const etk::UString& _name);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,13 @@
|
|||||||
#include <exml/EXmlNode.h>
|
#include <exml/EXmlNode.h>
|
||||||
#include <exml/debug.h>
|
#include <exml/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
exml::EXmlNode::EXmlNode(const etk::UString& _value) :
|
||||||
|
m_value(_value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void exml::EXmlNode::AddIndent(etk::UString& _data, int32_t _indent)
|
void exml::EXmlNode::AddIndent(etk::UString& _data, int32_t _indent)
|
||||||
{
|
{
|
||||||
for (int32_t iii=0; iii<_indent; iii++) {
|
for (int32_t iii=0; iii<_indent; iii++) {
|
||||||
@ -91,3 +98,63 @@ int32_t exml::EXmlNode::CountWhiteChar(const etk::UString& _data, int32_t _pos)
|
|||||||
}
|
}
|
||||||
return white;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@
|
|||||||
|
|
||||||
namespace exml
|
namespace exml
|
||||||
{
|
{
|
||||||
|
class EXmlDocument;
|
||||||
|
class EXmlAttribute;
|
||||||
|
class EXmlComment;
|
||||||
|
class EXmlDeclaration;
|
||||||
|
class EXmlElement;
|
||||||
|
class EXmlText;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
typeNode, //!< might be an error ...
|
typeNode, //!< might be an error ...
|
||||||
typeDocument, //!< all the file main access
|
typeDocument, //!< all the file main access
|
||||||
@ -29,6 +36,7 @@ namespace exml
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EXmlNode(void) { };
|
EXmlNode(void) { };
|
||||||
|
EXmlNode(const etk::UString& _value);
|
||||||
virtual ~EXmlNode(void) { };
|
virtual ~EXmlNode(void) { };
|
||||||
protected:
|
protected:
|
||||||
void AddIndent(etk::UString& _data, int32_t _indent);
|
void AddIndent(etk::UString& _data, int32_t _indent);
|
||||||
@ -38,11 +46,6 @@ namespace exml
|
|||||||
*/
|
*/
|
||||||
virtual bool 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) = 0;
|
||||||
virtual bool Generate(etk::UString& _data, int32_t _indent) { return true; };
|
virtual bool Generate(etk::UString& _data, int32_t _indent) { return true; };
|
||||||
protected:
|
|
||||||
etk::UString m_name;
|
|
||||||
public:
|
|
||||||
virtual void SetName(etk::UString _name) { m_name = _name; };
|
|
||||||
virtual const etk::UString& GetName(void) { return m_name; };
|
|
||||||
protected:
|
protected:
|
||||||
etk::UString m_value;
|
etk::UString m_value;
|
||||||
public:
|
public:
|
||||||
@ -54,6 +57,20 @@ namespace exml
|
|||||||
void DrawElementParsed(const etk::UniChar& _val, const ivec2& _firstChar);
|
void DrawElementParsed(const etk::UniChar& _val, const ivec2& _firstChar);
|
||||||
bool CheckAvaillable(const etk::UniChar& _val, bool _firstChar);
|
bool CheckAvaillable(const etk::UniChar& _val, bool _firstChar);
|
||||||
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos);
|
int32_t CountWhiteChar(const etk::UString& _data, int32_t _pos);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
15
exml/exml.h
Normal file
15
exml/exml.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
*
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* @license BSD v3 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ETK_XML_H__
|
||||||
|
#define __ETK_XML_H__
|
||||||
|
|
||||||
|
#include <exml/EXmlDocument.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user