StringView class final

A zero-copy view over UTF-8 bytes.

Index keys, bloom probes and range comparisons all need to compare and hash text without materialising a String. Comparisons use the UTF-8 byte order, which is identical to code-point order, so sorting a StringView and sorting the decoded strings agree.

Implemented types

Constructors

StringView(Uint8List bytes, int start, int end)
Creates a view over bytes[start, end).
const
StringView.of(Uint8List bytes)
Creates a view over the whole buffer.
factory

Properties

byteLength → int
Length in bytes (not code units).
no setter
bytes → Uint8List
Backing bytes; must not be mutated while the view is used as a key.
final
end → int
Offset one past the last byte of the view.
final
hashCode → int
Hash of the raw bytes. Used for index buckets and hash tables.
no setteroverride
isEmpty → bool
Whether the view is empty.
no setter
isNotEmpty → bool
Whether the view is non-empty.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
start → int
First byte of the view.
final

Methods

compareTo(StringView other) → int
Lexicographic comparison with another view.
override
compareToString(String other) → int
Compares against a decoded string without allocating one.
equalsRange(Uint8List other, int otherStart, int otherEnd) → bool
Byte equality with another range.
equalsString(String other) → bool
Whether the decoded text equals other, without allocating.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startsWith(StringView prefix) → bool
Whether this view starts with prefix.
startsWithAscii(String prefix) → bool
Whether this view starts with the UTF-8 encoding of prefix.
toString() → String
Decodes to a String. Allocates; prefer the view when you can.
override

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

compareRanges(Uint8List a, int aStart, int aEnd, Uint8List b, int bStart, int bEnd) → int
Compares two UTF-8 byte ranges lexicographically.