Small html cleanup
This commit is contained in:
parent
c102ebb6da
commit
31b479e9f6
27 changed files with 330 additions and 252 deletions
|
@ -1,6 +1,5 @@
|
|||
#include "XmlAttribute.h"
|
||||
|
||||
|
||||
XmlAttribute::XmlAttribute(const std::string& name)
|
||||
: mName(name),
|
||||
mValue()
|
||||
|
@ -8,22 +7,22 @@ XmlAttribute::XmlAttribute(const std::string& name)
|
|||
|
||||
}
|
||||
|
||||
XmlAttributeUPtr XmlAttribute::Create(const std::string& name)
|
||||
XmlAttributePtr XmlAttribute::Create(const std::string& name)
|
||||
{
|
||||
return std::make_unique<XmlAttribute>(name);
|
||||
}
|
||||
|
||||
void XmlAttribute::SetValue(const std::string& value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
std::string XmlAttribute::GetName() const
|
||||
const std::string& XmlAttribute::getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
std::string XmlAttribute::GetValue() const
|
||||
const std::string& XmlAttribute::getValue() const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void XmlAttribute::setValue(const std::string& value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class XmlAttribute
|
||||
{
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mValue;
|
||||
|
||||
public:
|
||||
|
||||
XmlAttribute(const std::string& name);
|
||||
|
||||
static std::unique_ptr<XmlAttribute> Create(const std::string& name);
|
||||
|
||||
void SetValue(const std::string& value);
|
||||
const std::string& getName() const;
|
||||
|
||||
std::string GetName() const;
|
||||
const std::string& getValue() const;
|
||||
|
||||
std::string GetValue() const;
|
||||
void setValue(const std::string& value);
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mValue;
|
||||
};
|
||||
|
||||
using XmlAttributePtr = std::shared_ptr<XmlAttribute>;
|
||||
using XmlAttributeUPtr = std::unique_ptr<XmlAttribute>;
|
||||
using XmlAttributePtr = std::unique_ptr<XmlAttribute>;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "XmlElement.h"
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
XmlElement::XmlElement(const std::string& tagName)
|
||||
: mTagName(tagName),
|
||||
|
@ -8,46 +9,51 @@ XmlElement::XmlElement(const std::string& tagName)
|
|||
|
||||
}
|
||||
|
||||
XmlElementUPtr XmlElement::Create(const std::string& tagName)
|
||||
XmlElement::~XmlElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XmlElementPtr XmlElement::Create(const std::string& tagName)
|
||||
{
|
||||
return std::make_unique<XmlElement>(tagName);
|
||||
}
|
||||
|
||||
void XmlElement::SetTagName(const std::string& tagName)
|
||||
void XmlElement::setTagName(const std::string& tagName)
|
||||
{
|
||||
mTagName = tagName;
|
||||
}
|
||||
|
||||
void XmlElement::AddChild(XmlElementUPtr child)
|
||||
void XmlElement::addChild(XmlElementPtr child)
|
||||
{
|
||||
mChildren.push_back(std::move(child));
|
||||
}
|
||||
|
||||
void XmlElement::AddAttribute(XmlAttributeUPtr attribute)
|
||||
void XmlElement::addAttribute(XmlAttributePtr attribute)
|
||||
{
|
||||
mAttributes.push_back(std::move(attribute));
|
||||
}
|
||||
|
||||
std::string XmlElement::GetTagName() const
|
||||
const std::string& XmlElement::getTagName() const
|
||||
{
|
||||
return mTagName;
|
||||
}
|
||||
|
||||
std::string XmlElement::GetText() const
|
||||
const std::string& XmlElement::getText() const
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
void XmlElement::SetText(const std::string& text)
|
||||
void XmlElement::setText(const std::string& text)
|
||||
{
|
||||
mText = text;
|
||||
}
|
||||
|
||||
XmlAttribute* XmlElement::GetAttribute(const std::string& attributeName) const
|
||||
XmlAttribute* XmlElement::getAttribute(const std::string& attributeName) const
|
||||
{
|
||||
for(const auto& attribute : mAttributes)
|
||||
{
|
||||
if(attribute->GetName() == attributeName)
|
||||
if(attribute->getName() == attributeName)
|
||||
{
|
||||
return attribute.get();
|
||||
}
|
||||
|
@ -55,7 +61,7 @@ XmlAttribute* XmlElement::GetAttribute(const std::string& attributeName) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
XmlAttribute* XmlElement::GetAttribute(std::size_t index) const
|
||||
XmlAttribute* XmlElement::getAttribute(std::size_t index) const
|
||||
{
|
||||
if(index < mAttributes.size())
|
||||
{
|
||||
|
@ -64,17 +70,17 @@ XmlAttribute* XmlElement::GetAttribute(std::size_t index) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::size_t XmlElement::GetNumAttributes() const
|
||||
std::size_t XmlElement::getNumAttributes() const
|
||||
{
|
||||
return mAttributes.size();
|
||||
}
|
||||
|
||||
std::size_t XmlElement::GetNumChildren() const
|
||||
std::size_t XmlElement::getNumChildren() const
|
||||
{
|
||||
return mChildren.size();
|
||||
}
|
||||
|
||||
XmlElement* XmlElement::GetChild(std::size_t index) const
|
||||
XmlElement* XmlElement::getChild(std::size_t index) const
|
||||
{
|
||||
return mChildren[index].get();
|
||||
}
|
||||
|
|
|
@ -1,40 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class XmlAttribute;
|
||||
using XmlAttributePtr = std::unique_ptr<XmlAttribute>;
|
||||
|
||||
class XmlElement
|
||||
{
|
||||
public:
|
||||
XmlElement(const std::string& tagName);
|
||||
virtual ~XmlElement() = default;
|
||||
virtual ~XmlElement();
|
||||
|
||||
static std::unique_ptr<XmlElement> Create(const std::string& tagName);
|
||||
|
||||
void AddAttribute(XmlAttributeUPtr attribute);
|
||||
void AddChild(std::unique_ptr<XmlElement> child);
|
||||
void addAttribute(XmlAttributePtr attribute);
|
||||
void addChild(std::unique_ptr<XmlElement> child);
|
||||
|
||||
std::string GetTagName() const;
|
||||
std::string GetText() const;
|
||||
XmlAttribute* GetAttribute(const std::string& attribute) const;
|
||||
XmlAttribute* GetAttribute(std::size_t index) const;
|
||||
std::size_t GetNumAttributes() const;
|
||||
const std::string& getTagName() const;
|
||||
const std::string& getText() const;
|
||||
XmlAttribute* getAttribute(const std::string& attribute) const;
|
||||
XmlAttribute* getAttribute(std::size_t index) const;
|
||||
std::size_t getNumAttributes() const;
|
||||
|
||||
std::size_t GetNumChildren() const;
|
||||
XmlElement* GetChild(std::size_t index) const;
|
||||
std::size_t getNumChildren() const;
|
||||
XmlElement* getChild(std::size_t index) const;
|
||||
|
||||
void SetText(const std::string& text);
|
||||
void SetTagName(const std::string& tagName);
|
||||
void setText(const std::string& text);
|
||||
void setTagName(const std::string& tagName);
|
||||
|
||||
protected:
|
||||
std::string mTagName;
|
||||
std::vector<XmlAttributeUPtr> mAttributes;
|
||||
std::vector<std::unique_ptr<XmlElement> > mChildren;
|
||||
std::string mText;
|
||||
|
||||
std::vector<XmlAttributePtr> mAttributes;
|
||||
std::vector<std::unique_ptr<XmlElement> > mChildren;
|
||||
};
|
||||
|
||||
using XmlElementPtr = std::shared_ptr<XmlElement>;
|
||||
using XmlElementUPtr = std::unique_ptr<XmlElement>;
|
||||
using XmlElementPtr = std::unique_ptr<XmlElement>;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "XmlProlog.h"
|
||||
|
||||
#include "XmlAttribute.h"
|
||||
|
||||
XmlProlog::XmlProlog(const std::string& tagName)
|
||||
: XmlElement(tagName),
|
||||
|
@ -9,22 +10,22 @@ XmlProlog::XmlProlog(const std::string& tagName)
|
|||
|
||||
}
|
||||
|
||||
XmlPrologUPtr XmlProlog::Create(const std::string& tagName)
|
||||
XmlPrologPtr XmlProlog::Create(const std::string& tagName)
|
||||
{
|
||||
return std::make_unique<XmlProlog>(tagName);
|
||||
}
|
||||
|
||||
XmlProlog::Encoding XmlProlog::GetEncoding() const
|
||||
XmlProlog::Encoding XmlProlog::getEncoding() const
|
||||
{
|
||||
return mEncoding;
|
||||
}
|
||||
|
||||
XmlProlog::Version XmlProlog::GetVersion() const
|
||||
XmlProlog::Version XmlProlog::getVersion() const
|
||||
{
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
void XmlProlog::SetEncoding(const std::string& encoding)
|
||||
void XmlProlog::setEncoding(const std::string& encoding)
|
||||
{
|
||||
if(encoding == "UTF-8")
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ void XmlProlog::SetEncoding(const std::string& encoding)
|
|||
}
|
||||
}
|
||||
|
||||
void XmlProlog::SetVersion(const std::string& version)
|
||||
void XmlProlog::setVersion(const std::string& version)
|
||||
{
|
||||
if(version == "1.0")
|
||||
{
|
||||
|
@ -40,15 +41,15 @@ void XmlProlog::SetVersion(const std::string& version)
|
|||
}
|
||||
}
|
||||
|
||||
void XmlProlog::Update()
|
||||
void XmlProlog::update()
|
||||
{
|
||||
if(const auto version = GetAttribute("version"))
|
||||
if(const auto version = getAttribute("version"))
|
||||
{
|
||||
SetVersion(version->GetValue());
|
||||
setVersion(version->getValue());
|
||||
}
|
||||
|
||||
if(const auto encoding = GetAttribute("encoding"))
|
||||
if(const auto encoding = getAttribute("encoding"))
|
||||
{
|
||||
SetEncoding(encoding->GetValue());
|
||||
setEncoding(encoding->getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "XmlElement.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class XmlProlog : public XmlElement
|
||||
{
|
||||
public:
|
||||
|
@ -15,23 +16,21 @@ public:
|
|||
UTF8
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
Version mVersion;
|
||||
Encoding mEncoding;
|
||||
|
||||
public:
|
||||
XmlProlog(const std::string& tagName);
|
||||
|
||||
static std::unique_ptr<XmlProlog> Create(const std::string& tagName);
|
||||
|
||||
Encoding GetEncoding() const;
|
||||
Version GetVersion() const;
|
||||
Encoding getEncoding() const;
|
||||
Version getVersion() const;
|
||||
|
||||
void SetEncoding(const std::string& encoding);
|
||||
void SetVersion(const std::string& version);
|
||||
void Update();
|
||||
void setEncoding(const std::string& encoding);
|
||||
void setVersion(const std::string& version);
|
||||
void update();
|
||||
|
||||
private:
|
||||
Version mVersion;
|
||||
Encoding mEncoding;
|
||||
};
|
||||
|
||||
using XmlPrologPtr = std::shared_ptr<XmlProlog>;
|
||||
using XmlPrologUPtr = std::unique_ptr<XmlProlog>;
|
||||
using XmlPrologPtr = std::unique_ptr<XmlProlog>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue