Skip to content

Commit

Permalink
added ReadOnlySpan overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
koliva8245 committed Jan 11, 2024
1 parent 00d87d1 commit 523759f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Heroes.MpqTool/MpqHeroesArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,20 @@ public void GetHeaderBytes(Span<byte> buffer)
/// <returns>An <see cref="MpqHeroesArchiveEntry"/>.</returns>
/// <exception cref="FileNotFoundException">The <paramref name="fileName"/> was not found.</exception>
public MpqHeroesArchiveEntry GetEntry(string fileName)
{
return GetEntry(fileName.AsSpan());
}

/// <summary>
/// Gets a <see cref="MpqHeroesArchiveEntry"/> by its file name.
/// </summary>
/// <param name="fileName">The name of the archive entry.</param>
/// <returns>An <see cref="MpqHeroesArchiveEntry"/>.</returns>
/// <exception cref="FileNotFoundException">The <paramref name="fileName"/> was not found.</exception>
public MpqHeroesArchiveEntry GetEntry(ReadOnlySpan<char> fileName)
{
if (!TryGetEntry(fileName, out MpqHeroesArchiveEntry? entry))
throw new FileNotFoundException("File not found: " + fileName);
throw new FileNotFoundException("File not found", fileName.ToString());

return entry.Value;
}
Expand All @@ -137,6 +148,17 @@ public MpqHeroesArchiveEntry GetEntry(string fileName)
/// <param name="mpqHeroesArchiveEntry">When this method returns, contains the <see cref="MpqHeroesArchiveEntry"/>.</param>
/// <returns><see langword="true"/> if the value was found; otherwise <see langword="false"/>.</returns>
public bool TryGetEntry(string fileName, [NotNullWhen(true)] out MpqHeroesArchiveEntry? mpqHeroesArchiveEntry)
{
return TryGetEntry(fileName.AsSpan(), out mpqHeroesArchiveEntry);
}

/// <summary>
/// Tries to get a <see cref="MpqHeroesArchiveEntry"/> by its file name.
/// </summary>
/// <param name="fileName">The name of the archive entry.</param>
/// <param name="mpqHeroesArchiveEntry">When this method returns, contains the <see cref="MpqHeroesArchiveEntry"/>.</param>
/// <returns><see langword="true"/> if the value was found; otherwise <see langword="false"/>.</returns>
public bool TryGetEntry(ReadOnlySpan<char> fileName, [NotNullWhen(true)] out MpqHeroesArchiveEntry? mpqHeroesArchiveEntry)
{
mpqHeroesArchiveEntry = null;

Expand All @@ -155,7 +177,14 @@ public bool TryGetEntry(string fileName, [NotNullWhen(true)] out MpqHeroesArchiv
/// </summary>
/// <param name="fileName">The name of the archive entry. Is case-insensitive.</param>
/// <returns><see langword="true"/> if the entry exists, otherwise returns <see langword="false"/>.</returns>
public bool FileEntryExists(string fileName) => TryGetHashEntry(fileName, out _);
public bool FileEntryExists(string fileName) => FileEntryExists(fileName.AsSpan());

/// <summary>
/// Checks if the entry exist.
/// </summary>
/// <param name="fileName">The name of the archive entry. Is case-insensitive.</param>
/// <returns><see langword="true"/> if the entry exists, otherwise returns <see langword="false"/>.</returns>
public bool FileEntryExists(ReadOnlySpan<char> fileName) => TryGetHashEntry(fileName, out _);

/// <inheritdoc/>
public void Dispose()
Expand Down

0 comments on commit 523759f

Please sign in to comment.