mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Cleanup fsTinyXml implementation
This commit is contained in:
parent
5abd66dfa3
commit
3ef57168b2
|
|
@ -266,21 +266,21 @@ void VfsXMLDocument::SetError(tinyxml2::XMLError error, int lineNum, const char*
|
|||
// Overwrite Visitation of elements to add newlines before attributes
|
||||
PrettyXMLPrinter::PrettyXMLPrinter(VfsXMLPrinter& innerPrinter, int depth)
|
||||
: mInnerPrinter(innerPrinter),
|
||||
_depth(depth)
|
||||
mDepth(depth)
|
||||
{
|
||||
for (int i = 0; i < ENTITY_RANGE; ++i) {
|
||||
_entityFlag[i] = false;
|
||||
_restrictedEntityFlag[i] = false;
|
||||
mEntityFlag[i] = false;
|
||||
mRestrictedEntityFlag[i] = false;
|
||||
}
|
||||
for (int i = 0; i < NUM_ENTITIES; ++i) {
|
||||
const char entityValue = entities[i].value;
|
||||
const unsigned char flagIndex = static_cast<unsigned char>(entityValue);
|
||||
TIXMLASSERT(flagIndex < ENTITY_RANGE);
|
||||
_entityFlag[flagIndex] = true;
|
||||
mEntityFlag[flagIndex] = true;
|
||||
}
|
||||
_restrictedEntityFlag[static_cast<unsigned char>('&')] = true;
|
||||
_restrictedEntityFlag[static_cast<unsigned char>('<')] = true;
|
||||
_restrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice
|
||||
mRestrictedEntityFlag[static_cast<unsigned char>('&')] = true;
|
||||
mRestrictedEntityFlag[static_cast<unsigned char>('<')] = true;
|
||||
mRestrictedEntityFlag[static_cast<unsigned char>('>')] = true; // not required, but consistency is nice
|
||||
}
|
||||
|
||||
void PrettyXMLPrinter::PrintString(const char* p, bool restricted)
|
||||
|
|
@ -288,8 +288,8 @@ void PrettyXMLPrinter::PrintString(const char* p, bool restricted)
|
|||
// Look for runs of bytes between entities to print.
|
||||
const char* q = p;
|
||||
|
||||
if (_processEntities) {
|
||||
const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;
|
||||
if (mProcessEntities) {
|
||||
const bool* flag = restricted ? mRestrictedEntityFlag : mEntityFlag;
|
||||
while (*q) {
|
||||
TIXMLASSERT(p <= q);
|
||||
// Remember, char is sometimes signed. (How many times has that bitten me?)
|
||||
|
|
@ -345,7 +345,7 @@ bool PrettyXMLPrinter::VisitEnter(const tinyxml2::XMLElement& element, const tin
|
|||
}
|
||||
const bool compactMode = parentElem ? mInnerPrinter.CompactMode(*parentElem) : mInnerPrinter.CompactMode(element);
|
||||
mInnerPrinter.OpenElement(element.Name(), compactMode);
|
||||
_depth++;
|
||||
mDepth++;
|
||||
while (attribute) {
|
||||
PushAttribute(attribute->Name(), attribute->Value(), compactMode);
|
||||
attribute = attribute->Next();
|
||||
|
|
@ -362,7 +362,7 @@ void PrettyXMLPrinter::PushAttribute(const char* name, const char* value, bool c
|
|||
else
|
||||
{
|
||||
mInnerPrinter.Putc('\n');
|
||||
mInnerPrinter.PrintSpace(_depth);
|
||||
mInnerPrinter.PrintSpace(mDepth);
|
||||
}
|
||||
mInnerPrinter.Write(name);
|
||||
mInnerPrinter.Write("=\"");
|
||||
|
|
|
|||
|
|
@ -40,34 +40,19 @@ public:
|
|||
VfsXMLPrinter(FileStream& stream, bool compact = false, int depth = 0);
|
||||
~VfsXMLPrinter() override;
|
||||
|
||||
// Re-implement private functionality in TinyXML2 library, this is just a copy-paste job
|
||||
// Re-implement protected functionality in TinyXML2 library, and make it public
|
||||
// (This is a bit dirty, but it's necessary for the PrettyXMLPrinter)
|
||||
bool CompactMode(const tinyxml2::XMLElement& element) override { return tinyxml2::XMLPrinter::CompactMode(element); }
|
||||
void PrintSpace(int depth) override { tinyxml2::XMLPrinter::PrintSpace(depth); }
|
||||
inline void Write(const char* data) { Write(data, strlen(data)); }
|
||||
|
||||
// Add VFS friendly implementations of output functions
|
||||
void Print(const char* format, ...) override;
|
||||
void Write(const char* data, size_t size) override;
|
||||
inline void Write(const char* data) { Write(data, strlen(data)); }
|
||||
void Putc(char ch) override;
|
||||
void PrintSpace(int depth) override { tinyxml2::XMLPrinter::PrintSpace(depth); }
|
||||
|
||||
// Overwrite Visitation of elements to add newlines before attributes
|
||||
void PushAttribute(const char* name, const char* value, bool compactMode);
|
||||
|
||||
// Accept a virtual FileStream instead of a FILE pointer
|
||||
FileStream& m_Stream;
|
||||
|
||||
// Track private fields that are necessary for private functionality in TinyXML2
|
||||
int _depth;
|
||||
bool _processEntities;
|
||||
|
||||
enum
|
||||
{
|
||||
ENTITY_RANGE = 64,
|
||||
BUF_SIZE = 200
|
||||
};
|
||||
|
||||
bool _entityFlag[ENTITY_RANGE];
|
||||
bool _restrictedEntityFlag[ENTITY_RANGE];
|
||||
};
|
||||
|
||||
class VfsXMLDocument : public tinyxml2::XMLDocument
|
||||
|
|
@ -182,7 +167,7 @@ public:
|
|||
/// Visit a document.
|
||||
virtual bool VisitEnter(const tinyxml2::XMLDocument& doc)
|
||||
{
|
||||
_processEntities = doc.ProcessEntities();
|
||||
mProcessEntities = doc.ProcessEntities();
|
||||
return mInnerPrinter.VisitEnter(doc);
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +182,7 @@ public:
|
|||
/// Visit an element.
|
||||
virtual bool VisitExit(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
_depth--;
|
||||
mDepth--;
|
||||
return mInnerPrinter.VisitExit(element);
|
||||
}
|
||||
|
||||
|
|
@ -224,17 +209,20 @@ public:
|
|||
{
|
||||
return mInnerPrinter.Visit(unknown);
|
||||
}
|
||||
|
||||
|
||||
void PushAttribute(const char* name, const char* value, bool compactMode);
|
||||
|
||||
// Re-implement private functionality in TinyXML2 library, this is just a copy-paste job
|
||||
void PrintString(const char*, bool restrictedEntitySet); // prints out, after detecting entities.
|
||||
|
||||
// The inner printer we are wrapping, we only support VfsXMLPrinter based classes because
|
||||
// stock tinyxml printer is very closed
|
||||
VfsXMLPrinter& mInnerPrinter;
|
||||
|
||||
// Track private fields that are necessary for private functionality in TinyXML2
|
||||
int _depth;
|
||||
bool _processEntities;
|
||||
bool _compactMode;
|
||||
int mDepth;
|
||||
bool mProcessEntities;
|
||||
bool mCompactMode;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -242,8 +230,8 @@ public:
|
|||
BUF_SIZE = 200
|
||||
};
|
||||
|
||||
bool _entityFlag[ENTITY_RANGE];
|
||||
bool _restrictedEntityFlag[ENTITY_RANGE];
|
||||
bool mEntityFlag[ENTITY_RANGE];
|
||||
bool mRestrictedEntityFlag[ENTITY_RANGE];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue