Generic Instance Method


Runs body over the content of this string in contiguous memory. If this string is not contiguous, this will first make it contiguous, which will also speed up subsequent access. If this mutates the string, it will invalidate any pre-existing indices.


mutating func withUTF8<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R


Note that it is unsafe to escape the pointer provided to body. For example, strings of up to 15 UTF-8 code units in length may be represented in a small-string representation, and thus will be spilled into temporary stack space which is invalid after withUTF8 finishes execution.

Complexity: O(n) if non-contiguous, O(1) if already contiguous