WebURL Documentation Beta

Extensions on LazyCollectionProtocol

Methods

percent​Encoded(using:​)

@inlinable @inline(__always)
public func percentEncoded<EncodeSet>(using encodeSet: EncodeSet) -> LazilyPercentEncoded<Elements, EncodeSet> 

Returns a Collection whose elements are computed lazily by percent-encoding this collection's elements.

Percent-encoding transforms arbitrary bytes to ASCII strings (e.g. the byte value 200, or 0xC8, to the string "%C8"), with bytes within the ASCII range being restricted by encodeSet.

Form-encoding (as used by HTML forms) is a legacy variant of percent-encoding which includes substitutions; provide the appropriate SubstitutionMap when decoding form-encoded data to accurately recover the source contents.

// Encode arbitrary data as an ASCII string.
let image: Data = ...
image.lazy.percentEncoded(using: .urlComponentSet) // ASCII bytes, decoding to "%BAt_%E0%11%22%EB%10%2C%7F..."

// Encode-sets determine which characters are encoded, and some perform substitutions.
let bytes = "hello, world!".utf8
bytes.lazy.percentEncoded(using: .urlComponentSet)
  .elementsEqual("hello%2C%20world!".utf8) // ✅
bytes.lazy.percentEncoded(using: .formEncoding)
  .elementsEqual("hello%2C+world%21".utf8) // ✅

percent​Encoded(using:​)

@inlinable @inline(__always) @_disfavoredOverload
public func percentEncoded<EncodeSet>(
  using encodeSet: EncodeSet._Member
) -> LazilyPercentEncoded<Elements, EncodeSet> 

Returns a Collection whose elements are computed lazily by percent-encoding this collection's elements.

Percent-encoding transforms arbitrary bytes to ASCII strings (e.g. the byte value 200, or 0xC8, to the string "%C8"), with bytes within the ASCII range being restricted by encodeSet.

Form-encoding (as used by HTML forms) is a legacy variant of percent-encoding which includes substitutions; provide the appropriate SubstitutionMap when decoding form-encoded data to accurately recover the source contents.

// Encode arbitrary data as an ASCII string.
let image: Data = ...
image.lazy.percentEncoded(using: .urlComponentSet) // ASCII bytes, decoding to "%BAt_%E0%11%22%EB%10%2C%7F..."

// Encode-sets determine which characters are encoded, and some perform substitutions.
let bytes = "hello, world!".utf8
bytes.lazy.percentEncoded(using: .urlComponentSet)
  .elementsEqual("hello%2C%20world!".utf8) // ✅
bytes.lazy.percentEncoded(using: .formEncoding)
  .elementsEqual("hello%2C+world%21".utf8) // ✅

percent​Decoded(substitutions:​)

@inlinable @inline(__always)
public func percentDecoded<Substitutions>(
  substitutions: Substitutions
) -> LazilyPercentDecodedWithSubstitutions<Elements, Substitutions> 

Returns a Collection whose elements are computed lazily by percent-decoding the elements of this collection.

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, or .none for modern percent-encoded content.

// 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.

percent​Decoded(substitutions:​)

@inlinable @inline(__always) @_disfavoredOverload
public func percentDecoded<Substitutions>(
  substitutions: Substitutions._Member
) -> LazilyPercentDecodedWithSubstitutions<Elements, Substitutions> 

Returns a Collection whose elements are computed lazily by percent-decoding the elements of this collection.

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, or .none for modern percent-encoded content.

// 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.

percent​Decoded()

@inlinable @inline(__always)
public func percentDecoded() -> LazilyPercentDecoded<Elements> 

Returns a Collection whose elements are computed lazily by percent-decoding the elements of this collection.

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, or .none for modern percent-encoded content.

This function is equivalent to calling percentDecoded(substitutions: .none).

// 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.