StringMethods

protocol StringMethods

Shared text operations for owned strings, substrings, and static strings.

as_substring is the common borrowed representation. Methods in this protocol count bytes; the extensions in Text.tlk count and slice extended grapheme clusters, preserving a clear boundary between encoding and text.

Methods

func as_substring() -> Substring

Borrows the complete text as a contiguous substring.

View Source
func as_substring() -> Substring

func utf8() -> UTF8View

Returns a view of the UTF-8 code units.

View Source
func utf8() -> UTF8View

func is_empty() -> Bool

Returns whether the text contains zero UTF-8 bytes.

View Source
func is_empty() -> Bool {
	self.as_substring().byte_count == 0
}

func utf8_count() -> Int

Returns the number of UTF-8 bytes.

View Source
func utf8_count() -> Int {
	self.as_substring().byte_count
}