Add Path::removeQuotationMarks() to clean path.
This commit is contained in:
parent
d539cf59ca
commit
b889f663ae
16
lib/path.cpp
16
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);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -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\""));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue