Structure
LazilyPercentDecodedWithSubstitutions
public struct LazilyPercentDecodedWithSubstitutions<Source, Substitutions>: Collection, LazyCollectionProtocol
where Source: Collection, Source.Element == UInt8, Substitutions: SubstitutionMap
A Collection
which percent-decodes elements from its Source
on-demand, and reverses substitutions made by a SubstitutionMap
.
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; provide the appropriate
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 UTF-8 form-encoding.
let source: [UInt8] = [
0x68, 0x25, 0x43, 0x32, 0x25, 0x41, 0x33, 0x6C, 0x6C, 0x6F, 0x2B, 0x77, 0x6F, 0x72, 0x6C, 0x64
]
String(decoding: source, as: UTF8.self) // "h%C2%A3llo+world"
// Specify the `.formEncoding` substitution map to decode the contents.
source.lazy.percentDecoded(substitutions: .formEncoding)
.elementsEqual("h£llo world".utf8) // ✅
The elements of this collection are raw bytes, potenially including NULL bytes or invalid UTF-8.
Relationships
Conforms To
BidirectionalCollection
Collection
LazyCollectionProtocol
Nested Type Aliases
Element
public typealias Element = UInt8
Properties
startIndex
public let startIndex: Index
endIndex
@inlinable
public var endIndex: Index
isEmpty
@inlinable
public var isEmpty: Bool
Methods
index(after:)
@inlinable
public func index(after i: Index) -> Index
formIndex(after:)
@inlinable
public func formIndex(after i: inout Index)