minor changes to hex parsing

This commit is contained in:
Lee Thomason
2020-06-13 17:35:21 -07:00
parent c9c9d8cdfa
commit 18468b8cc4
3 changed files with 11 additions and 13 deletions

View File

@@ -591,10 +591,8 @@ public:
} }
inline static bool IsPrefixHex( const char* p) { inline static bool IsPrefixHex( const char* p) {
while (p && *p != '\0' && !isdigit(*p)) { p = SkipWhiteSpace(p, 0);
++p; return p && *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
}
return *p == '0' && ( *(p + 1) == 'x' || *(p + 1) == 'X');
} }
inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) {

View File

@@ -1675,21 +1675,21 @@ int main( int argc, const char ** argv )
} }
{ {
//API:IntText(),UnsignedText(),Int64Text(), hex value test // hex value test
const char* xml = "<point> <IntText> -0x2020</IntText> <UnsignedText>0x2020</UnsignedText> \ const char* xml = "<point> <IntText> 0x2020</IntText> <UnsignedText>0X2020</UnsignedText> \
<Int64Text> +0x1234</Int64Text></point>"; <Int64Text> 0x1234</Int64Text></point>";
XMLDocument doc; XMLDocument doc;
doc.Parse(xml); doc.Parse(xml);
const XMLElement* pointElement = doc.RootElement(); const XMLElement* pointElement = doc.RootElement();
int test1 = pointElement->FirstChildElement("IntText")->IntText(); int test1 = pointElement->FirstChildElement("IntText")->IntText();
XMLTest("IntText() hex value test", -0x2020, test1); XMLTest("IntText() hex value test", 0x2020, test1);
unsigned test2 = pointElement->FirstChildElement("UnsignedText")->UnsignedText(); unsigned test2 = pointElement->FirstChildElement("UnsignedText")->UnsignedText();
XMLTest("UnsignedText() hex value test", static_cast<unsigned>(0x2020), test2); XMLTest("UnsignedText() hex value test", static_cast<unsigned>(0x2020), test2);
int64_t test3 = pointElement->FirstChildElement("Int64Text")->Int64Text(); int64_t test3 = pointElement->FirstChildElement("Int64Text")->Int64Text();
XMLTest("Int64Text() hex value test", static_cast<int64_t>(+0x1234), test3); XMLTest("Int64Text() hex value test", static_cast<int64_t>(0x1234), test3);
} }
{ {