Path methods fixes

This commit is contained in:
Timerix22 2023-04-04 23:17:29 +06:00
parent 555f4759a8
commit a76077de99
2 changed files with 9 additions and 5 deletions

View File

@ -28,12 +28,16 @@ public readonly struct IOPath
static string FixSeparators(char[] path) static string FixSeparators(char[] path)
{ {
int length = path.Length; int length = path.Length;
if (path[path.Length-1]==Path.Sep || path[path.Length-1]==Path.NotSep) if (path[length-1] == Path.Sep || path[length-1] == Path.NotSep)
length--; // removing trailing sep length--; // removing trailing sep
char[] fixed_path = new char[length];
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{
if (path[i] == Path.NotSep) if (path[i] == Path.NotSep)
path[i] = Path.Sep; fixed_path[i] = Path.Sep;
return new string(path); else fixed_path[i] = path[i];
}
return new string(fixed_path);
} }
public static IOPath[] ArrayCast(string[] a) public static IOPath[] ArrayCast(string[] a)

View File

@ -147,6 +147,6 @@ public static class Path
{ {
if (!path.StartsWith(baseDir)) if (!path.StartsWith(baseDir))
throw new Exception($"path <{path}> doesnt starts with <{baseDir}"); throw new Exception($"path <{path}> doesnt starts with <{baseDir}");
return path.Substring(baseDir.Length); return path.Substring(baseDir.Length+1);
} }
} }