Add Path::removeQuotationMarks() to clean path.

This commit is contained in:
Kimmo Varis 2011-03-28 22:14:19 +03:00
parent d539cf59ca
commit b889f663ae
3 changed files with 34 additions and 0 deletions

View File

@ -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); return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0);
#endif #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;
}

View File

@ -63,6 +63,13 @@ public:
* @return true if the filenames match on the current platform * @return true if the filenames match on the current platform
*/ */
static bool sameFileName(const std::string &fname1, const std::string &fname2); 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);
}; };
/// @} /// @}

View File

@ -35,6 +35,7 @@ private:
void simplify_path() void simplify_path()
{ {
// Path::simplifyPath()
ASSERT_EQUALS("index.h", Path::simplifyPath("index.h")); ASSERT_EQUALS("index.h", Path::simplifyPath("index.h"));
ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h")); ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h"));
ASSERT_EQUALS("/path/", Path::simplifyPath("/path/")); ASSERT_EQUALS("/path/", Path::simplifyPath("/path/"));
@ -49,6 +50,16 @@ private:
ASSERT_EQUALS("a/..", Path::simplifyPath("a/..")); 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"));
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\""));
} }
}; };