Skip to content

Commit

Permalink
Merge pull request #1259 from lairworks/refactorXml
Browse files Browse the repository at this point in the history
Remove Clang `-Wpadded` warnings from XML code
  • Loading branch information
DanRStevens authored Mar 4, 2025
2 parents 10cc6bc + bf630ff commit fb1f006
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 44 deletions.
15 changes: 0 additions & 15 deletions NAS2D/Xml/XmlBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,6 @@ class XmlBase
ParseLocation location{};

private:
struct Entity
{
const char* str;
unsigned int strLength;
char chr;
};

enum
{
NUM_ENTITY = 5,
MAX_ENTITY_LENGTH = 6

};

static Entity entity[NUM_ENTITY];
static bool condenseWhiteSpace;
};

Expand Down
8 changes: 3 additions & 5 deletions NAS2D/Xml/XmlDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ class XmlDocument : public XmlNode

private:
XmlErrorCode _errorId{};

bool _error{};

std::string _errorDesc{};

XmlBase::ParseLocation _errorLocation{};
std::string _errorDesc{};
bool _error{};
char padding[7];
};

} // namespace Xml
Expand Down
2 changes: 1 addition & 1 deletion NAS2D/Xml/XmlMemoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline void line_break(const std::string& linebreak, std::string& buffer)
}


XmlMemoryBuffer::XmlMemoryBuffer() : depth(0), _indent("\t"), _lineBreak("\n")
XmlMemoryBuffer::XmlMemoryBuffer() : _indent("\t"), _lineBreak("\n"), depth(0)
{}


Expand Down
5 changes: 3 additions & 2 deletions NAS2D/Xml/XmlMemoryBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ class XmlMemoryBuffer : public XmlVisitor
const std::string& buffer();

private:
int depth;

std::string _buffer{};
std::string _indent;
std::string _lineBreak;
int depth;
protected:
int _padding{};
};

} // namespace Xml
Expand Down
8 changes: 4 additions & 4 deletions NAS2D/Xml/XmlNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ using namespace NAS2D::Xml;
XmlNode::XmlNode() :
XmlBase(),
_parent(nullptr),
_type(NodeType::XML_UNKNOWN),
_firstChild(nullptr),
_lastChild(nullptr),
_prev(nullptr),
_next(nullptr)
_next(nullptr),
_type(NodeType::XML_UNKNOWN)
{}


Expand All @@ -33,11 +33,11 @@ XmlNode::XmlNode() :
XmlNode::XmlNode(NodeType type) :
XmlBase(),
_parent(nullptr),
_type(type),
_firstChild(nullptr),
_lastChild(nullptr),
_prev(nullptr),
_next(nullptr)
_next(nullptr),
_type(type)
{}


Expand Down
8 changes: 3 additions & 5 deletions NAS2D/Xml/XmlNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,13 @@ class XmlNode : public XmlBase
XmlNode* identify(const char* start);

XmlNode* _parent;
NodeType _type;

XmlNode* _firstChild;
XmlNode* _lastChild;

std::string _value{};

XmlNode* _prev;
XmlNode* _next;
std::string _value{};
NodeType _type;
int _padding{};

private:
friend class XmlDocument;
Expand Down
35 changes: 23 additions & 12 deletions NAS2D/Xml/XmlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,36 @@ namespace
"Error parsing CDATA.",
"Error adding XmlDocument to document: XmlDocument can only be at the root.",
};

struct Entity
{
const char* str;
unsigned int strLength;
char chr;
};

enum
{
NUM_ENTITY = 5,
MAX_ENTITY_LENGTH = 6

};

Entity entity[NUM_ENTITY] =
{
{ "&", 5, '&' },
{ "&lt;", 4, '<' },
{ "&gt;", 4, '>' },
{ "&quot;", 6, '\"' },
{ "&apos;", 6, '\'' }
};
}


namespace NAS2D
{
namespace Xml {

// Note that "PutString" hardcodes the same list. This is less flexible
// than it appears. Changing the entries or order will break putstring.
XmlBase::Entity XmlBase::entity[ XmlBase::NUM_ENTITY ] =
{
{ "&amp;", 5, '&' },
{ "&lt;", 4, '<' },
{ "&gt;", 4, '>' },
{ "&quot;", 6, '\"' },
{ "&apos;", 6, '\'' }
};


int XmlBase::isAlpha(unsigned char anyByte)
{
if (anyByte < 127)
Expand Down
1 change: 1 addition & 0 deletions NAS2D/Xml/XmlText.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class XmlText : public XmlNode

private:
bool cdata{}; // true if this should be input and output as a CDATA style text element
char padding[7]{};
};

} // namespace Xml
Expand Down

0 comments on commit fb1f006

Please sign in to comment.