diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp
index 6c3979980..b6c70cded 100644
--- a/src/preprocessor.cpp
+++ b/src/preprocessor.cpp
@@ -719,13 +719,17 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
std::string Preprocessor::getHeaderFileName(const std::string &str)
{
std::string result;
- std::string::size_type i = str.find("\"");
+ std::string::size_type i = str.find_first_of("<\"");
if (i == std::string::npos)
return result;
+ char c = str[i];
+ if (c == '<')
+ c = '>';
+
for (i = i + 1; i < str.length(); ++i)
{
- if (str[i] == '"')
+ if (str[i] == c)
break;
result.append(1, str[i]);
diff --git a/src/preprocessor.h b/src/preprocessor.h
index 9d43f6195..699a02bd4 100644
--- a/src/preprocessor.h
+++ b/src/preprocessor.h
@@ -95,6 +95,13 @@ protected:
*/
static std::string removeComments(const std::string &str);
+ /**
+ * Returns the string between double quote characters or < > characters.
+ * @param str e.g. '#include "menu.h"' or '#include
'
+ * @return e.g. 'menu.h' or empty string if double quotes
+ * or < > were not found.
+ */
+ static std::string getHeaderFileName(const std::string &str);
private:
/**
@@ -128,13 +135,6 @@ private:
*/
static void handleIncludes(std::string &code, const std::string &filename, const std::list &includePaths);
- /**
- * Returns the string between double quote characters.
- * @param str e.g. '#include "menu.h"'
- * @return e.g. 'menu.h' or empty string if double quotes were
- * not found.
- */
- static std::string getHeaderFileName(const std::string &str);
};
//---------------------------------------------------------------------------
diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp
index 73e8ecf58..aae70f4ab 100644
--- a/test/testpreprocessor.cpp
+++ b/test/testpreprocessor.cpp
@@ -50,6 +50,11 @@ public:
{
return Preprocessor::expandMacros(code, "file.cpp", errorLogger);
}
+
+ static std::string getHeaderFileName(const std::string &str)
+ {
+ return Preprocessor::getHeaderFileName(str);
+ }
};
private:
@@ -126,6 +131,7 @@ private:
TEST_CASE(multiline_comment);
TEST_CASE(macro_parameters);
TEST_CASE(newline_in_macro);
+ TEST_CASE(includes);
}
@@ -1068,7 +1074,11 @@ private:
ASSERT_EQUALS("", errout.str());
}
-
+ void includes()
+ {
+ ASSERT_EQUALS("a.h", OurPreprocessor::getHeaderFileName("#include \"a.h\""));
+ ASSERT_EQUALS("a.h", OurPreprocessor::getHeaderFileName("#include "));
+ }
};
REGISTER_TEST(TestPreprocessor)