Documentation
¶
Index ¶
- func BytesToUtf8(data []byte) ([]rune, error)
- func EitherOrString(elems []rune, quote bool) string
- func IndicesOf(data []rune, sep rune, exclude_sep bool) []int
- func NormalizeRunes(chars []rune) ([]rune, error)
- func StringToUtf8(str string) ([]rune, error)
- type ErrInvalidUTF8Encoding
- type ErrUnexpectedChar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToUtf8 ¶ added in v0.1.1
BytesToUtf8 is a function that converts bytes to runes. When error occurs, the function returns the runes decoded so far and the error.
Parameters:
- data: The bytes to convert.
Returns:
- []rune: The runes.
- error: An error if the bytes are not valid UTF-8.
Errors:
- *ErrInvalidUTF8Encoding: If the bytes are not valid UTF-8.
func EitherOrString ¶ added in v0.1.1
EitherOrString is a function that returns a string representation of a slice of strings. Empty strings are ignored.
Parameters:
- values: The values to convert to a string.
Returns:
- string: The string representation.
Example:
EitherOrString([]rune{'a', 'b', 'c'}, false) // "either a, b or c"
func IndicesOf ¶ added in v0.1.1
Indices returns the indices of the separator in the data.
Parameters:
- data: The data.
- sep: The separator.
- exclude_sep: Whether the separator is inclusive. If set to true, the indices will point to the character right after the separator. Otherwise, the indices will point to the separator itself.
Returns:
- []int: The indices.
func NormalizeRunes ¶ added in v0.1.21
NormalizeRunes is a function that converts '\r\n' to '\n'.
Parameters:
- chars: The characters to convert.
Returns:
- []rune: The normalized characters.
- error: An error if the characters are not valid UTF-8.
Errors:
- *ErrUnexpectedChar: If the characters are not valid UTF-8.
func StringToUtf8 ¶ added in v0.1.1
StringToUtf8 converts a string to a slice of runes. When error occurs, the function returns the runes decoded so far and the error.
Parameters:
- str: The string to convert.
Returns:
- runes: The slice of runes.
- error: An error of if the string is not valid UTF-8.
Errors:
- *ErrInvalidUTF8Encoding: If the string is not valid UTF-8.
Types ¶
type ErrInvalidUTF8Encoding ¶ added in v0.1.1
type ErrInvalidUTF8Encoding struct {
// At is the index of the invalid UTF-8 encoding.
At int
}
ErrInvalidUTF8Encoding is an error type for invalid UTF-8 encoding.
func NewErrInvalidUTF8Encoding ¶ added in v0.1.1
func NewErrInvalidUTF8Encoding(at int) *ErrInvalidUTF8Encoding
NewErrInvalidUTF8Encoding creates a new ErrInvalidUTF8Encoding error.
Parameters:
- at: The index of the invalid UTF-8 encoding.
Returns:
- *ErrInvalidUTF8Encoding: A pointer to the newly created error.
func (ErrInvalidUTF8Encoding) Error ¶ added in v0.1.1
func (e ErrInvalidUTF8Encoding) Error() string
Error implements the error interface.
Message:
"invalid UTF-8 encoding at index {At}"
type ErrUnexpectedChar ¶ added in v0.1.21
type ErrUnexpectedChar struct {
// Expected is the expected character.
Expecteds []rune
// Previous is the previous character.
Previous rune
// Got is the current character.
Got *rune
}
ErrUnexpectedChar is an error that occurs when an unexpected character is encountered.
func NewErrUnexpectedChar ¶ added in v0.1.21
func NewErrUnexpectedChar(previous rune, expecteds []rune, got *rune) *ErrUnexpectedChar
NewErrUnexpectedChar creates a new ErrUnexpectedChar error.
Parameters:
- previous: the previous character.
- expecteds: the expected characters.
- got: the current character.
Returns:
- *ErrUnexpectedChar: the error. Never returns nil.
func (ErrUnexpectedChar) Error ¶ added in v0.1.21
func (e ErrUnexpectedChar) Error() string
Error implements the error interface.
Message:
"expected {expected} after {previous}, got {got} instead".