replace v6 with experimental v7 code

This commit is contained in:
stax76
2023-10-24 11:17:45 +02:00
parent fb27bb8727
commit 5706d7b66d
212 changed files with 15014 additions and 12173 deletions

View File

@@ -0,0 +1,67 @@

namespace MpvNet.ExtensionMethod;
public static class PathStringExtension
{
public static string Ext(this string filepath) => filepath.Ext(false);
public static string Ext(this string filepath, bool includeDot)
{
if (string.IsNullOrEmpty(filepath))
return "";
char[] chars = filepath.ToCharArray();
for (int x = filepath.Length - 1; x >= 0; x--)
{
if (chars[x] == Path.DirectorySeparatorChar)
return "";
if (chars[x] == '.')
return filepath.Substring(x + (includeDot ? 0 : 1)).ToLowerInvariant();
}
return "";
}
public static string FileName(this string instance)
{
if (string.IsNullOrEmpty(instance))
return "";
int index = instance.LastIndexOf('\\');
if (index > -1)
return instance.Substring(index + 1);
index = instance.LastIndexOf('/');
if (index > -1)
return instance.Substring(index + 1);
return instance;
}
public static string ShortPath(this string instance, int maxLength)
{
if (string.IsNullOrEmpty(instance))
return "";
if (instance.Length > maxLength && instance.Substring(1, 2) == ":\\")
instance = instance[..3] + "...\\" + instance.FileName();
return instance;
}
// Ensure trailing directory separator char
public static string AddSep(this string instance)
{
if (string.IsNullOrEmpty(instance))
return "";
if (!instance.EndsWith(Path.DirectorySeparatorChar.ToString()))
instance = instance + Path.DirectorySeparatorChar;
return instance;
}
}