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

Merge pull request #123 from damianday/Path

Add Path.ChangeExtension
This commit is contained in:
Brian Fiete 2020-04-28 07:33:51 -07:00 committed by GitHub
commit 7911dde7cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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)