antioch-0.4.0
List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
tinyxml2::StrPair Class Reference

#include <tinyxml2.h>

Public Types

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, 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 char * GetStr ()
 
bool Empty () const
 
void SetInternedStr (const char *str)
 
void SetStr (const char *str, int flags=0)
 
char * ParseText (char *in, const char *endTag, int strFlags)
 
char * ParseName (char *in)
 

Private Types

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

Private Member Functions

void Reset ()
 
void CollapseWhitespace ()
 

Private Attributes

int flags
 
char * start
 
char * end
 

Detailed Description

Definition at line 119 of file tinyxml2.h.

Member Enumeration Documentation

anonymous enum
anonymous enum
private
Enumerator
NEEDS_FLUSH 
NEEDS_DELETE 

Definition at line 156 of file tinyxml2.h.

156  {
157  NEEDS_FLUSH = 0x100,
158  NEEDS_DELETE = 0x200
159  };

Constructor & Destructor Documentation

tinyxml2::StrPair::StrPair ( )
inline

Definition at line 135 of file tinyxml2.h.

135 : flags( 0 ), start( 0 ), end( 0 ) {}
StrPair::~StrPair ( )
inline

Definition at line 89 of file tinyxml2_imp.h.

References Reset().

90 {
91  Reset();
92 }

Member Function Documentation

void StrPair::CollapseWhitespace ( )
inlineprivate

Definition at line 168 of file tinyxml2_imp.h.

References tinyxml2::XMLUtil::IsWhiteSpace(), tinyxml2::XMLUtil::SkipWhiteSpace(), and start.

Referenced by GetStr().

169 {
170  // Trim leading space.
172 
173  if ( start && *start ) {
174  char* p = start; // the read pointer
175  char* q = start; // the write pointer
176 
177  while( *p ) {
178  if ( XMLUtil::IsWhiteSpace( *p )) {
179  p = XMLUtil::SkipWhiteSpace( p );
180  if ( *p == 0 )
181  break; // don't write to q; this trims the trailing space.
182  *q = ' ';
183  ++q;
184  }
185  *q = *p;
186  ++q;
187  ++p;
188  }
189  *q = 0;
190  }
191 }
static bool IsWhiteSpace(char p)
Definition: tinyxml2.h:382
static const char * SkipWhiteSpace(const char *p)
Definition: tinyxml2.h:380
bool tinyxml2::StrPair::Empty ( ) const
inline

Definition at line 143 of file tinyxml2.h.

References end, and start.

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

143 { return start == end; }
const char * StrPair::GetStr ( )
inline

Definition at line 195 of file tinyxml2_imp.h.

References COLLAPSE_WHITESPACE, CollapseWhitespace(), end, flags, tinyxml2::XMLUtil::GetCharacterRef(), Entity::length, NEEDS_DELETE, NEEDS_ENTITY_PROCESSING, NEEDS_FLUSH, NEEDS_NEWLINE_NORMALIZATION, start, TIXMLASSERT, and Entity::value.

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

