MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / withoutWindowsRoot

Function withoutWindowsRoot

Libraries/Plugin/Internal/PluginString.h:166–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164
165#if SC_PLATFORM_WINDOWS
166[[nodiscard]] constexpr StringSpan withoutWindowsRoot(StringSpan path)
167{
168 if (path.getEncoding() != StringEncoding::Utf16)
169 return path;
170 const size_t units = path.sizeInBytes() / sizeof(wchar_t);
171 const auto at = [&](size_t index) -> char
172 { return index < units ? path.bytesWithoutTerminator()[index * sizeof(wchar_t)] : 0; };
173 const auto isSeparator = [&](size_t index) { return at(index) == '\\' or at(index) == '/'; };
174 size_t rootUnits = 0;
175 if (units >= 3 and at(1) == ':' and isSeparator(2))
176 {
177 rootUnits = 3;
178 }
179 else if (units >= 2 and isSeparator(0) and isSeparator(1))
180 {
181 size_t index = 2;
182 if (units >= 4 and at(2) == '?' and isSeparator(3))
183 {
184 index = 4;
185 if (units >= 7 and at(5) == ':' and isSeparator(6))
186 rootUnits = 7;
187 }
188 if (rootUnits == 0)
189 {
190 while (index < units and not isSeparator(index))
191 ++index;
192 if (index < units)
193 ++index;
194 while (index < units and not isSeparator(index))
195 ++index;
196 rootUnits = index < units ? index + 1 : index;
197 }
198 }
199 else if (units > 0 and isSeparator(0))
200 {
201 rootUnits = 1;
202 }
203 return slice(path, rootUnits * sizeof(wchar_t), path.sizeInBytes() - rootUnits * sizeof(wchar_t));
204}
205#endif
206
207[[nodiscard]] inline bool append(StringPath& output, Span<const StringSpan> components)

Callers

nothing calls this directly

Calls 3

isSeparatorFunction · 0.85
sliceFunction · 0.85
sizeInBytesMethod · 0.45

Tested by

no test coverage detected