Files
School/Anul 3/Semestrul 2/Design Patterns/FileCompression/Utils/ArchiveUtils.cs
T
2025-07-03 20:56:38 +03:00

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) => "/",
};
}
}