From 618076a65fec169a6017607a80e8b54b416c90f9 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Wed, 21 Jul 2010 14:16:42 +0300 Subject: [PATCH] Better fix for #1371. Now handles also system includes. And have couple of tests. --- lib/preprocessor.cpp | 9 ++++----- test/testpreprocessor.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 683247300..fad19c448 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1322,6 +1322,9 @@ Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str) result.append(1, str[i]); } + // Linux can't open include paths with \ separator, so fix them + std::replace(result.begin(), result.end(), '\\', '/'); + str = result; if (c == '"') return UserHeader; @@ -1397,11 +1400,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath if (headerType == UserHeader && !fileOpened) { filename = paths.back() + filename; - - // Linux can't open include paths with \ separator, so fix them - std::string fixedname(filename); - std::replace(fixedname.begin(), fixedname.end(), '\\', '/'); - fin.open(fixedname.c_str()); + fin.open(filename.c_str()); if (fin.is_open()) { fileOpened = true; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f7c504fdd..bd707091a 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2030,6 +2030,18 @@ private: ASSERT_EQUALS(OurPreprocessor::SystemHeader, OurPreprocessor::getHeaderFileName(src)); ASSERT_EQUALS("c.h", src); } + + { + std::string src = "#include \"d/d.h\""; + ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src)); + ASSERT_EQUALS("d/d.h", src); + } + + { + std::string src = "#include \"e\\e.h\""; + ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src)); + ASSERT_EQUALS("e/e.h", src); + } } void ifdef_ifdefined()