Anul 3 Semestrul 2
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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) => "/",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user