Fix ticket #212 (Tokenizer: Handle L "text")

http://apps.sourceforge.net/trac/cppcheck/ticket/212
This commit is contained in:
Reijo Tomperi 2009-04-05 22:21:38 +03:00
parent 051f2929b5
commit 51d97fa831
2 changed files with 33 additions and 0 deletions

View File

@ -808,6 +808,17 @@ void Tokenizer::simplifyTokenList()
simplifyNamespaces();
// Combine wide strings
for (Token *tok = _tokens; tok; tok = tok->next())
{
while (tok->str() == "L" && tok->next() && tok->next()->str()[0] == '"')
{
// Combine 'L "string"'
tok->str(tok->next()->str().c_str());
tok->deleteNext();
}
}
// Combine strings
for (Token *tok = _tokens; tok; tok = tok->next())
{

View File

@ -91,6 +91,7 @@ private:
// "if(0==x)" => "if(!x)"
TEST_CASE(ifnot);
TEST_CASE(combine_wstrings);
}
std::string tok(const char code[])
@ -212,6 +213,27 @@ private:
ASSERT_EQUALS(tok(code2), tok(code1));
}
void combine_wstrings()
{
const char code1[] = "void foo()\n"
"{\n"
"const wchar_t *a =\n"
"{\n"
"L\"hello \"\n"
"L\"world\"\n"
"};\n"
"}\n";
const char code2[] = "void foo()\n"
"{\n"
"const wchar_t *a =\n"
"{\n"
"\"hello world\"\n"
"};\n"
"}\n";
ASSERT_EQUALS(tok(code2), tok(code1));
}
void double_plus()
{
{