ReactOS  0.4.12-dev-14-gd0c8636
tinyxml2::StrPair Class Reference

#include <tinyxml2.h>

Collaboration diagram for tinyxml2::StrPair:

Public Types

enum  {
  NEEDS_ENTITY_PROCESSING = 0x01, NEEDS_NEWLINE_NORMALIZATION = 0x02, NEEDS_WHITESPACE_COLLAPSING = 0x04, TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
  TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, ATTRIBUTE_NAME = 0, ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
  COMMENT = NEEDS_NEWLINE_NORMALIZATION
}
 

Public Member Functions

 StrPair ()
 
 ~StrPair ()
 
void Set (char *start, char *end, int flags)
 
const charGetStr ()
 
bool Empty () const
 
void SetInternedStr (const char *str)
 
void SetStr (const char *str, int flags=0)
 
charParseText (char *in, const char *endTag, int strFlags)
 
charParseName (char *in)
 
void TransferTo (StrPair *other)
 

Private Types

enum  { NEEDS_FLUSH = 0x100, NEEDS_DELETE = 0x200 }
 

Private Member Functions

void Reset ()
 
void CollapseWhitespace ()
 
 StrPair (const StrPair &other)
 
void operator= (StrPair &other)
 

Private Attributes

int _flags
 
char_start
 
char_end
 

Detailed Description

Definition at line 116 of file tinyxml2.h.

Member Enumeration Documentation

◆ anonymous enum

◆ anonymous enum

anonymous enum
private
Enumerator
NEEDS_FLUSH 
NEEDS_DELETE 

Definition at line 164 of file tinyxml2.h.

Constructor & Destructor Documentation

◆ StrPair() [1/2]

tinyxml2::StrPair::StrPair ( )
inline

Definition at line 132 of file tinyxml2.h.

132 : _flags( 0 ), _start( 0 ), _end( 0 ) {}

◆ ~StrPair()

tinyxml2::StrPair::~StrPair ( )

Definition at line 138 of file tinyxml2.cpp.

Referenced by StrPair().

139 {
140  Reset();
141 }

◆ StrPair() [2/2]

tinyxml2::StrPair::StrPair ( const StrPair other)
private

Member Function Documentation

◆ CollapseWhitespace()

void tinyxml2::StrPair::CollapseWhitespace ( )
private

Definition at line 231 of file tinyxml2.cpp.

Referenced by SetInternedStr().

232 {
233  // Adjusting _start would cause undefined behavior on delete[]
234  TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
235  // Trim leading space.
237 
238  if ( *_start ) {
239  char* p = _start; // the read pointer
240  char* q = _start; // the write pointer
241 
242  while( *p ) {
243  if ( XMLUtil::IsWhiteSpace( *p )) {
244  p = XMLUtil::SkipWhiteSpace( p );
245  if ( *p == 0 ) {
246  break; // don't write to q; this trims the trailing space.
247  }
248  *q = ' ';
249  ++q;
250  }
251  *q = *p;
252  ++q;
253  ++p;
254  }
255  *q = 0;
256  }
257 }
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:519
static bool IsWhiteSpace(char p)
Definition: tinyxml2.h:533
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
GLfloat GLfloat p
Definition: glext.h:8902

◆ Empty()

bool tinyxml2::StrPair::Empty ( ) const
inline

Definition at line 144 of file tinyxml2.h.

Referenced by tinyxml2::XMLNode::ParseDeep(), and tinyxml2::XMLElement::ParseDeep().

144  {
145  return _start == _end;
146  }

◆ GetStr()

const char * tinyxml2::StrPair::GetStr ( )

Definition at line 260 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLNode::ParseDeep(), Set(), tinyxml2::XMLNode::Value(), and tinyxml2::XMLAttribute::Value().

