| 98 | |
| 99 | template <typename T> |
| 100 | static inline void PathAppendString(std::string& dst, const T& src) |
| 101 | { |
| 102 | if (dst.capacity() < (dst.length() + src.length())) |
| 103 | dst.reserve(dst.length() + src.length()); |
| 104 | |
| 105 | bool last_separator = (!dst.empty() && dst.back() == FS_OSPATH_SEPARATOR_CHARACTER); |
| 106 | |
| 107 | size_t index = 0; |
| 108 | |
| 109 | #ifdef _WIN32 |
| 110 | // special case for UNC paths here |
| 111 | if (dst.empty() && src.length() >= 3 && src[0] == '\\' && src[1] == '\\' && src[2] != '\\') |
| 112 | { |
| 113 | dst.append("\\\\"); |
| 114 | index = 2; |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | for (; index < src.length(); index++) |
| 119 | { |
| 120 | const char ch = src[index]; |
| 121 | |
| 122 | #ifdef _WIN32 |
| 123 | // convert forward slashes to backslashes |
| 124 | if (ch == '\\' || ch == '/') |
| 125 | #else |
| 126 | if (ch == '/') |
| 127 | #endif |
| 128 | { |
| 129 | if (last_separator) |
| 130 | continue; |
| 131 | last_separator = true; |
| 132 | dst.push_back(FS_OSPATH_SEPARATOR_CHARACTER); |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | last_separator = false; |
| 137 | dst.push_back(ch); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | std::string Path::SanitizeFileName(const std::string_view str, bool strip_slashes /* = true */) |
| 143 | { |
no test coverage detected