Implement new utility functions for testing validity of name and token characters.
diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 647901b..2c06a46 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -136,12 +136,7 @@
return 0;
}
- while( *p && (
- XMLUtil::IsAlphaNum( (unsigned char) *p )
- || *p == '_'
- || *p == ':'
- || (*p == '-' && p>start ) // can be in a name, but not lead it.
- || (*p == '.' && p>start ) )) { // can be in a name, but not lead it.
+ while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) {
++p;
}
@@ -1357,7 +1352,7 @@
}
// attribute.
- if ( XMLUtil::IsAlpha( *p ) ) {
+ if (XMLUtil::IsNameStartChar( *p ) ) {
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
attrib->_memPool = &_document->_attributePool;
attrib->_memPool->SetTracked();
diff --git a/tinyxml2.h b/tinyxml2.h
index 0f8e9ad..698412a 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -464,6 +464,19 @@
static bool IsWhiteSpace( char p ) {
return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) );
}
+
+ inline static bool IsNameStartChar( unsigned char ch ) {
+ return ( ( ch < 128 ) ? isalpha( ch ) : 1 )
+ || ch == ':'
+ || ch == '_';
+ }
+
+ inline static bool IsNameChar( unsigned char ch ) {
+ return IsNameStartChar( ch )
+ || isdigit( ch )
+ || ch == '.'
+ || ch == '-';
+ }
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {
int n = 0;
@@ -480,15 +493,10 @@
}
return false;
}
+
inline static int IsUTF8Continuation( const char p ) {
return p & 0x80;
}
- inline static int IsAlphaNum( unsigned char anyByte ) {
- return ( anyByte < 128 ) ? isalnum( anyByte ) : 1;
- }
- inline static int IsAlpha( unsigned char anyByte ) {
- return ( anyByte < 128 ) ? isalpha( anyByte ) : 1;
- }
static const char* ReadBOM( const char* p, bool* hasBOM );
// p is the starting location,