// 1. Let sequences be the result of splitting input on 0x26 (&).
autosequences=input.split_view('&');
// 2. Let output be an initially empty list of name-value tuples where both name and value hold a string.
Vector<QueryParam>output;
// 3. For each byte sequence bytes in sequences:
for(autobytes:sequences){
// 1. If bytes is the empty byte sequence, then continue.
if(bytes.is_empty())
continue;
StringViewname;
StringViewvalue;
// 2. If bytes contains a 0x3D (=), then let name be the bytes from the start of bytes up to but excluding its first 0x3D (=), and let value be the bytes, if any, after the first 0x3D (=) up to the end of bytes. If 0x3D (=) is the first byte, then name will be the empty byte sequence. If it is the last, then value will be the empty byte sequence.
if(autoindex=bytes.find('=');index.has_value()){
name=bytes.substring_view(0,*index);
value=bytes.substring_view(*index+1);
}
// 3. Otherwise, let name have the value of bytes and let value be the empty byte sequence.
else{
name=bytes;
value=""sv;
}
// 4. Replace any 0x2B (+) in name and value with 0x20 (SP).
// 1. If init is a sequence, then for each pair in init:
// a. If pair does not contain exactly two items, then throw a TypeError.
// b. Append a new name-value pair whose name is pair’s first item, and value is pair’s second item, to query’s list.
// TODO
// 2. Otherwise, if init is a record, then for each name → value of init, append a new name-value pair whose name is name and value is value, to query’s list.
// 3. Otherwise:
// a. Assert: init is a string.
// b. Set query’s list to the result of parsing init.
// 1. If this’s list contains any name-value pairs whose name is name, then set the value of the first such name-value pair to value and remove the others.
// 2. Otherwise, append a new name-value pair whose name is name and value is value, to this’s list.
else{
m_list.empend(name,value);
}
// 3. Update this.
update();
}
voidURLSearchParams::sort()
{
// 1. Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of code units. The relative order between name-value pairs with equal names must be preserved.