WebURL Documentation Beta

Typealias Lazily​Percent​Decoded

public typealias LazilyPercentDecoded<Source> = LazilyPercentDecodedWithSubstitutions<Source, NoSubstitutions>
where Source: Collection, Source.Element == UInt8

A Collection which percent-decodes elements from its Source on-demand.

Percent-decoding transforms certain ASCII sequences to bytes ("%AB" to the byte value 171, or 0xAB).

Form-encoding (as used by HTML forms) is a legacy variant of percent-encoding which includes substitutions; use LazilyPercentDecodedWithSubstitutions, providing the correct SubstitutionMap, to accurately decode form-encoded content.

To decode a source collection containing a percent-encoded or form-encoded string, use the extension methods provided on LazyCollectionProtocol:

// The bytes, containing a string with percent-encoding.
let source: [UInt8] = [0x25, 0x36, 0x31, 0x25, 0x36, 0x32, 0x25, 0x36, 0x33]
String(decoding: source, as: UTF8.self) // "%61%62%63"

// In this case, the decoded bytes contain the ASCII string "abc".
source.lazy.percentDecoded().elementsEqual("abc".utf8) // ✅

The elements of this collection are raw bytes, potenially including NULL bytes or invalid UTF-8.