1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Add Path.ChangeExtension

This commit is contained in:
Damian Day 2020-04-19 16:45:28 +01:00
parent f77ccb8994
commit dcd9bc35ac

View file

@ -54,6 +54,34 @@ namespace System.IO
}
public static void ChangeExtension(StringView path, StringView ext, String outPath)
{
if (path.IsNull)
return;
CheckInvalidPathChars(path);
outPath.Set(path);
for (int i = path.Length; --i >= 0;)
{
let ch = path[i];
if (ch == '.')
{
outPath.Set(path.Substring(0, i));
break;
}
if (ch == DirectorySeparatorChar || ch == AltDirectorySeparatorChar || ch == VolumeSeparatorChar) break;
}
if (!ext.IsNull && path.Length != 0)
{
if (ext.IsEmpty || ext[0] != '.')
{
outPath.Append('.');
}
outPath.Append(ext);
}
}
public static void GetFileName(StringView inPath, String outFileName)
{
if (inPath.IsEmpty)