shortstrings

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package shortstrings operates on packed canonical WTF-8 strings.

Index

Constants

View Source
const MaxBytes = 8

MaxBytes is the maximum byte length of a packed string.

Variables

This section is empty.

Functions

func Bytes

func Bytes(data uint64) [MaxBytes]byte

Bytes returns the bytes of a packed string, including its zero padding.

func CodePointAt

func CodePointAt(data uint64, i int) (r rune)

CodePointAt returns the code point starting at UTF-16 index i. i must be in range.

func Compare

func Compare(a uint64, aN int, b uint64, bN int) int

Compare orders the packed strings by UTF-16 code units and returns -1, 0, or 1. aN and bN are their byte lengths.

func Concat

func Concat(a uint64, aN int, b uint64, bN int) (uint64, int, bool)

Concat returns the packed concatenation and its byte length, or false if it does not fit. aN and bN are the operands' byte lengths.

func Index

func Index(data uint64, n int, sub uint64, subN int, from int) int

Index returns the first UTF-16 index of sub at or after from, or -1. n and subN are byte lengths, and from must be nonnegative.

func IsASCII

func IsASCII(data uint64) bool

IsASCII reports whether every byte of the packed string is below 0x80.

func IsWellFormed

func IsWellFormed(data uint64) bool

IsWellFormed reports whether the packed string contains no lone surrogates.

func LastIndex

func LastIndex(data uint64, n int, sub uint64, subN int, from int) int

LastIndex returns the last UTF-16 index of sub at or before from, or -1. n and subN are byte lengths, and from must be nonnegative.

func Len

func Len(data uint64, n int) int

Len returns the UTF-16 length of the packed string whose byte length is n.

func Pack

func Pack(s wtf8.String) uint64

Pack returns the zero-padded payload of s, which must contain at most MaxBytes bytes.

func ParseDecimal

func ParseDecimal(data uint64, n int) (uint32, bool)

ParseDecimal parses a nonempty sequence of ASCII decimal digits, or returns false. n is the packed string's byte length.

func Repeat

func Repeat(data uint64, n, count int) (uint64, int, bool)

Repeat returns count copies of the packed string and their byte length, or false if they do not fit. n is the string's byte length, and count must be nonnegative.

func Slice

func Slice(data uint64, start, end int) (uint64, int)

Slice returns the packed substring and its byte length. start and end must be ordered UTF-16 indices within the string.

func String

func String(data uint64, n int) wtf8.String

String returns the packed string whose byte length is n.

func ToLowerASCII

func ToLowerASCII(data uint64) uint64

ToLowerASCII converts data to lowercase. data must be a packed ASCII string.

func ToUpperASCII

func ToUpperASCII(data uint64) uint64

ToUpperASCII converts data to uppercase. data must be a packed ASCII string.

func ToWellFormed

func ToWellFormed(data uint64) uint64

ToWellFormed replaces lone surrogates with U+FFFD in the packed string, preserving its byte length.

func TrimASCII

func TrimASCII(data uint64, n int, start, end bool) (uint64, int)

TrimASCII returns the trimmed packed string and its byte length. data must be ASCII; n is its byte length, and start and end select the sides to trim.

func UnitAt

func UnitAt(data uint64, i int) (u uint16)

UnitAt returns the UTF-16 code unit at i in the packed string. i must be in range.

Types

type Builder

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

Builder builds a canonical WTF-8 string, packed while it fits. Its zero value is ready to use.

func (*Builder) Packed

func (b *Builder) Packed() (uint64, int, bool)

Packed returns the built string in packed form and its byte length, and reports whether it fits.

func (*Builder) String

func (b *Builder) String() wtf8.String

String returns the built string.

func (*Builder) WriteRune

func (b *Builder) WriteRune(r rune)

WriteRune appends r, which must be a Unicode code point or surrogate.

func (*Builder) WriteString

func (b *Builder) WriteString(s wtf8.String)

WriteString appends s.

func (*Builder) WriteUnit

func (b *Builder) WriteUnit(u uint16)

WriteUnit appends the UTF-16 code unit u.

Jump to

Keyboard shortcuts

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