Documentation
¶
Index ¶
- func AndString(values []string, quote bool) string
- func EitherOrString(values []string, quote bool) string
- func FindContentIndexes(op_token, cl_token string, tokens []string) (result [2]int, err error)
- func GoStringOf(elem any) string
- func IndicesOf(data []string, sep []string, exclude_sep bool) []int
- func OrString(values []string, quote, is_negative bool) string
- func QuoteInt(value int) string
- func TrimEmpty(values []string) []string
- 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 strings.
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 strings.
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([]string{"a", "b", "c"}, false) // "a, b or c"
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 GoStringOf ¶ added in v0.1.2
GoStringOf returns a string representation of the element.
Parameters:
- elem: The element to get the string representation of.
Returns:
- string: The string representation of the element.
Behaviors:
- If the element is nil, the function returns "nil".
- If the element implements the fmt.GoStringer interface, the function returns the result of the GoString method.
- If the element implements the fmt.Stringer interface, the function returns the result of the String method.
- If the element is a string, the function returns the string enclosed in double quotes.
- If the element is an error, the function returns the error message enclosed in double quotes.
- Otherwise, the function returns the result of the %#v format specifier.
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 strings.
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([]string{"a", "b", "c"}, false, true) // "a, b, nor c"
func QuoteInt ¶
QuoteInt returns a quoted string of an integer prefixed and suffixed with square brackets.
Parameters:
- value: The integer to quote.
Returns:
- string: The quoted integer.
Types ¶
type ErrNeverOpened ¶
type ErrNeverOpened struct {
// OpeningToken is the opening token that was never closed.
OpeningToken string
// ClosingToken is the closing token that was found without a corresponding
// opening token.
ClosingToken string
}
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 string) *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 string
// 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 string, 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"