mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Add helper: rdcstr standardise_directory_separator(const rdcstr &path);
Replaces all directory separators combinations with '/' i.e. '\' -> '/' '//' -> '/'
This commit is contained in:
@@ -141,6 +141,29 @@ rdcstr strip_extension(const rdcstr &path)
|
||||
return path.substr(0, offs);
|
||||
}
|
||||
|
||||
rdcstr standardise_directory_separator(const rdcstr &path)
|
||||
{
|
||||
// Replace '\' -> '/'
|
||||
// Replace '//' -> '/'
|
||||
rdcstr ret;
|
||||
ret.reserve(path.size());
|
||||
int slashCount = 0;
|
||||
for(size_t i = 0; i < path.size(); ++i)
|
||||
{
|
||||
char c = path[i];
|
||||
if(c == '\\')
|
||||
c = '/';
|
||||
|
||||
if(c == '/')
|
||||
slashCount++;
|
||||
else
|
||||
slashCount = 0;
|
||||
if(slashCount < 2)
|
||||
ret.push_back(c);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void strip_nonbasic(rdcstr &str)
|
||||
{
|
||||
for(char &c : str)
|
||||
@@ -339,6 +362,17 @@ TEST_CASE("String manipulation", "[string]")
|
||||
CHECK(strip_extension("bar/foo.exe") == "bar/foo");
|
||||
};
|
||||
|
||||
SECTION("standardise_directory_separator")
|
||||
{
|
||||
CHECK(standardise_directory_separator("a/exe.ext") == "a/exe.ext");
|
||||
CHECK(standardise_directory_separator("a\\exe.ext") == "a/exe.ext");
|
||||
CHECK(standardise_directory_separator("a//exe.ext") == "a/exe.ext");
|
||||
CHECK(standardise_directory_separator("a\\\\exe.ext") == "a/exe.ext");
|
||||
CHECK(standardise_directory_separator("a\\b/exe.ext") == "a/b/exe.ext");
|
||||
CHECK(standardise_directory_separator("a\\/b/\\exe.ext") == "a/b/exe.ext");
|
||||
CHECK(standardise_directory_separator("a\\\\/b//exe.ext") == "a/b/exe.ext");
|
||||
};
|
||||
|
||||
SECTION("strupper")
|
||||
{
|
||||
CHECK(strupper("foobar") == "FOOBAR");
|
||||
|
||||
@@ -37,6 +37,10 @@ rdcstr get_basename(const rdcstr &path);
|
||||
rdcstr get_dirname(const rdcstr &path);
|
||||
rdcstr strip_extension(const rdcstr &path);
|
||||
|
||||
// Replace all directory separators combinations with '/'
|
||||
// i.e. '\' -> '/' and '//' -> '/'
|
||||
rdcstr standardise_directory_separator(const rdcstr &path);
|
||||
|
||||
// remove everything but alphanumeric ' ' and '.'
|
||||
// It replaces everything else with _
|
||||
// for logging strings where they might contain garbage characters
|
||||
|
||||
Reference in New Issue
Block a user