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

View File

@ -83,7 +83,7 @@ private:
TEST_CASE(preprocessor_doublesharp); TEST_CASE(preprocessor_doublesharp);
TEST_CASE(preprocessor_include_in_str); TEST_CASE(preprocessor_include_in_str);
// TODO TEST_CASE(fmt); // TODO TEST_CASE(fmt);
// TODO TEST_CASE(multi_character_character); TEST_CASE(multi_character_character);
} }
@ -600,7 +600,7 @@ private:
// Compare results.. // Compare results..
ASSERT_EQUALS(1, actual.size()); 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[""]);
} }
}; };