mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 17:08:00 +02:00
Fix GetExtension
and add HasExtension
to Path
This commit is contained in:
parent
4d82420212
commit
77b4ddce89
1 changed files with 47 additions and 4 deletions
|
@ -303,11 +303,54 @@ namespace System.IO
|
||||||
|
|
||||||
public static Result<void> GetExtension(StringView inPath, String outExt)
|
public static Result<void> GetExtension(StringView inPath, String outExt)
|
||||||
{
|
{
|
||||||
int i;
|
if (inPath.IsEmpty)
|
||||||
if ((i = inPath.LastIndexOf('.')) != -1)
|
return .Err;
|
||||||
outExt.Append(inPath, i);
|
|
||||||
|
CheckInvalidPathChars(inPath);
|
||||||
|
|
||||||
|
for (int i = inPath.Length; --i >= 0;)
|
||||||
|
{
|
||||||
|
char8 ch = inPath[i];
|
||||||
|
if (ch == '.')
|
||||||
|
{
|
||||||
|
if (i != inPath.Length - 1)
|
||||||
|
{
|
||||||
|
outExt.Append(inPath.Substring(i, inPath.Length - i));
|
||||||
return .Ok;
|
return .Ok;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ch == DirectorySeparatorChar || ch == AltDirectorySeparatorChar || ch == VolumeSeparatorChar)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return .Err;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasExtension(StringView path)
|
||||||
|
{
|
||||||
|
if (path.IsEmpty)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CheckInvalidPathChars(path);
|
||||||
|
|
||||||
|
for (int i = path.Length; --i >= 0;)
|
||||||
|
{
|
||||||
|
char8 ch = path[i];
|
||||||
|
if (ch == '.')
|
||||||
|
{
|
||||||
|
if (i != path.Length - 1)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ch == DirectorySeparatorChar || ch == AltDirectorySeparatorChar || ch == VolumeSeparatorChar)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static Result<void> GetTempPath(String outPath)
|
public static Result<void> GetTempPath(String outPath)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue