| 140 | } |
| 141 | |
| 142 | std::string Path::SanitizeFileName(const std::string_view str, bool strip_slashes /* = true */) |
| 143 | { |
| 144 | std::string ret; |
| 145 | ret.reserve(str.length()); |
| 146 | |
| 147 | size_t pos = 0; |
| 148 | while (pos < str.length()) |
| 149 | { |
| 150 | char32_t ch; |
| 151 | pos += StringUtil::DecodeUTF8(str, pos, &ch); |
| 152 | ch = FileSystemCharacterIsSane(ch, strip_slashes) ? ch : U'_'; |
| 153 | StringUtil::EncodeAndAppendUTF8(ret, ch); |
| 154 | } |
| 155 | |
| 156 | #ifdef _WIN32 |
| 157 | // Windows: Can't end filename with a period. |
| 158 | if (ret.length() > 0 && ret.back() == '.') |
| 159 | ret.back() = '_'; |
| 160 | #endif |
| 161 | |
| 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | void Path::SanitizeFileName(std::string* str, bool strip_slashes /* = true */) |
| 166 | { |
nothing calls this directly
no test coverage detected