From da3efe8fa2a1125c3d59e2ccffb26e94587f2c11 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 8 Feb 2009 10:25:33 +0000 Subject: [PATCH] Improve fix made for Ticket #85 to handle strings that are in 3 parts also. --- src/tokenize.cpp | 2 +- test/testincompletestatement.cpp | 1 + test/testtokenize.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 269296022..61e78155d 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -556,7 +556,7 @@ void Tokenizer::simplifyTokenList() // Combine strings for (Token *tok = _tokens; tok; tok = tok->next()) { - if (tok->str()[0] == '"' && tok->next() && tok->next()->str()[0] == '"') + while (tok->str()[0] == '"' && tok->next() && tok->next()->str()[0] == '"') { // Two strings after each other, combine them std::string temp = tok->str(); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 812751bc4..bea823a53 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -107,6 +107,7 @@ private: "const char *a =\n" "{\n" "\"hello \"\n" + "\"more \"\n" "\"world\"\n" "};\n" "}\n"); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0d46c5280..b39a29b05 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -109,6 +109,7 @@ private: TEST_CASE(sizeof4); TEST_CASE(simplify_numeric_condition); TEST_CASE(tokenize_double); + TEST_CASE(tokenize_strings); } @@ -1008,6 +1009,30 @@ private: ostr << " " << tok->str(); ASSERT_EQUALS(std::string(" void f ( ) { double a = 4.2 ; float b = 4.2f ; }"), ostr.str()); } + + void tokenize_strings() + { + const char code[] = "void f()\n" + "{\n" + "const char *a =\n" + "{\n" + "\"hello \"\n" + "\"more \"\n" + "\"world\"\n" + "};\n" + "}\n"; + + // tokenize.. + OurTokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList(); + + std::ostringstream ostr; + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) + ostr << " " << tok->str(); + ASSERT_EQUALS(std::string(" void f ( ) { const char * a = { \"hello more world\" } ; }"), ostr.str()); + } }; REGISTER_TEST(TestTokenizer)