Skip to content

Commit

Permalink
Change the return type of Decode to int[]
Browse files Browse the repository at this point in the history
Mainly so that the code examples in the README and also at https://sqids.org/dotnet
work (since they're using `int[]` for the variable that holds the return
value of `Decode`.); and also secondarily because it makes the API
more consistent with `Encode`.

This is not a breaking change.
  • Loading branch information
aradalvand committed Aug 7, 2023
1 parent 248afaf commit 21e0f61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Sqids/Sqids.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>

<PackageId>Sqids</PackageId>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Description>Official .NET port of Sqids. Generate short YouTube-looking IDs from numbers.</Description>
<PackageTags>Sqids;ID-generator;number-obfuscator;YouTube-ID</PackageTags>
<PackageIconUrl>https://raw.githubusercontent.com/sqids/sqids-dotnet/main/icon.png</PackageIconUrl>
Expand Down
4 changes: 2 additions & 2 deletions src/Sqids/SqidsEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private string Encode(ReadOnlySpan<int> numbers, bool partitioned = false)
/// input string is null, empty, contains fewer characters than the configured minimum length,
/// or includes characters not found in the alphabet.
/// </returns>
public IReadOnlyList<int> Decode(ReadOnlySpan<char> id)
public int[] Decode(ReadOnlySpan<char> id)
{
if (id.IsEmpty)
return Array.Empty<int>();
Expand Down Expand Up @@ -269,7 +269,7 @@ public IReadOnlyList<int> Decode(ReadOnlySpan<char> id)
ConsistentShuffle(alphabetTemp);
}

return result; // NOTE: We don't do `.ToArray()` here to avoid creating a new array; we just return the list directly as an `IReadOnlyList`.
return result.ToArray(); // TODO: A way to return an array without creating a new array from the list like this?
}

private bool IsBlockedId(ReadOnlySpan<char> id)
Expand Down
7 changes: 4 additions & 3 deletions src/Sqids/SqidsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Sqids;

/// <summary>
/// Custom alphabet that will be used for the IDs.
/// Must contain at least 5 characters.
/// The default is lowercase letters, uppercase letters, and digits.
/// The configuration options for <see cref="SqidsEncoder" />.
/// All properties are optional; any property that isn't explicitly specified when passing an
/// instance of this class to the constructor of <see cref="SqidsEncoder" /> will fall back to its
/// default value.
/// </summary>
public sealed class SqidsOptions
{
Expand Down

0 comments on commit 21e0f61

Please sign in to comment.