261 {
262  TIXMLASSERT( _start );
263  TIXMLASSERT( _end );
264  if ( _flags & NEEDS_FLUSH ) {
265  *_end = 0;
266  _flags ^= NEEDS_FLUSH;
267 
268  if ( _flags ) {
269  char* p = _start; // the read pointer
270  char* q = _start; // the write pointer
271 
272  while( p < _end ) {
273  if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
274  // CR-LF pair becomes LF
275  // CR alone becomes LF
276  // LF-CR becomes LF
277  if ( *(p+1) == LF ) {
278  p += 2;
279  }
280  else {
281  ++p;
282  }
283  *q++ = LF;
284  }
285  else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
286  if ( *(p+1) == CR ) {
287  p += 2;
288  }
289  else {
290  ++p;
291  }
292  *q++ = LF;
293  }
294  else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
295  // Entities handled by tinyXML2:
296  // - special entities in the entity table [in/out]
297  // - numeric character reference [in]
298  // &#20013; or &#x4e2d;
299 
300  if ( *(p+1) == '#' ) {
301  const int buflen = 10;
302  char buf[buflen] = { 0 };
303  int len = 0;
304  char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
305  if ( adjusted == 0 ) {
306  *q = *p;
307  ++p;
308  ++q;
309  }
310  else {
311  TIXMLASSERT( 0 <= len && len <= buflen );
312  TIXMLASSERT( q + len <= adjusted );
313  p = adjusted;
314  memcpy( q, buf, len );
315  q += len;
316  }
317  }
318  else {
319  bool entityFound = false;
320  for( int i = 0; i < NUM_ENTITIES; ++i ) {
321  const Entity& entity = entities[i];
322  if ( strncmp( p + 1, entity.pattern, entity.length ) == 0
323  && *( p + entity.length + 1 ) == ';' ) {
324  // Found an entity - convert.
325  *q = entity.value;
326  ++q;
327  p += entity.length + 2;
328  entityFound = true;
329  break;
330  }
331  }
332  if ( !entityFound ) {
333  // fixme: treat as error?
334  ++p;
335  ++q;
336  }
337  }
338  }
339  else {
340  *q = *p;
341  ++p;
342  ++q;
343  }
344  }
345  *q = 0;
346  }
347  // The loop below has plenty going on, and this
348  // is a less useful mode. Break it out.
351  }
352  _flags = (_flags & NEEDS_DELETE);
353  }
354  TIXMLASSERT( _start );
355  return _start;
356 }
void CollapseWhitespace()
Definition: tinyxml2.cpp:231
static const char * GetCharacterRef(const char *p, char *value, int *length)
Definition: tinyxml2.cpp:430
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static const Entity entities[NUM_ENTITIES]
Definition: tinyxml2.cpp:129
GLenum GLclampf GLint i
Definition: glfuncs.h:14
Definition: actctx.c:371
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
static const int NUM_ENTITIES
Definition: tinyxml2.cpp:128
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
static const char CR
Definition: tinyxml2.cpp:107
static const char LF
Definition: tinyxml2.cpp:105
GLfloat GLfloat p
Definition: glext.h:8902

◆ operator=()

◆ ParseName()

char * tinyxml2::StrPair::ParseName ( char in)

Definition at line 211 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLElement::ParseDeep(), and SetInternedStr().

212 {
213  if ( !p || !(*p) ) {
214  return 0;
215  }
216  if ( !XMLUtil::IsNameStartChar( *p ) ) {
217  return 0;
218  }
219 
220  char* const start = p;
221  ++p;
222  while ( *p && XMLUtil::IsNameChar( *p ) ) {
223  ++p;
224  }
225 
226  Set( start, p, 0 );
227  return p;
228 }
void Set(char *start, char *end, int flags)
Definition: tinyxml2.h:135
static bool IsNameChar(unsigned char ch)
Definition: tinyxml2.h:548
GLuint start
Definition: gl.h:1545
static bool IsNameStartChar(unsigned char ch)
Definition: tinyxml2.h:537
GLfloat GLfloat p
Definition: glext.h:8902

◆ ParseText()

