WebURL Documentation Beta

Structure Web​URL.​UTF8View

public struct UTF8View 

A view of the UTF-8 code-units in a serialized URL.

This view provides efficient random-access as well as read-write access to the code-units of a serialized URL string, including information about where each URL component is situated. The code-units are guaranteed to only contain ASCII code-points.

Component properties (such as scheme, path, and query) and setter methods (such as setQuery), have the same semantics and behaviour as the corresponding methods on WebURL.

Member Of

WebURL

A Uniform Resource Locator (URL) is a universal identifier, which often describes the location of a resource.

Conforms To

RandomAccessCollection

Nested Type Aliases

Index

public typealias Index = Int

Indices

public typealias Indices = Range<Index>

Element

public typealias Element = UInt8

Properties

start​Index

@inlinable
public var startIndex: Index 

end​Index

@inlinable
public var endIndex: Index 

indices

@inlinable
public var indices: Range<Index> 

count

@inlinable
public var count: Int 

scheme

public var scheme: SubSequence 

The UTF-8 code-units containing this URL's scheme.

username

public var username: SubSequence? 

The UTF-8 code-units containing this URL's username, if present.

password

public var password: SubSequence? 

The UTF-8 code-units containing this URL's password, if present.

hostname

public var hostname: SubSequence? 

The UTF-8 code-units containing this URL's hostname, if present.

port

public var port: SubSequence? 

The UTF-8 code-units containing this URL's port, if present.

path

public var path: SubSequence 

The UTF-8 code-units containing this URL's path.

query

public var query: SubSequence? 

The UTF-8 code-units containing this URL's query, if present.

fragment

public var fragment: SubSequence? 

The UTF-8 code-units containing this URL's fragment, if present.

Methods

path​Component(_:​)

public func pathComponent(_ component: WebURL.PathComponents.Index) -> SubSequence 

The UTF-8 code-units containing the given path component.

index(after:​)

@inlinable
public func index(after i: Index) -> Index 

form​Index(after:​)

@inlinable
public func formIndex(after i: inout Index) 

index(before:​)

@inlinable
public func index(before i: Index) -> Index 

form​Index(before:​)

@inlinable
public func formIndex(before i: inout Index) 

index(_:​offset​By:​)

@inlinable
public func index(_ i: Index, offsetBy distance: Int) -> Index 

distance(from:​to:​)

@inlinable
public func distance(from start: Index, to end: Index) -> Int 

with​Contiguous​Storage​IfAvailable(_:​)

@inlinable @inline(__always)
public func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R? 

with​Unsafe​Buffer​Pointer(_:​)

@inlinable @inline(__always)
public func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R 

Invokes body with a pointer to the contiguous UTF-8 code-units of the serialized URL string.

Parameters

body (Unsafe​Buffer​Pointer<UInt8>) throws -> R

A closure which processes the content of the serialized URL.

resolve(_:​)

@inlinable @inline(__always)
public func resolve<UTF8Bytes>(
  _ utf8: UTF8Bytes
) -> WebURL? where UTF8Bytes: BidirectionalCollection, UTF8Bytes.Element == UInt8 

Parses the given string, which is provided as a collection of UTF-8 code-units, with this URL as its base.

This function supports a wide range of relative URL strings, producing the same result as an HTML <a> tag on the page given by this URL.

It should be noted that this method accepts protocol-relative URLs, which are able to direct to a different hostname, as well as absolute URL strings, which do not copy any information from their base URLs.

set​Scheme(_:​)

@inlinable
public mutating func setScheme<UTF8Bytes>(
  _ newScheme: UTF8Bytes
) throws where UTF8Bytes: Collection, UTF8Bytes.Element == UInt8 

Replaces this URL's scheme with the given UTF-8 code-units.

set​Username(_:​)

@inlinable
public mutating func setUsername<UTF8Bytes>(
  _ newUsername: UTF8Bytes?
) throws where UTF8Bytes: Collection, UTF8Bytes.Element == UInt8 

Replaces this URL's username with the given UTF-8 code-units.

Any code-points which are not valid for use in the URL's user-info section will be percent-encoded.

set​Password(_:​)

@inlinable
public mutating func setPassword<UTF8Bytes>(
  _ newPassword: UTF8Bytes?
) throws where UTF8Bytes: Collection, UTF8Bytes.Element == UInt8 

Replaces this URL's password with the given UTF-8 code-units.

Any code-points which are not valid for use in the URL's user-info section will be percent-encoded.

set​Hostname(_:​)

@inlinable
public mutating func setHostname<UTF8Bytes>(
  _ newHostname: UTF8Bytes?
) throws where UTF8Bytes: BidirectionalCollection, UTF8Bytes.Element == UInt8 

Replaces this URL's hostname with the given UTF-8 code-units.

Unlike other setters, not all code-points which are invalid for use in hostnames will be percent-encoded. If the new content contains a forbidden host code-point, the operation will fail.

set​Path(_:​)

@inlinable
public mutating func setPath<UTF8Bytes>(
  _ newPath: UTF8Bytes
) throws where UTF8Bytes: BidirectionalCollection, UTF8Bytes.Element == UInt8 

Replaces this URL's path with the given UTF-8 code-units.

The given path string will be lexically simplified, and any code-points in the path's components that are not valid for use will be percent-encoded.

set​Query(_:​)

@inlinable
public mutating func setQuery<UTF8Bytes>(
  _ newQuery: UTF8Bytes?
) throws where UTF8Bytes: Collection, UTF8Bytes.Element == UInt8 

Replaces this URL's query with the given UTF-8 code-units.

Any code-points which are not valid for use in the URL's query will be percent-encoded. Note that the set of code-points which are valid depends on the URL's scheme.

set​Fragment(_:​)

@inlinable
public mutating func setFragment<UTF8Bytes>(
  _ newFragment: UTF8Bytes?
) throws where UTF8Bytes: Collection, UTF8Bytes.Element == UInt8 

Replaces this URL's fragment with the given UTF-8 code-units.

Any code-points which are not valid for use in the URL's fragment will be percent-encoded.