added whitespace=collapse support. tests work. code needs review

This commit is contained in:
Lee Thomason (grinliz)
2012-08-20 22:00:38 -07:00
parent 77d7f206f6
commit bc1bfb7f27
3 changed files with 90 additions and 13 deletions

View File

@@ -24,11 +24,21 @@ distribution.
#ifndef TINYXML2_INCLUDED
#define TINYXML2_INCLUDED
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstring>
#include <cstdarg>
#ifdef ANDROID_NDK
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#else
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#endif
/*
TODO: intern strings instead of allocation.
@@ -112,6 +122,7 @@ public:
enum {
NEEDS_ENTITY_PROCESSING = 0x01,
NEEDS_NEWLINE_NORMALIZATION = 0x02,
COLLAPSE_WHITESPACE = 0x04,
TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
@@ -140,6 +151,7 @@ public:
private:
void Reset();
void CollapseWhitespace();
enum {
NEEDS_FLUSH = 0x100,
@@ -365,6 +377,7 @@ public:
// correct, but simple, and usually works.
static const char* SkipWhiteSpace( const char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<const unsigned char*>(p) ) ) { ++p; } return p; }
static char* SkipWhiteSpace( char* p ) { while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast<unsigned char*>(p) ) ) { ++p; } return p; }
static bool IsWhiteSpace( char p ) { return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) ); }
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
int n = 0;
@@ -1031,6 +1044,12 @@ private:
};
enum Whitespace {
PRESERVE_WHITESPACE,
COLLAPSE_WHITESPACE
};
/** A Document binds together all the functionality.
It can be saved, loaded, and printed to the screen.
All Nodes are connected and allocated to a Document.
@@ -1041,7 +1060,7 @@ class XMLDocument : public XMLNode
friend class XMLElement;
public:
/// constructor
XMLDocument( bool processEntities = true );
XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE );
~XMLDocument();
virtual XMLDocument* ToDocument() { return this; }
@@ -1086,7 +1105,8 @@ public:
*/
int SaveFile( FILE* );
bool ProcessEntities() const { return processEntities; }
bool ProcessEntities() const { return processEntities; }
Whitespace WhitespaceMode() const { return whitespace; }
/**
Returns true if this document has a leading Byte Order Mark of UTF8.
@@ -1189,6 +1209,7 @@ private:
bool writeBOM;
bool processEntities;
int errorID;
Whitespace whitespace;
const char* errorStr1;
const char* errorStr2;
char* charBuffer;