diff options
author | Peter Rice <peter@peterrice.xyz> | 2019-08-06 21:41:38 -0400 |
---|---|---|
committer | Peter Rice <peter@peterrice.xyz> | 2019-08-06 21:41:38 -0400 |
commit | e1e220c975e50cc159197ad9409278719e671ff7 (patch) | |
tree | 94bc8231b66f65b7d34d37cacdeee7116e4efbf9 /src/utility | |
parent | 2ff23ed71912a958f0ccd729d2a088aa660a71ea (diff) |
Escape single quotes in filenames
Diffstat (limited to 'src/utility')
-rw-r--r-- | src/utility/string.cpp | 12 | ||||
-rw-r--r-- | src/utility/string.h | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/utility/string.cpp b/src/utility/string.cpp index 837a6b7a..f82e6be7 100644 --- a/src/utility/string.cpp +++ b/src/utility/string.cpp @@ -96,3 +96,15 @@ void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible } } } + +void escapeSingleQuotes(std::string &filename) +{ + for (size_t i = 0; i < filename.length(); ++i) + { + if (filename[i] == '\'') + { + filename.replace(i, 1, "'\\''"); + i += 3; + } + } +} diff --git a/src/utility/string.h b/src/utility/string.h index f9910f4d..41616756 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -60,4 +60,6 @@ std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos) void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible); +void escapeSingleQuotes(std::string &filename); + #endif // NCMPCPP_UTILITY_STRING_H |