mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Add path normalization function.
This commit is contained in:
parent
165cc22115
commit
8cc43284bd
@ -699,6 +699,62 @@ static void InitKernelSymbols()
|
||||
}
|
||||
#endif
|
||||
|
||||
char* NormalizePath( const char* path )
|
||||
{
|
||||
if( path[0] != '/' ) return nullptr;
|
||||
|
||||
const char* ptr = path;
|
||||
const char* end = path;
|
||||
while( *end ) end++;
|
||||
|
||||
char* res = (char*)tracy_malloc( end - ptr + 1 );
|
||||
size_t rsz = 0;
|
||||
|
||||
while( ptr < end )
|
||||
{
|
||||
const char* next = ptr;
|
||||
while( next < end && *next != '/' ) next++;
|
||||
size_t lsz = next - ptr;
|
||||
switch( lsz )
|
||||
{
|
||||
case 2:
|
||||
if( memcmp( ptr, "..", 2 ) == 0 )
|
||||
{
|
||||
const char* back = res + rsz - 1;
|
||||
while( back > res && *back != '/' ) back--;
|
||||
rsz = back - res;
|
||||
ptr = next + 1;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( *ptr == '.' )
|
||||
{
|
||||
ptr = next + 1;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
ptr = next + 1;
|
||||
continue;
|
||||
}
|
||||
if( rsz != 1 ) res[rsz++] = '/';
|
||||
memcpy( res+rsz, ptr, lsz );
|
||||
rsz += lsz;
|
||||
ptr = next + 1;
|
||||
}
|
||||
|
||||
if( rsz == 0 )
|
||||
{
|
||||
memcpy( res, "/", 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
res[rsz] = '\0';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void InitCallstackCritical()
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user