diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 7e73c5550..81ad1158c 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -4291,8 +4291,11 @@ std::string Tokenizer::simplifyString(const std::string &source) // We will replace all other character as 'a' // If that causes problems in the future, this can // be improved. But for now, this should be OK. + int n = 1; + while (n < 2 && std::isxdigit(str[i+1+n])) + ++n; --i; - str.replace(i, 4, "a"); + str.replace(i, 2 + n, "a"); } } else if (MathLib::isOctalDigit(str[i])) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0fd69b9f3..2612b4637 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -158,6 +158,8 @@ private: TEST_CASE(removeExceptionSpecification); TEST_CASE(gt); // use "<" comparisons instead of ">" + + TEST_CASE(simplifyString); } @@ -2542,6 +2544,16 @@ private: ASSERT_EQUALS("; i < 10 ;", tokenizeAndStringify(";10>i;")); } + + void simplifyString() + { + Tokenizer *tokenizer = 0; + ASSERT_EQUALS("\"abc\"", tokenizer->simplifyString("\"abc\"")); + ASSERT_EQUALS("\"a\"", tokenizer->simplifyString("\"\\x3\"")); + ASSERT_EQUALS("\"a\"", tokenizer->simplifyString("\"\\x33\"")); + ASSERT_EQUALS("\"a3\"", tokenizer->simplifyString("\"\\x333\"")); + } + }; REGISTER_TEST(TestTokenizer)