Documentation
¶
Index ¶
- Variables
- func BytesToUtf8(data []byte) ([]rune, error)
- func Equals(first, second []rune) bool
- func IndicesOf(slice []rune, sep rune) []int
- func NewErrAfter(quote bool, previous *rune, inner error) error
- func NewErrNotAsExpected(quote bool, kind string, got *rune, expecteds ...rune) error
- func Normalize(chars *[]rune, tab_size int) error
- func Repeat(char rune, count int) ([]rune, error)
- func StringToUtf8(str string) ([]rune, error)
- type ErrAfter
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.