Documentation
¶
Index ¶
- func AndString(values [][]byte, quote bool) string
- func EitherOrString(values [][]byte, quote bool) string
- func FindByte(data []byte, from int, sep byte) int
- func FindByteReversed(data []byte, from int, sep byte) int
- func FindContentIndexes(op_token, cl_token []byte, tokens [][]byte) (result [2]int, err error)
- func FirstIndex(tokens [][]byte, target []byte) int
- func ForwardSearch(data []byte, from int, sep []byte) int
- func IndicesOf(data []byte, sep []byte, exclude_sep bool) []int
- func OrString(values [][]byte, quote, is_negative bool) string
- func ReverseSearch(data []byte, from int, sep []byte) int
- func TrimEmpty(values [][]byte) [][]byte
- type ErrNeverOpened
- type ErrTokenNotFound
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AndString ¶
AndString is a function that returns a string representation of a slice of bytes.
Parameters:
- values: The values to convert to a string.
- quote: Whether to quote the values.
Returns:
- string: The string representation of the values.
func EitherOrString ¶
EitherOrString is a function that returns a string representation of a slice of bytes.
Parameters:
- values: The values to convert to a string.
- quote: True if the values should be quoted, false otherwise.
Returns:
- string: The string representation.
Example:
EitherOrString(bytes.Fields([]byte("a b c"}, false) // "a, b or c"
func FindByte ¶
FindByte searches for the first occurrence of a byte in a byte slice starting from a given index.
Parameters:
- data: the byte slice to search in.
- from: the index to start the search from. If negative, it is treated as 0.
- sep: the byte to search for.
Returns:
- int: the index of the first occurrence of the byte in the byte slice, or -1 if not found.
func FindByteReversed ¶
FindByteReversed searches for the first occurrence of a byte in a byte slice starting from a given index in reverse order.
Parameters:
- data: the byte slice to search in.
- from: the index to start the search from. If greater than or equal to the length of the byte slice, it is treated as the length of the byte slice minus 1.
- sep: the byte to search for.
Returns:
- int: the index of the first occurrence of the byte in the byte slice in reverse order, or -1 if not found.
func FindContentIndexes ¶
FindContentIndexes searches for the positions of opening and closing tokens in a slice of strings.
Parameters:
- op_token: The string that marks the beginning of the content.
- cl_token: The string that marks the end of the content.
- tokens: The slice of strings in which to search for the tokens.
Returns:
- result: An array of two integers representing the start and end indexes of the content.
- err: Any error that occurred while searching for the tokens.
Errors:
- *luc.ErrInvalidParameter: If the closingToken is an empty string.
- *ErrTokenNotFound: If the opening or closing token is not found in the content.
- *ErrNeverOpened: If the closing token is found without any corresponding opening token.
Behaviors:
- The first index of the content is inclusive, while the second index is exclusive.
- This function returns a partial result when errors occur. ([-1, -1] if errors occur before finding the opening token, [index, 0] if the opening token is found but the closing token is not found.
func FirstIndex ¶
FirstIndex returns the first index of the target in the tokens.
Parameters:
- tokens: The slice of tokens in which to search for the target.
- target: The target to search for.
Returns:
- int: The index of the target. -1 if the target is not found.
If either tokens or the target are empty, it returns -1.
func ForwardSearch ¶
ForwardSearch searches for the first occurrence of a byte in a byte slice.
Parameters:
- data: the byte slice to search in.
- from: the index to start the search from. If negative, it is treated as 0.
- sep: the byte to search for.
Returns:
- int: the index of the first occurrence of the byte in the byte slice, or -1 if not found.
func IndicesOf ¶
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 character right before the separator.
Returns:
- []int: The indices.
func OrString ¶
OrString is a function that returns a string representation of a slice of bytes.
Parameters:
- values: The values to convert to a string.
- quote: True if the values should be quoted, false otherwise.
- is_negative: True if the string should use "nor" instead of "or", false otherwise.
Returns:
- string: The string representation.
Example:
OrString(bytes.Fields([]byte("a b c"), false, true) // "a, b, nor c"
func ReverseSearch ¶
ReverseSearch searches for the last occurrence of a byte in a byte slice.
Parameters:
- data: the byte slice to search in.
- from: the index to start the search from. If greater than or equal to the length of the byte slice, it is treated as the length of the byte slice minus 1.
- sep: the byte to search for.
Returns:
- int: the index of the last occurrence of the byte in the byte slice, or -1 if not found.
Types ¶
type ErrNeverOpened ¶
type ErrNeverOpened struct {
// OpeningToken is the opening token that was never closed.
OpeningToken []byte
// ClosingToken is the closing token that was found without a corresponding
// opening token.
ClosingToken []byte
}
ErrNeverOpened is a struct that represents an error when a closing token is found without a corresponding opening token.
func NewErrNeverOpened ¶
func NewErrNeverOpened(openingToken, closingToken []byte) *ErrNeverOpened
NewErrNeverOpened is a constructor of ErrNeverOpened.
Parameters:
- openingToken: The opening token that was never closed.
- closingToken: The closing token that was found without a corresponding opening token.
Returns:
- *ErrNeverOpened: A pointer to the newly created error.
func (*ErrNeverOpened) Error ¶
func (e *ErrNeverOpened) Error() string
Error implements the error interface.
Message:
- "closing token {ClosingToken} found without a corresponding opening token {OpeningToken}".
type ErrTokenNotFound ¶
type ErrTokenNotFound struct {
// Token is the token that was not found in the content.
Token []byte
// IsOpening is the type of the token (opening or closing).
IsOpening bool
}
ErrTokenNotFound is a struct that represents an error when a token is not found in the content.
func NewErrTokenNotFound ¶
func NewErrTokenNotFound(token []byte, is_opening bool) *ErrTokenNotFound
NewErrTokenNotFound is a constructor of ErrTokenNotFound.
Parameters:
- token: The token that was not found in the content.
- is_opening: The type of the token (opening or closing).
Returns:
- *ErrTokenNotFound: A pointer to the newly created error.
func (*ErrTokenNotFound) Error ¶
func (e *ErrTokenNotFound) Error() string
Error implements the error interface.
Message: "{Type} token {Token} is not in the content"