Repository navigation
AdaSearchParams
Sanam edited this page Sep 23, 2026
·
1 revision
public ref struct AdaSearchParams : IDisposable
A parsed query string with the behaviour of the WHATWG URLSearchParams interface. It owns native
memory, so dispose it.
AdaSearchParams.Parse(ReadOnlySpan<byte> utf8Query) accepts the query with or without a leading
?. It does not fail: any input is a query.
using var query = AdaSearchParams.Parse("?b=2&a=1&a=3"u8);| Member | Description |
|---|---|
Count |
Number of pairs, counting repeated keys separately |
Has(ReadOnlySpan<byte> key) |
true if any pair has the key |
Get(ReadOnlySpan<byte> key) |
The first value for the key, or empty if absent. Use Has to tell absent from empty. |
Append(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value) |
Adds a pair and keeps existing ones |
Set(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value) |
Sets the first pair with the key and removes the others |
Remove(ReadOnlySpan<byte> key) |
Removes every pair with the key |
Sort() |
Sorts by key, keeping the order of equal keys |
TryToString(Span<byte> destination, out int written) |
Serialises into your buffer. false if too small. |
ToString() |
Serialises to a string. Allocates. |
GetEnumerator() |
Enumerates the pairs in order, for foreach
|
Dispose() |
Frees the native memory. Safe to call twice. |
Get, the enumerated keys and values, and anything else that returns a span, are borrowed and
invalidated by Append, Set, Remove or Sort.
using var query = AdaSearchParams.Parse("?b=2&a=1&a=3"u8);
query.Count; // 3
query.Has("a"u8); // true
query.Get("a"u8); // 1
query.Append("c"u8, "x y"u8); // b=2&a=1&a=3&c=x+y
query.Set("a"u8, "9"u8); // b=2&a=9&c=x+y
query.Remove("b"u8); // a=9&c=x+ySort is stable:
using var query = AdaSearchParams.Parse("z=1&a=2&z=0"u8);
query.Sort(); // a=2&z=1&z=0The enumerator is a struct, so foreach allocates nothing. Values are decoded: x+y comes back
as x y.
foreach (AdaSearchParams.Entry entry in query)
{
ReadOnlySpan<byte> key = entry.Key;
ReadOnlySpan<byte> value = entry.Value;
}AdaSearchParams does not implement IEnumerable, because that would box the enumerator on every
loop. LINQ does not work on it directly.
| Type | Members |
|---|---|
AdaSearchParams.Entry |
Key, Value: borrowed spans |
AdaSearchParams.Enumerator |
Current, MoveNext(), Dispose(). foreach calls these for you. |
Ada.Url
API reference
Links