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

Method convert

Libraries/FileSystem/FileSystem.cpp:154–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154SC::Result SC::FileSystem::convert(const StringSpan file, StringPath& destination,
155 StringNativeBuffer<StringPath::MaxPath + 6 + 1>& transportPath,
156 StringSpan* encodedPath)
157{
158#if SC_PLATFORM_WINDOWS
159 SC_TRY(FileSystemWindowsDetail::WindowsPath::makeTransportPath(file, currentDirectory.view(), destination,
160 transportPath));
161 if (encodedPath != nullptr)
162 {
163 *encodedPath = transportPath.view();
164 }
165 return Result(true);
166#else
167 (void)(transportPath);
168 SC_TRY(destination.assign(file));
169 if (encodedPath)
170 {
171 *encodedPath = destination.view();
172 }
173
174 auto destinationBuffer = destination.writableSpan().data();
175 const bool absolute = not destination.view().isEmpty() and destinationBuffer[0] == '/';
176 if (absolute)
177 {
178 if (encodedPath != nullptr)
179 {
180 *encodedPath = destination.view();
181 }
182 return Result(true);
183 }
184 if (currentDirectory.view().isEmpty())
185 return Result(false);
186
187 StringPath relative = destination;
188 destination = currentDirectory;
189#if SC_PLATFORM_WINDOWS
190 const size_t destLen = destination.view().sizeInBytes() / sizeof(wchar_t);
191 const size_t relLen = relative.view().sizeInBytes() / sizeof(wchar_t);
192 destinationBuffer[destLen] = L'\\';
193 ::memcpy(destinationBuffer + destLen + 1, relative.view().bytesIncludingTerminator(), relLen * sizeof(wchar_t));
194#else
195 destinationBuffer[destination.view().sizeInBytes()] = '/';
196 ::memcpy(destinationBuffer + destination.view().sizeInBytes() + 1, relative.view().bytesWithoutTerminator(),
197 relative.view().sizeInBytes());
198#endif
199 const size_t lastPos =
200 (destination.view().sizeInBytes() + relative.view().sizeInBytes()) / sizeof(native_char_t) + 1;
201 destinationBuffer[lastPos] = 0;
202 (void)destination.resize(lastPos);
203 if (encodedPath != nullptr)
204 {
205 *encodedPath = destination.view();
206 }
207 return Result(true);
208#endif
209}
210
211#define SC_TRY_FORMAT_ERRNO(path, func) \

Callers

nothing calls this directly

Calls 8

writableSpanMethod · 0.80
ResultClass · 0.50
viewMethod · 0.45
assignMethod · 0.45
dataMethod · 0.45
isEmptyMethod · 0.45
sizeInBytesMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected