27 lines
706 B
C#
27 lines
706 B
C#
using System;
|
|
|
|
namespace FileCompression.Utils;
|
|
|
|
public static class ArchiveUtils
|
|
{
|
|
public static string EntryFromPath(ReadOnlySpan<char> path, bool appendPathSeparator = false)
|
|
{
|
|
// Remove leading separators.
|
|
int nonSlash = path.IndexOfAnyExcept('/');
|
|
if (nonSlash < 0)
|
|
{
|
|
nonSlash = path.Length;
|
|
}
|
|
path = path.Slice(nonSlash);
|
|
|
|
// Append a separator if necessary.
|
|
return (path.IsEmpty, appendPathSeparator) switch
|
|
{
|
|
(false, false) => path.ToString(),
|
|
(false, true) => string.Concat(path, "/"),
|
|
(true, false) => string.Empty,
|
|
(true, true) => "/",
|
|
};
|
|
}
|
|
}
|