This commit is contained in:
Michael DiLeo 2025-07-06 17:54:19 +10:00 committed by GitHub
commit d28321bb1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 134 additions and 13 deletions

View file

@ -1,4 +1,6 @@
using System.IO;
using System;
using System.Globalization;
using System.IO;
namespace API.Extensions;
#nullable enable
@ -12,4 +14,23 @@ public static class PathExtensions
if (string.IsNullOrEmpty(extension)) return filepath;
return Path.GetFullPath(filepath.Replace(extension, string.Empty));
}
public static ReadOnlySpan<char> GetFirstSegmentSpan(this string urlKey)
{
var idx = urlKey.IndexOf('/');
return idx < 0 ? urlKey.AsSpan() : urlKey.AsSpan()[..idx];
}
public static ReadOnlySpan<char> GetLastSegmentSpan(this string urlKey)
{
var idx = urlKey.LastIndexOf('/');
return idx < 0 ? urlKey.AsSpan() : urlKey.AsSpan().Slice(idx + 1);
}
public static int? ParseInt(this ReadOnlySpan<char> s)
{
if (int.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var value))
return value;
return default;
}
}