String.CharacterView.Index

struct String.CharacterView.Index

A character position.

Inheritance BidirectionalIndexType, Comparable, Equatable, ForwardIndexType, _Incrementable, _Reflectable View Protocol Hierarchy →
Import import Swift

Initializers

init?(_: UTF8Index, within: String)

Construct the position in characters that corresponds exactly to utf8Index. If no such position exists, the result is nil.

Requires: utf8Index is an element of characters.utf8.indices.

Declaration

init?(_ utf8Index: UTF8Index, within characters: String)
init?(_: UTF16Index, within: String)

Construct the position in characters that corresponds exactly to utf16Index. If no such position exists, the result is nil.

Requires: utf16Index is an element of characters.utf16.indices.

Declaration

init?(_ utf16Index: UTF16Index, within characters: String)
init?(_: UnicodeScalarIndex, within: String)

Construct the position in characters that corresponds exactly to unicodeScalarIndex. If no such position exists, the result is nil.

Requires: unicodeScalarIndex is an element of characters.unicodeScalars.indices.

Declaration

init?(_ unicodeScalarIndex: UnicodeScalarIndex, within characters: String)

Instance Methods

func advancedBy(_:)

Return the result of advancing self by n positions.

Returns: - If n > 0, the result of applying successor to self n times. - If n < 0, the result of applying predecessor to self -n times. - Otherwise, self.

Requires: n >= 0 if only conforming to ForwardIndexType Complexity: - O(1) if conforming to RandomAccessIndexType - O(abs(n)) otherwise

Declaration

func advancedBy(n: String.CharacterView.Index.Distance) -> String.CharacterView.Index

Declared In

BidirectionalIndexType, ForwardIndexType
func advancedBy(_:limit:)

Return the result of advancing self by n positions, or until it equals limit.

Returns: - If n > 0, the result of applying successor to self n times but not past limit. - If n < 0, the result of applying predecessor to self -n times but not past limit. - Otherwise, self.

Requires: n >= 0 if only conforming to ForwardIndexType.

Complexity: - O(1) if conforming to RandomAccessIndexType - O(abs(n)) otherwise

Declaration

func advancedBy(n: String.CharacterView.Index.Distance, limit: String.CharacterView.Index) -> String.CharacterView.Index

Declared In

BidirectionalIndexType, ForwardIndexType
func distanceTo(_:)

Measure the distance between self and end.

Requires: - start and end are part of the same sequence when conforming to RandomAccessSequenceType. - end is reachable from self by incrementation otherwise.

Complexity: - O(1) if conforming to RandomAccessIndexType - O(n) otherwise, where n is the function's result.

Declaration

func distanceTo(end: String.CharacterView.Index) -> String.CharacterView.Index.Distance

Declared In

BidirectionalIndexType, ForwardIndexType
func predecessor()

Returns the previous consecutive value before self.

Requires: The previous value is representable.

Declaration

func predecessor() -> String.CharacterView.Index
func samePositionIn(_: String.UTF8View)

Return the position in utf8 that corresponds exactly to self.

Requires: self is an element of String(utf8).indices.

Declaration

func samePositionIn(utf8: String.UTF8View) -> String.UTF8View.Index
func samePositionIn(_: String.UTF16View)

Return the position in utf16 that corresponds exactly to self.

Requires: self is an element of String(utf16).indices.

Declaration

func samePositionIn(utf16: String.UTF16View) -> String.UTF16View.Index
func samePositionIn(_: String.UnicodeScalarView)

Return the position in unicodeScalars that corresponds exactly to self.

Requires: self is an element of String(unicodeScalars).indices.

Declaration

func samePositionIn(unicodeScalars: String.UnicodeScalarView) -> String.UnicodeScalarView.Index
func successor()

Returns the next consecutive value after self.

Requires: The next value is representable.

Declaration

func successor() -> String.CharacterView.Index