rstring

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package rstring provides an efficient way to index strings by rune rather than by byte.

There are three types, Rstring, LRstring, and IRstring, that provide different levels of buffering. For instance, LRstring buffers the rune count, so that it does not have to be recomputed, while Rstring is just a wrapper around string:

 	R	LR	IR	Buffering
	-	+	+	RuneCount
	-	-	+	Position

The IRstring implementation is based on the standard library's exp/utf8string package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IRstring

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

String wraps a regular string with a small structure that provides more efficient indexing by code point index, as opposed to byte index. Scanning incrementally forwards or backwards is O(1) per index operation (although not as fast a range clause going forwards). Random access is O(N) in the length of the string, but the overhead is less than always scanning from the beginning. If the string is ASCII, random access is O(1). Unlike the built-in string type, String has internal mutable state and is not thread-safe.

func NewIRstring

func NewIRstring(contents string) *IRstring

NewString returns a new UTF-8 string with the provided contents.

func (*IRstring) At

func (s *IRstring) At(i int) rune

At returns the rune with index i in the String. The sequence of runes is the same as iterating over the contents with a "for range" clause.

func (*IRstring) ByteIndices

func (s *IRstring) ByteIndices(i, j int) (low int, high int)

Slice returns the string sliced at rune positions [i:j].

func (*IRstring) BytePos

func (s *IRstring) BytePos(i int) int

func (*IRstring) Count

func (s *IRstring) Count() int

Count returns the number of runes (Unicode code points) in the String.

func (*IRstring) Init

func (s *IRstring) Init(contents string) *IRstring

Init initializes an existing String to hold the provided contents. It returns a pointer to the initialized String.

func (*IRstring) IsASCII

func (s *IRstring) IsASCII() bool

IsASCII returns a boolean indicating whether the String contains only ASCII bytes.

func (*IRstring) String

func (s *IRstring) String() string

String returns the contents of the String. This method also means the String is directly printable by fmt.Print.

type LRstring

type LRstring struct {
	Rstring
	// contains filtered or unexported fields
}

func LRString

func LRString(s string) (lrstr LRstring)

func (*LRstring) Concat

func (s *LRstring) Concat(s1, s2 LRstring) LRstring

func (LRstring) Count

func (s LRstring) Count() int

type Rstring

type Rstring string

func (Rstring) ByteIndices

func (s Rstring) ByteIndices(start, end int) (i0, iEnd int)

func (Rstring) BytePos

func (s Rstring) BytePos(runePos int) int

func (Rstring) Count

func (s Rstring) Count() int

func (Rstring) Len

func (s Rstring) Len() int

func (Rstring) String

func (s Rstring) String() string

Jump to

Keyboard shortcuts

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