From b7e4f1319c49866372368a4ce0a468d3b62b17e8 Mon Sep 17 00:00:00 2001 From: Nicolas Le Cam Date: Wed, 21 Jan 2009 21:45:17 +0000 Subject: [PATCH] Fix Preprocessor::read to handle char constant of more than one char, fixing issue #45; Fix the test that handle the case. --- src/preprocessor.cpp | 25 +++++++++++++------------ test/testpreprocessor.cpp | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index bea3467b0..32cb5a478 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -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 << "\'"; } - +*/ // .. else if (ch == '\\') { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 44f5b26a1..efa8cf226 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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[""]); } };