196 {
197  if ( flags & NEEDS_FLUSH ) {
198  *end = 0;
199  flags ^= NEEDS_FLUSH;
200 
201  if ( flags ) {
202  char* p = start; // the read pointer
203  char* q = start; // the write pointer
204 
205  while( p < end ) {
206  if ( (flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) {
207  // CR-LF pair becomes LF
208  // CR alone becomes LF
209  // LF-CR becomes LF
210  if ( *(p+1) == LF ) {
211  p += 2;
212  }
213  else {
214  ++p;
215  }
216  *q++ = LF;
217  }
218  else if ( (flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) {
219  if ( *(p+1) == CR ) {
220  p += 2;
221  }
222  else {
223  ++p;
224  }
225  *q++ = LF;
226  }
227  else if ( (flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) {
228  // Entities handled by tinyXML2:
229  // - special entities in the entity table [in/out]
230  // - numeric character reference [in]
231  // &#20013; or &#x4e2d;
232 
233  if ( *(p+1) == '#' ) {
234  char buf[10] = { 0 };
235  int len;
236  p = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
237  for( int i=0; i<len; ++i ) {
238  *q++ = buf[i];
239  }
240  TIXMLASSERT( q <= p );
241  }
242  else {
243  int i=0;
244  for(; i<NUM_ENTITIES; ++i ) {
245  if ( strncmp( p+1, entities[i].pattern, entities[i].length ) == 0
246  && *(p+entities[i].length+1) == ';' )
247  {
248  // Found an entity convert;
249  *q = entities[i].value;
250  ++q;
251  p += entities[i].length + 2;
252  break;
253  }
254  }
255  if ( i == NUM_ENTITIES ) {
256  // fixme: treat as error?
257  ++p;
258  ++q;
259  }
260  }
261  }
262  else {
263  *q = *p;
264  ++p;
265  ++q;
266  }
267  }
268  *q = 0;
269  }
270  // The loop below has plenty going on, and this
271  // is a less useful mode. Break it out.
272  if ( flags & COLLAPSE_WHITESPACE ) {
274  }
275  flags = (flags & NEEDS_DELETE);
276  }
277  return start;
278 }
#define TIXMLASSERT(x)
Definition: tinyxml2.h:68
static const char * GetCharacterRef(const char *p, char *value, int *length)
Definition: tinyxml2_imp.h:345
char value
Definition: tinyxml2_imp.h:74
int length
Definition: tinyxml2_imp.h:73
void CollapseWhitespace()
Definition: tinyxml2_imp.h:168
char * StrPair::ParseName ( char *  in)
inline

Definition at line 141 of file tinyxml2_imp.h.

References tinyxml2::XMLUtil::IsAlphaNum(), Set(), and start.

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

142 {
143  char* start = p;
144 
145  if ( !start || !(*start) ) {
146  return 0;
147  }
148 
149  while( *p && (
150  XMLUtil::IsAlphaNum( (unsigned char) *p )
151  || *p == '_'
152  || *p == ':'
153  || (*p == '-' && p>start ) // can be in a name, but not lead it.
154  || (*p == '.' && p>start ) )) // can be in a name, but not lead it.
155  {
156  ++p;
157  }
158 
159  if ( p > start ) {
160  Set( start, p, 0 );
161  return p;
162  }
163  return 0;
164 }
void Set(char *_start, char *_end, int _flags)
Definition: tinyxml2.h:138
static int IsAlphaNum(unsigned char anyByte)
Definition: tinyxml2.h:398
char * StrPair::ParseText ( char *  in,
const char *  endTag,
int  strFlags 
)
inline

Definition at line 120 of file tinyxml2_imp.h.

References Set(), start, and TIXMLASSERT.

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

121 {
122  TIXMLASSERT( endTag && *endTag );
123 
124  char* start = p; // fixme: hides a member
125  char endChar = *endTag;
126  size_t length = strlen( endTag );
127 
128  // Inner loop of text parsing.
129  while ( *p ) {
130  if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) {
131  Set( start, p, strFlags );
132  return p + length;
133  }
134  ++p;
135  }
136  return 0;
137 }
#define TIXMLASSERT(x)
Definition: tinyxml2.h:68
void Set(char *_start, char *_end, int _flags)
Definition: tinyxml2.h:138
void StrPair::Reset ( )
inlineprivate

Definition at line 96 of file tinyxml2_imp.h.

References end, flags, NEEDS_DELETE, and start.

Referenced by Set(), SetInternedStr(), SetStr(), and ~StrPair().

97 {
98  if ( flags & NEEDS_DELETE ) {
99  delete [] start;
100  }
101  flags = 0;
102  start = 0;
103  end = 0;
104 }
void tinyxml2::StrPair::Set ( char *  _start,
char *  _end,
int  _flags 
)
inline

Definition at line 138 of file tinyxml2.h.

References end, flags, NEEDS_FLUSH, Reset(), and start.

Referenced by ParseName(), and ParseText().

138  {
139  Reset();
140  this->start = _start; this->end = _end; this->flags = _flags | NEEDS_FLUSH;
141  }
void tinyxml2::StrPair::SetInternedStr ( const char *  str)
inline

Definition at line 145 of file tinyxml2.h.

References Reset(), and start.

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

145 { Reset(); this->start = const_cast<char*>(str); }
void StrPair::SetStr ( const char *  str,
int  flags = 0 
)
inline

Definition at line 108 of file tinyxml2_imp.h.

References end, NEEDS_DELETE, Reset(), and start.

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

109 {
110  Reset();
111  size_t len = strlen( str );
112  start = new char[ len+1 ];
113  memcpy( start, str, len+1 );
114  end = start + len;
115  this->flags = flags | NEEDS_DELETE;
116 }

Member Data Documentation

char* tinyxml2::StrPair::end
private

Definition at line 164 of file tinyxml2.h.

Referenced by Empty(), GetStr(), Reset(), Set(), and SetStr().

int tinyxml2::StrPair::flags
private

Definition at line 162 of file tinyxml2.h.

Referenced by GetStr(), Reset(), and Set().

char* tinyxml2::StrPair::start
private

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

Generated on Thu Jul 7 2016 11:09:52 for antioch-0.4.0 by  doxygen 1.8.8