utf8string

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2022 License: MIT-0 Imports: 5 Imported by: 0

Documentation

Overview

Package utf8string provides types and helpers (currently just one String type) designed for making certain uses of unicode strings more efficient.

The String type stores a UTF-8 encoded string as well as a memory-efficient slice of exceptions to the most common encoded code-point size.

Other types may be added at a later date.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	Rune int
	U16  int
	Byte int
	// contains filtered or unexported fields
}

Cursor is a cursor representing an offset within the parent string.

type String

type String struct {
	// contains filtered or unexported fields
}

String is the main type of the utf8string package, it represents an indexed utf8 string with O(log(m)) slicing by rune offset where m is the number of runes with encodings requiring an uncommon number of runes.

func NewString

func NewString(in string) String

NewString creates a UTF8String, including the appropriate index.

func (*String) RuneLen

func (u *String) RuneLen() int

RuneLen returns the number of runes in the string, with a result equivalent to len([]rune(u.String())), (but in constant time).

func (*String) SeekByte

func (u *String) SeekByte(boffset int) Cursor

SeekByte provides a Cursor for the specified Byte-offset

func (*String) SeekRune

func (u *String) SeekRune(roffset int) Cursor

SeekRune returns the offset in bytes into the contained string for that rune offset.

func (*String) SeekUTF16

func (u *String) SeekUTF16(u16offset int) Cursor

SeekUTF16 returns a Cursor for the UTF-16 offset (useful in webassembly when interacting with JS strings)

func (*String) SliceByte

func (u *String) SliceByte(i, j int) String

SliceByte returns a substring of u on the interval [i, j) (matching the slice expression u.String()[i:j]), except the relevant components of the index are preserved.

func (*String) SliceRune

func (u *String) SliceRune(i, j int) String

SliceRune returns a substring of u on the rune-interval [i, j) (matching the slice expression string([]rune(u.String())[i:j])), except the relevant components of the index are preserved.

func (*String) SliceU16

func (u *String) SliceU16(i, j int) String

SliceU16 returns a substring of u on the rune-interval [i, j) (matching the slice expression string([]rune(u.String())[i:j])), except the relevant components of the index are preserved.

func (*String) String

func (u *String) String() string

String implements fmt.Stringer, returning the underlying string-segment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL