UTF8View

struct UTF8View

A borrowed view of raw UTF-8 code units.

Indices and slice lengths are bytes, not characters. slice deliberately permits splitting a multi-byte scalar and should only feed byte-oriented protocols; use StringMethods and StringIndex for Unicode-safe slicing.

Properties

let start: Int

The inclusive starting byte offset in the source.

let byte_count: Int

The number of bytes in the encoded representation.

Methods

func count() -> Int

Returns the number of bytes in the view.

View Source
pub func count() -> Int { self.byte_count }

func at(index: Int) -> Byte

Loads the byte at a view-relative index.

Bounds are not checked here; an invalid index traps through raw storage access.

View Source
pub func at(index: Int) -> Byte {
	self.storage.get(self.start + index)
}

func slice(start: Int, byte_count: Int) -> Substring

Creates a borrowed raw-byte slice relative to this view.

Bounds are the caller's responsibility and the slice may split a UTF-8 scalar or grapheme cluster. Use StringRange-based text slicing when boundaries matter.

View Source
pub func slice(start: Int, byte_count: Int) -> Substring {
	Substring(
		storage: self.storage,
		start: self.start + start,
		byte_count: byte_count
	)
}