Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindContentIndexes ¶
func FindContentIndexes(openingToken, closingToken string, contentTokens []string) (int, int, error)
FindContentIndexes searches for the positions of opening and closing tokens in a slice of strings. It returns the start and end indexes of the content between the tokens, and an error if any.
Parameters:
- openingToken: The string that marks the beginning of the content.
- closingToken: The string that marks the end of the content.
- contentTokens: The slice of strings in which to search for the tokens.
Returns:
- The start index of the content (inclusive).
- The end index of the content (exclusive).
- An error if the opening or closing tokens are empty, or if they are not found in the correct order in the contentTokens.
If the openingToken is found but the closingToken is not, the function will return an error. If the closingToken is found before the openingToken, the function will return an error. If the closingToken is a newline ("\n") and it is not found, the function will return the length of the contentTokens as the end index.
Errors returned can be of type ErrOpeningTokenEmpty, ErrClosingTokenEmpty, ErrOpeningTokenNotFound, or a generic error with a message about the closing token.
func GetOrdinalSuffix ¶
GetOrdinalSuffix returns the ordinal suffix for a given integer.
Parameters:
- number: The integer for which to get the ordinal suffix.
The function returns a string that represents the number with its ordinal suffix.
For example, for the number 1, the function returns "1st"; for the number 2, it returns "2nd"; and so on. For numbers ending in 11, 12, or 13, the function returns the number with the suffix "th" (e.g., "11th", "12th", "13th"). For negative numbers, the function also returns the number with the suffix "th".
If the last digit of the number is 0 or greater than 3 (and the last two digits are not 11, 12, or 13), the function returns the number with the suffix "th". If the last digit of the number is 1, 2, or 3 (and the last two digits are not 11, 12, or 13), the function returns the number with the corresponding ordinal suffix ("st", "nd", or "rd").
func ReplaceSuffix ¶
ReplaceSuffix replaces the end of the given string with the provided suffix. The function checks the lengths of the string and the suffix to determine the appropriate action:
- If the length of the suffix is greater than the length of the string, the function returns an empty string and an ErrSuffixTooLong error.
- If the length of the suffix is equal to the length of the string, the function returns the suffix.
- If the length of the suffix is zero, the function returns the original string.
- Otherwise, the function replaces the end of the string with the suffix and returns the result.
Parameters:
- str: The original string.
- suffix: The suffix to replace the end of the string.
Returns:
- The modified string, or an error if the suffix is too long.
Types ¶
type ErrClosingTokenEmpty ¶
type ErrClosingTokenEmpty struct{}
func (ErrClosingTokenEmpty) Error ¶
func (e ErrClosingTokenEmpty) Error() string
type ErrOpeningTokenEmpty ¶
type ErrOpeningTokenEmpty struct{}
func (ErrOpeningTokenEmpty) Error ¶
func (e ErrOpeningTokenEmpty) Error() string
type ErrOpeningTokenNotFound ¶
type ErrOpeningTokenNotFound struct{}
func (ErrOpeningTokenNotFound) Error ¶
func (e ErrOpeningTokenNotFound) Error() string
type ErrSuffixTooLong ¶
type ErrSuffixTooLong struct{}
func (ErrSuffixTooLong) Error ¶
func (e ErrSuffixTooLong) Error() string