Skip to content

Commit b889f66

Browse files
committed
Add Path::removeQuotationMarks() to clean path.
1 parent d539cf5 commit b889f66

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/path.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,19 @@ bool Path::sameFileName(const std::string &fname1, const std::string &fname2)
114114
return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0);
115115
#endif
116116
}
117+
118+
std::string Path::removeQuotationMarks(const std::string &path)
119+
{
120+
size_t pos = path.length() - 1;
121+
std::string editPath(path);
122+
while (pos != std::string::npos)
123+
{
124+
pos = editPath.rfind('\"', pos);
125+
if (pos != std::string::npos)
126+
{
127+
editPath.erase(pos, 1);
128+
--pos;
129+
}
130+
}
131+
return editPath;
132+
}

lib/path.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class Path
6363
* @return true if the filenames match on the current platform
6464
*/
6565
static bool sameFileName(const std::string &fname1, const std::string &fname2);
66+
67+
/**
68+
* @brief Remove quotation marks (") from the path.
69+
* @param originalPath path to be cleaned.
70+
* @return Cleaned path without quotation marks.
71+
*/
72+
static std::string removeQuotationMarks(const std::string &path);
6673
};
6774

6875
/// @}

test/testpath.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TestPath : public TestFixture
3535

3636
void simplify_path()
3737
{
38+
// Path::simplifyPath()
3839
ASSERT_EQUALS("index.h", Path::simplifyPath("index.h"));
3940
ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h"));
4041
ASSERT_EQUALS("/path/", Path::simplifyPath("/path/"));
@@ -49,6 +50,16 @@ class TestPath : public TestFixture
4950
ASSERT_EQUALS("a/..", Path::simplifyPath("a/.."));
5051
ASSERT_EQUALS("../../src/test.cpp", Path::simplifyPath("../../src/test.cpp"));
5152
ASSERT_EQUALS("../../../src/test.cpp", Path::simplifyPath("../../../src/test.cpp"));
53+
54+
// Path::removeQuotationMarks()
55+
ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("index.cpp"));
56+
ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("\"index.cpp"));
57+
ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("index.cpp\""));
58+
ASSERT_EQUALS("index.cpp", Path::removeQuotationMarks("\"index.cpp\""));
59+
ASSERT_EQUALS("path to/index.cpp", Path::removeQuotationMarks("\"path to\"/index.cpp"));
60+
ASSERT_EQUALS("path to/index.cpp", Path::removeQuotationMarks("\"path to/index.cpp\""));
61+
ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("the/\"path to\"/index.cpp"));
62+
ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("\"the/path to/index.cpp\""));
5263
}
5364
};
5465

0 commit comments

Comments
 (0)