-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Replace library functions(isalpha & isspace) #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -561,22 +561,28 @@ class TINYXML2_LIB XMLUtil | |||||
| static char* SkipWhiteSpace( char* const p, int* curLineNumPtr ) { | ||||||
| return const_cast<char*>( SkipWhiteSpace( const_cast<const char*>(p), curLineNumPtr ) ); | ||||||
| } | ||||||
| inline static bool IsSpace( unsigned char ch ) { | ||||||
| static constexpr uint64_t mask = | ||||||
| 1ULL << 9 | ||||||
| | 1ULL << 10 | ||||||
| | 1ULL << 11 | ||||||
| | 1ULL << 12 | ||||||
| | 1ULL << 13 | ||||||
| | 1ULL << 32; | ||||||
| if ( ch > 32 ) { | ||||||
| return false; | ||||||
| } | ||||||
| return mask >> ch & 1; | ||||||
| } | ||||||
|
Comment on lines
+564
to
+576
|
||||||
|
|
||||||
| // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't | ||||||
| // correct, but simple, and usually works. | ||||||
| static bool IsWhiteSpace( char p ) { | ||||||
| return !IsUTF8Continuation(p) && isspace( static_cast<unsigned char>(p) ); | ||||||
| return IsSpace( static_cast<unsigned char>(p) ); | ||||||
| } | ||||||
|
|
||||||
| // The method checks a char for matching ':', '_', alphabetic symbols or char >= 128 by bit mask | ||||||
|
||||||
| // The method checks a char for matching ':', '_', alphabetic symbols or char >= 128 by bit mask | |
| // The method checks a char for matching ':', '_', alphabetic symbols or char >= 128 by bit mask |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2729,6 +2729,26 @@ int main( int argc, const char ** argv ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ---------- Testing IsNameStartChar ---------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLUtil test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Tests validate key edge cases for IsNameStartChar without exhaustive coverage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar(':')", true, test.IsNameStartChar(':')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('_')", true, test.IsNameStartChar('_')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('@')", false, test.IsNameStartChar('@')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('A')", true, test.IsNameStartChar('A')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('Z')", true, test.IsNameStartChar('Z')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('[')", false, test.IsNameStartChar('[')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('`')", false, test.IsNameStartChar('`')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('a')", true, test.IsNameStartChar('a')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('z')", true, test.IsNameStartChar('z')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar('{')", false, test.IsNameStartChar('{')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar(127)", false, test.IsNameStartChar(static_cast<unsigned char>(127))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar(128)", true, test.IsNameStartChar(static_cast<unsigned char>(128))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XMLTest("IsNameStartChar(255)", true, test.IsNameStartChar(static_cast<unsigned char>(255))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2733
to
+2750
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ---------- Testing IsNameStartChar ---------- | |
| { | |
| XMLUtil test; | |
| // Tests validate key edge cases for IsNameStartChar without exhaustive coverage | |
| XMLTest("IsNameStartChar(':')", true, test.IsNameStartChar(':')); | |
| XMLTest("IsNameStartChar('_')", true, test.IsNameStartChar('_')); | |
| XMLTest("IsNameStartChar('@')", false, test.IsNameStartChar('@')); | |
| XMLTest("IsNameStartChar('A')", true, test.IsNameStartChar('A')); | |
| XMLTest("IsNameStartChar('Z')", true, test.IsNameStartChar('Z')); | |
| XMLTest("IsNameStartChar('[')", false, test.IsNameStartChar('[')); | |
| XMLTest("IsNameStartChar('`')", false, test.IsNameStartChar('`')); | |
| XMLTest("IsNameStartChar('a')", true, test.IsNameStartChar('a')); | |
| XMLTest("IsNameStartChar('z')", true, test.IsNameStartChar('z')); | |
| XMLTest("IsNameStartChar('{')", false, test.IsNameStartChar('{')); | |
| XMLTest("IsNameStartChar(127)", false, test.IsNameStartChar(static_cast<unsigned char>(127))); | |
| XMLTest("IsNameStartChar(128)", true, test.IsNameStartChar(static_cast<unsigned char>(128))); | |
| XMLTest("IsNameStartChar(255)", true, test.IsNameStartChar(static_cast<unsigned char>(255))); | |
| } | |
| // ---------- Testing IsNameStartChar ---------- | |
| { | |
| XMLUtil test; | |
| // Tests validate key edge cases for IsNameStartChar without exhaustive coverage | |
| XMLTest("IsNameStartChar(':')", true, test.IsNameStartChar(':')); | |
| XMLTest("IsNameStartChar('_')", true, test.IsNameStartChar('_')); | |
| XMLTest("IsNameStartChar('@')", false, test.IsNameStartChar('@')); | |
| XMLTest("IsNameStartChar('A')", true, test.IsNameStartChar('A')); | |
| XMLTest("IsNameStartChar('Z')", true, test.IsNameStartChar('Z')); | |
| XMLTest("IsNameStartChar('[')", false, test.IsNameStartChar('[')); | |
| XMLTest("IsNameStartChar('`')", false, test.IsNameStartChar('`')); | |
| XMLTest("IsNameStartChar('a')", true, test.IsNameStartChar('a')); | |
| XMLTest("IsNameStartChar('z')", true, test.IsNameStartChar('z')); | |
| XMLTest("IsNameStartChar('{')", false, test.IsNameStartChar('{')); | |
| XMLTest("IsNameStartChar(127)", false, test.IsNameStartChar(static_cast<unsigned char>(127))); | |
| XMLTest("IsNameStartChar(128)", true, test.IsNameStartChar(static_cast<unsigned char>(128))); | |
| XMLTest("IsNameStartChar(255)", true, test.IsNameStartChar(static_cast<unsigned char>(255))); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parentheses in bitwise operation. The expression
mask >> ch & 1is evaluated asmask >> (ch & 1)due to operator precedence, not(mask >> ch) & 1as intended. This will produce incorrect results for most inputs.Fix:
return (mask >> ch) & 1;