Fix Preprocessor::read to handle char constant of more than one char, fixing issue #45; Fix the test that handle the case.

This commit is contained in:
Nicolas Le Cam 2009-01-21 21:45:17 +00:00
parent 42c608b6f0
commit b7e4f1319c
2 changed files with 15 additions and 14 deletions

View File

@ -120,30 +120,31 @@ std::string Preprocessor::read(std::istream &istr)
}
}
// String constants..
else if (ch == '\"')
// String or char constants..
else if (ch == '\"' || ch == '\'')
{
code << "\"";
code << std::string(1, ch);
char chNext;
do
{
ch = (char)istr.get();
if (ch == '\\')
chNext = (char)istr.get();
if (chNext == '\\')
{
char chNext = readChar(istr);
if (chNext == '\n')
char chSeq = readChar(istr);
if (chSeq == '\n')
++newlines;
else
{
code << std::string(1, ch);
code << std::string(1, chNext);
code << std::string(1, chSeq);
}
}
else
code << std::string(1, ch);
code << std::string(1, chNext);
}
while (istr.good() && ch != '\"');
while (istr.good() && chNext != ch);
}
/*
// char constants..
else if (ch == '\'')
{
@ -158,7 +159,7 @@ std::string Preprocessor::read(std::istream &istr)
ch = readChar(istr);
code << "\'";
}
*/
// <backspace><newline>..
else if (ch == '\\')
{

View File

@ -83,7 +83,7 @@ private:
TEST_CASE(preprocessor_doublesharp);
TEST_CASE(preprocessor_include_in_str);
// TODO TEST_CASE(fmt);
// TODO TEST_CASE(multi_character_character);
TEST_CASE(multi_character_character);
}
@ -600,7 +600,7 @@ private:
// Compare results..
ASSERT_EQUALS(1, actual.size());
ASSERT_EQUALS("#define FOO 'ABCD'\nint main()\n{\nif( 'ABCD' == 0 );\nreturn 0;\n}\n", actual[""]);
ASSERT_EQUALS("\nint main()\n{\nif( 'ABCD' == 0 );\nreturn 0;\n}\n", actual[""]);
}
};