MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / makeCleanPathInPlace

Function makeCleanPathInPlace

Engine/source/platform/platformFileIO.cpp:246–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244#endif
245
246static void makeCleanPathInPlace( char* path )
247{
248 U32 pathDepth = 0;
249 char* fromPtr = path;
250 char* toPtr = path;
251
252 bool isAbsolute = false;
253 if( *fromPtr == '/' )
254 {
255 fromPtr ++;
256 toPtr ++;
257 isAbsolute = true;
258 }
259 else if( fromPtr[ 0 ] != '\0' && fromPtr[ 1 ] == ':' )
260 {
261 toPtr += 3;
262 fromPtr += 3;
263 isAbsolute = true;
264 }
265
266 while( *fromPtr )
267 {
268 if( fromPtr[ 0 ] == '.' && fromPtr[ 1 ] == '.' && fromPtr[ 2 ] == '/' )
269 {
270 // Back up from '../'
271
272 if( pathDepth > 0 )
273 {
274 pathDepth --;
275 toPtr -= 2;
276 while( toPtr >= path && *toPtr != '/' )
277 toPtr --;
278 toPtr ++;
279 }
280 else if( !isAbsolute )
281 {
282 dMemcpy( toPtr, fromPtr, 3 );
283 toPtr += 3;
284 }
285
286 fromPtr += 3;
287 }
288 else if( fromPtr[ 0 ] == '.' && fromPtr[ 1 ] == '/' )
289 {
290 // Ignore.
291 fromPtr += 2;
292 }
293 else
294 {
295 if( fromPtr[ 0 ] == '/' )
296 pathDepth ++;
297
298 *toPtr ++ = *fromPtr ++;
299 }
300 }
301
302 *toPtr = '\0';
303}

Callers 1

makeRelativePathNameMethod · 0.85

Calls 1

dMemcpyFunction · 0.50

Tested by

no test coverage detected