diff --git a/lib/path.cpp b/lib/path.cpp index 6660e5089..0a042f95e 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -114,3 +114,19 @@ bool Path::sameFileName(const std::string &fname1, const std::string &fname2) return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0); #endif } + +std::string Path::removeQuotationMarks(const std::string &path) +{ + size_t pos = path.length() - 1; + std::string editPath(path); + while (pos != std::string::npos) + { + pos = editPath.rfind('\"', pos); + if (pos != std::string::npos) + { + editPath.erase(pos, 1); + --pos; + } + } + return editPath; +} diff --git a/lib/path.h b/lib/path.h index 2de7a1653..1607723c1 100644 --- a/lib/path.h +++ b/lib/path.h @@ -63,6 +63,13 @@ public: * @return true if the filenames match on the current platform */ static bool sameFileName(const std::string &fname1, const std::string &fname2); + + /** + * @brief Remove quotation marks (") from the path. + * @param originalPath path to be cleaned. + * @return Cleaned path without quotation marks. + */ + static std::string removeQuotationMarks(const std::string &path); }; /// @} diff --git a/test/testpath.cpp b/test/testpath.cpp index c52251b41..8e529ee7e 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -35,6 +35,7 @@ private: void simplify_path() { + // Path::simplifyPath() ASSERT_EQUALS("index.h", Path::simplifyPath("index.h")); ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h")); ASSERT_EQUALS("/path/", Path::simplifyPath("/path/")); @@ -49,6 +50,16 @@ private: ASSERT_EQUALS("a/..", Path::simplifyPath("a/..")); ASSERT_EQUALS("../../src/test.cpp", Path::simplifyPath("../../src/test.cpp")); ASSERT_EQUALS("../../../src/test.cpp", Path::simplifyPath("../../../src/test.cpp")); + + // Path::removeQuotationMarks() + ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("index.cpp")); + ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("\"index.cpp")); + ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("index.cpp\"")); + ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("\"index.cpp\"")); + ASSERT_EQUALS("path to/index.cpp", Path::removeQuotationMarks("\"path to\"/index.cpp")); + ASSERT_EQUALS("path to/index.cpp", Path::removeQuotationMarks("\"path to/index.cpp\"")); + ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("the/\"path to\"/index.cpp")); + ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("\"the/path to/index.cpp\"")); } };