MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / SanitizeFileName

Method SanitizeFileName

common/FileSystem.cpp:142–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142std::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
165void Path::SanitizeFileName(std::string* str, bool strip_slashes /* = true */)
166{

Callers

nothing calls this directly

Calls 10

DecodeUTF8Function · 0.85
EncodeAndAppendUTF8Function · 0.85
sizeFunction · 0.50
reserveMethod · 0.45
lengthMethod · 0.45
backMethod · 0.45
getMethod · 0.45
c_strMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected