package runes

import "github.com/google/cel-go/common/runes"

Package runes provides interfaces and utilities for working with runes.

Index

Types

type Buffer

type Buffer interface {
	Get(i int) rune
	Slice(i, j int) string
	Len() int
}

Buffer is an interface for accessing a contiguous array of code points.

func NewBuffer

func NewBuffer(data string) Buffer

NewBuffer returns an efficient implementation of Buffer for the given text based on the ranges of the encoded code points contained within.

Code points are represented as an array of byte, uint16, or rune. This approach ensures that each index represents a code point by itself without needing to use an array of rune. At first we assume all code points are less than or equal to '\u007f'. If this holds true, the underlying storage is a byte array containing only ASCII characters. If we encountered a code point above this range but less than or equal to '\uffff' we allocate a uint16 array, copy the elements of previous byte array to the uint16 array, and continue. If this holds true, the underlying storage is a uint16 array containing only Unicode characters in the Basic Multilingual Plane. If we encounter a code point above '\uffff' we allocate an rune array, copy the previous elements of the byte or uint16 array, and continue. The underlying storage is an rune array containing any Unicode character.

Source Files

buffer.go

Version
v0.15.1
Published
May 5, 2023
Platform
js/wasm
Imports
2 packages
Last checked
1 minute ago

Tools for package owners.