char * tinyxml2::StrPair::ParseText ( char in,
const char endTag,
int  strFlags 
)

Definition at line 191 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLText::ParseDeep(), tinyxml2::XMLComment::ParseDeep(), tinyxml2::XMLDeclaration::ParseDeep(), tinyxml2::XMLUnknown::ParseDeep(), tinyxml2::XMLAttribute::ParseDeep(), and SetInternedStr().

192 {
193  TIXMLASSERT( endTag && *endTag );
194 
195  char* start = p;
196  char endChar = *endTag;
197  size_t length = strlen( endTag );
198 
199  // Inner loop of text parsing.
200  while ( *p ) {
201  if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
202  Set( start, p, strFlags );
203  return p + length;
204  }
205  ++p;
206  }
207  return 0;
208 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
void Set(char *start, char *end, int flags)
Definition: tinyxml2.h:135
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88
GLuint start
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902

◆ Reset()

void tinyxml2::StrPair::Reset ( void  )
private

Definition at line 167 of file tinyxml2.cpp.

Referenced by Set(), SetInternedStr(), and TransferTo().

168 {
169  if ( _flags & NEEDS_DELETE ) {
170  delete [] _start;
171  }
172  _flags = 0;
173  _start = 0;
174  _end = 0;
175 }

◆ Set()

void tinyxml2::StrPair::Set ( char start,
char end,
int  flags 
)
inline

Definition at line 135 of file tinyxml2.h.

135  {
136  Reset();
137  _start = start;
138  _end = end;
140  }
GLuint GLuint end
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
GLuint start
Definition: gl.h:1545

◆ SetInternedStr()

void tinyxml2::StrPair::SetInternedStr ( const char str)
inline

Definition at line 148 of file tinyxml2.h.

Referenced by tinyxml2::XMLNode::SetValue().

148  {
149  Reset();
150  _start = const_cast<char*>(str);
151  }
const WCHAR * str

◆ SetStr()

void tinyxml2::StrPair::SetStr ( const char str,
int  flags = 0 
)

Definition at line 178 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLAttribute::SetAttribute(), SetInternedStr(), and tinyxml2::XMLNode::SetValue().

179 {
180  TIXMLASSERT( str );
181  Reset();
182  size_t len = strlen( str );
183  TIXMLASSERT( _start == 0 );
184  _start = new char[ len+1 ];
185  memcpy( _start, str, len+1 );
186  _end = _start + len;
188 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const WCHAR * str
GLbitfield flags
Definition: glext.h:7161
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

◆ TransferTo()

void tinyxml2::StrPair::TransferTo ( StrPair other)

Definition at line 144 of file tinyxml2.cpp.

Referenced by tinyxml2::XMLNode::ParseDeep(), and SetInternedStr().

145 {
146  if ( this == other ) {
147  return;
148  }
149  // This in effect implements the assignment operator by "moving"
150  // ownership (as in auto_ptr).
151 
152  TIXMLASSERT( other->_flags == 0 );
153  TIXMLASSERT( other->_start == 0 );
154  TIXMLASSERT( other->_end == 0 );
155 
156  other->Reset();
157 
158  other->_flags = _flags;
159  other->_start = _start;
160  other->_end = _end;
161 
162  _flags = 0;
163  _start = 0;
164  _end = 0;
165 }
int other
Definition: msacm.c:1364
#define TIXMLASSERT(x)
Definition: tinyxml2.h:88

Member Data Documentation

◆ _end

char* tinyxml2::StrPair::_end
private

Definition at line 171 of file tinyxml2.h.

Referenced by Empty(), Set(), and TransferTo().

◆ _flags

int tinyxml2::StrPair::_flags
private

Definition at line 169 of file tinyxml2.h.

Referenced by Set(), and TransferTo().

◆ _start

char* tinyxml2::StrPair::_start
private

Definition at line 170 of file tinyxml2.h.

Referenced by Empty(), Set(), SetInternedStr(), and TransferTo().


The documentation for this class was generated from the following files: