runes

package
v0.0.0-...-84d6781 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadEncoding occurs when an input (slice of bytes or string) is not valid utf-8.
	// This error can be checked using the == operator.
	//
	// Format:
	// 	"invalid utf-8"
	ErrBadEncoding error
)

Functions

func BytesToUtf8

func BytesToUtf8(data []byte) ([]rune, error)

BytesToUtf8 converts a byte slice to a slice of runes.

Parameters:

  • data: The byte slice to convert.

Returns:

  • []rune: The slice of runes.
  • error: An error if conversion failed.

Errors:

  • ErrBadEncoding: If the byte slice is not valid utf-8.

func Equals

func Equals(first, second []rune) bool

Equals checks if two slices of runes are equal.

The two slices are considered equal if they have the same length and the same elements in the same order.

Parameters:

  • first: The first slice of runes.
  • second: The second slice of runes.

Returns:

  • bool: True if the two slices are equal, false otherwise.

func IndicesOf

func IndicesOf(slice []rune, sep rune) []int

IndicesOf returns a slice of indices that specify where the separator occurs in the data.

Parameters:

  • slice: The data.
  • sep: The separator.

Returns:

  • []int: The indices. Nil if no separator is found.

func NewErrAfter

func NewErrAfter(quote bool, previous *rune, inner error) error

NewErrAfter creates a new ErrAfter error.

Parameters:

  • quote: A flag indicating whether the previous value should be quoted.
  • previous: The previous value associated with the error. If not provided, "at the start" is used.
  • inner: The inner error that occurred. If not provided, "something went wrong" is used.

Returns:

  • error: The newly created ErrAfter error. Never returns nil.

Format:

"after <previous>: <inner>"

func NewErrNotAsExpected

func NewErrNotAsExpected(quote bool, kind string, got *rune, expecteds ...rune) error

NewErrNotAsExpected is a convenience function that creates a new ErrNotAsExpected error with the specified kind, got value, and expected values.

See common.NewErrNotAsExpected for more information.

func Normalize

func Normalize(chars *[]rune, tab_size int) error

Normalize normalizes the runes in chars by replacing all "\r\n" with "\n" and all "\t" with the appropriate number of spaces depending on tab_size.

The function normalizes the runes in place and has no other side effects.

Parameters:

  • chars: The characters to normalize.
  • tab_size: The size of the tab stop.

Returns:

  • error: An error if normalization fails.

Errors:

  • common.ErrBadParam: If tab_size is not positive.
  • ErrAt: If '\r' is not followed by '\n' at the specified index. This error wraps ErrNotAsExpected.

func Repeat

func Repeat(char rune, count int) ([]rune, error)

Repeat generates a slice of runes by repeating a given character a specified number of times.

Parameters:

  • char: The character to repeat.
  • count: The number of times to repeat the character.

Returns:

  • []rune: The resulting slice of repeated characters.
  • error: An error if the count is not a non-negative integer.

func StringToUtf8

func StringToUtf8(str string) ([]rune, error)

StringToUtf8 is like BytesToUtf8 but for strings.

Parameters:

  • str: The string to convert.

Returns:

  • []rune: The slice of runes.
  • error: An error if conversion failed.

Errors:

  • ErrBadEncoding: If the string is not valid utf-8.

Types

type ErrAfter

type ErrAfter struct {
	// Quote is a flag that indicates that the error should be quoted.
	Quote bool

	// Previous is the previous value.
	Previous *rune

	// Inner is the inner error.
	Inner error
}

ErrAfter is an error that occurs after another error.

func (ErrAfter) Error

func (e ErrAfter) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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