4343#define SIMPLECPP_WINDOWS
4444#endif
4545
46+ static bool isHex (const std::string &s) {
47+ return s.size ()>2 && (s.compare (0 ,2 ," 0x" )==0 || s.compare (0 ,2 ," 0X" )==0 );
48+ }
49+
4650namespace {
4751 const simplecpp::TokenString DEFINE (" define" );
4852 const simplecpp::TokenString UNDEF (" undef" );
@@ -73,7 +77,7 @@ namespace {
7377 long long stringToLL (const std::string &s)
7478 {
7579 long long ret;
76- const bool hex = (s. length ()> 2 && s. compare ( 0 , 2 , " 0x " ) == 0 );
80+ const bool hex = isHex (s );
7781 std::istringstream istr (hex ? s.substr (2 ) : s);
7882 if (hex)
7983 istr >> std::hex;
@@ -84,7 +88,7 @@ namespace {
8488 unsigned long long stringToULL (const std::string &s)
8589 {
8690 unsigned long long ret;
87- const bool hex = (s. length ()> 2 && s. compare ( 0 , 2 , " 0x " ) == 0 );
91+ const bool hex = isHex (s );
8892 std::istringstream istr (hex ? s.substr (2 ) : s);
8993 if (hex)
9094 istr >> std::hex;
@@ -585,6 +589,14 @@ void simplecpp::TokenList::constFold()
585589 }
586590}
587591
592+ static bool isFloatSuffix (const simplecpp::Token *tok) {
593+ if (!tok || tok->str .size () > 2 )
594+ return false ;
595+ std::string s = tok->str ;
596+ std::transform (s.begin (), s.end (), s.begin (), static_cast <int (*)(int )>(std::tolower));
597+ return s == " lf" || s == " f" ;
598+ }
599+
588600void simplecpp::TokenList::combineOperators ()
589601{
590602 for (Token *tok = front (); tok; tok = tok->next ) {
@@ -597,7 +609,7 @@ void simplecpp::TokenList::combineOperators()
597609 if (tok->previous && tok->previous ->number ) {
598610 tok->setstr (tok->previous ->str + ' .' );
599611 deleteToken (tok->previous );
600- if (tok->next && tok->next ->startsWithOneOf (" Ee" )) {
612+ if (isFloatSuffix ( tok->next ) || (tok-> next && tok->next ->startsWithOneOf (" Ee" ) )) {
601613 tok->setstr (tok->str + tok->next ->str );
602614 deleteToken (tok->next );
603615 }
@@ -609,7 +621,7 @@ void simplecpp::TokenList::combineOperators()
609621 }
610622 // match: [0-9.]+E [+-] [0-9]+
611623 const char lastChar = tok->str [tok->str .size () - 1 ];
612- if (tok->number && tok->str . compare ( 0 , 2 , " 0x " , 0 , 2 ) != 0 && (lastChar == ' E' || lastChar == ' e' ) && tok->next && tok->next ->isOneOf (" +-" ) && tok->next ->next && tok->next ->next ->number ) {
624+ if (tok->number && ! isHex ( tok->str ) && (lastChar == ' E' || lastChar == ' e' ) && tok->next && tok->next ->isOneOf (" +-" ) && tok->next ->next && tok->next ->next ->number ) {
613625 tok->setstr (tok->str + tok->next ->op + tok->next ->next ->str );
614626 deleteToken (tok->next );
615627 deleteToken (tok->next );
0 commit comments