Documentation
¶
Index ¶
- Constants
- func And(values []string) string
- func Concat(strs ...string) string
- func Count(str, substr string) (uint32, bool)
- func EitherOr(values []string) string
- func Fields(dst *[]string, str string) (uint32, error)
- func FormatFloat[E ~float32 | float64](num E) string
- func FormatInt[E ~int | int8 | int16 | int32 | int64](num E) string
- func FormatUint[E ~uint | uint8 | uint16 | uint32 | uint64](num E) string
- func IsLonger(s string) bool
- func IsShorter(str string) bool
- func Join(strs []string, sep string) string
- func Len(str string) (uint64, bool)
- func Or(values []string) string
- func Ordinal(num uint64) string
- func Quote(str string) string
- func QuoteIf(str string) string
- func RejectEmpty[S ~[]string](s *S) (uint32, error)
- func Repeat(str string, count uint64) string
- func ReplacePrefix(str, old, new string) (string, bool)
- func ReplaceSuffix(str, old, new string) (string, bool)
- func Rune(str string) iter.Seq[rune]
- func Split(dst *[]string, str, sep string) (uint32, error)
- func SplitN(dst *[]string, str *string, sep string, n uint32) (uint32, error)
- func Trim(str, sep string) string
- func TrimSpace(str string) string
- func TrimSuffix(str, suffix string) string
- type ErrBadFormat
Constants ¶
const ( // BASE_10 is the base 10 BASE_10 int = 10 )
const ( // MAX_STRING_SIZE is the maximum size that a string can have. // However, this is not a strict limit but a suggestion. MAX_STRING_SIZE uint64 = 0xFFFFFFFFFFFFFFFF )
Variables ¶
This section is empty.
Functions ¶
func And ¶ added in v0.1.5
And formats a slice of strings as a string using the "and" conjunction according to the rules of the English language. The provided values should be unique and not empty.
Parameters:
- values: The slice of strings to format.
Returns:
- string: The formatted string.
func Concat ¶ added in v0.1.5
Concat is a convenience function that does the same as `Join(strs, "")`. Empty strings are ignored.
Parameters:
- strs: The slice of strings to join.
Returns:
- string: The joined string.
func Count ¶ added in v0.1.5
Count returns the number of times a substring occurs in a string. If the substring is empty, it returns the length of the string.
Parameters:
- str: The string to count the substring in.
- substr: The substring to count.
Returns:
- uint32: The number of times the substring occurs in the string. It is never greater than common.MAX_SLICE_SIZE.
- bool: `true` if the number of times the substring occurs in the string is less than or equal to common.MAX_SLICE_SIZE, `false` otherwise.
func EitherOr ¶ added in v0.1.5
EitherOr formats a slice of strings as a string using the "either/or" conjunction according to the rules of the English language. The provided values should be unique and not empty.
Parameters:
- values: The slice of strings to format.
Returns:
- string: The formatted string.
func Fields ¶ added in v0.1.5
Fields splits the string s around each instance of one or more consecutive white space characters, returning an array of substrings of s or an empty slice if s contains only white space. The result is stored back into the provided memory location without any side effects.
Parameters:
- dst: The memory location to store the result.
- str: The string to split.
Returns:
- uint32: The number of substrings in the result.
- error: An error if splitting the string fails.
Errors:
- errors.ErrBadParam: If dst is nil.
- errors.ErrSizeExceeded: If the result has been truncated due to the number of substrings being too many.
func FormatFloat ¶ added in v0.1.9
FormatFloat returns the string representation of the float in base 10.
Parameters:
- num: The float to format.
Returns:
- string: The string representation of the float in base 10.
func FormatInt ¶ added in v0.1.9
FormatInt returns the string representation of the int in base 10.
Parameters:
- num: The int to format.
Returns:
- string: The string representation of the int in base 10.
func FormatUint ¶ added in v0.1.5
FormatUint returns the string representation of the uint in base 10.
Parameters:
- num: The uint to format.
Returns:
- string: The string representation of the uint in base 10.
func IsLonger ¶ added in v0.1.5
IsLonger reports whether the string is longer than MAX_STRING_SIZE.
Parameters:
- s: The string to check.
Returns:
- bool: `true` if the string is too long, `false` otherwise.
func IsShorter ¶ added in v0.1.5
IsShorter reports whether the length of the string is shorter than MAX_STRING_SIZE.
Parameters:
- str: the string to check.
Returns:
- bool: `true` if the length of the string is valid, `false` otherwise.
func Join ¶ added in v0.1.5
Join joins a slice of strings with a separator.
Parameters:
- strs: The slice of strings to join.
- sep: The separator.
Returns:
- string: The joined string.
func Len ¶
Len returns the length of the string, reporting whether it is shorter than or equal to MAX_STRING_SIZE.
Parameters:
- str: The string to get the length of.
Returns:
- uint64: The length of the string.
- bool: `true` if the string is shorter than or equal to MAX_STRING_SIZE, `false` otherwise.
func Or ¶ added in v0.1.5
Or formats a slice of strings as a string using the "or" conjunction according to the rules of the English language. The provided values should be unique and not empty.
Parameters:
- values: The slice of strings to format.
Returns:
- string: The formatted string.
func Ordinal ¶ added in v0.1.5
Ordinal returns the ordinal suffix of the number.
Parameters:
- num: The number to get the ordinal suffix of.
Returns:
- string: The ordinal suffix of the number.
func Quote ¶ added in v0.1.3
Quote quotes a string.
Parameters:
- str: The string to quote.
Returns:
- string: The quoted string.
func QuoteIf ¶ added in v0.1.5
QuoteIf quotes a string if it is not empty.
Parameters:
- str: The string to quote.
Returns:
- string: The quoted string.
func RejectEmpty ¶ added in v0.1.5
RejectEmpty returns a slice with the strings that are not empty. These strings are defined to be "valid".
The result of RejectEmpty is stored back in the provided variable without any side effect and without modifying the original slice.
Parameters:
- s: The slice to reject the empty strings from. The result is stored back in this variable.
Returns:
- uint32: The number of valid strings.
- error: An error if rejecting the strings fails.
Errors:
- errors.ErrBadParam: If s is nil.
- errors.ErrSizeExceeded: If the number of valid strings is greater than [MaxSliceSize].
Example:
s := []string{"", "", ""}
n, err := RejectEmpty(&s)
if err != nil {
panic(err)
}
// Do something with `result`
func Repeat ¶ added in v0.1.5
Repeat returns a string that is repeated count times.
Parameters:
- str: The string to repeat.
- count: The number of times to repeat the string.
Returns:
- string: The repeated string.
func ReplacePrefix ¶ added in v0.1.5
ReplacePrefix replaces the prefix of a string with another string, if the prefix exists. If `old` is empty, the prefix is added.
Parameters:
- str: The string to replace the prefix of.
- old: The prefix to replace.
- new: The string to replace the prefix with.
Returns:
- string: The string with the prefix replaced.
- bool: `true` if the prefix was replaced, `false` otherwise.
func ReplaceSuffix ¶ added in v0.1.5
ReplaceSuffix replaces the suffix of a string with another string, if the suffix exists. If `old` is empty, the suffix is added.
Parameters:
- str: The string to replace the suffix of.
- old: The suffix to replace.
- new: The string to replace the suffix with.
Returns:
- string: The string with the suffix replaced.
- bool: `true` if the suffix was replaced, `false` otherwise.
func Rune ¶ added in v0.1.5
Rune returns an iterator that yields the runes in a string.
The iterator is not single-use only.
Parameters:
- str: The string to yield the runes from.
Returns:
- iter.Seq[rune]: An iterator that yields the runes in a string. It is never nil.
func Split ¶
Split splits a string into a list of substrings, storing the result back into the provided memory location without any side-effects.
Parameters:
- dst: The memory location to store the result.
- str: The string to split.
- sep: The separator to use.
Returns:
- uint32: The number of substrings in the result.
- error: An error if splitting the string fails.
Errors:
- errors.ErrBadParam: If dst is nil.
- errors.ErrSizeExceeded: If the result has been truncated due to the number of substrings being too many.
func SplitN ¶ added in v0.1.5
SplitN splits a string into a slice of strings using a separator and a maximum number of splits. The remaining string is stored in the provided variable without any side effect. Likewise, the result is stored back into the provided memory location without any side effects.
If the maximum number of splits is greater than common.MAX_SLICE_SIZE, it is truncated.
Parameters:
- dst: The memory location to store the result.
- str: The string to split. The remaining string is stored back in this variable.
- sep: The separator to use.
- n: The maximum number of splits.
Returns:
- uint32: The number of splits performed.
- error: An error if splitting the string fails.
Errors:
- errors.ErrBadParam: If dst or str are nil.
func Trim ¶ added in v0.1.5
Trim trims leading and trailing separator characters from the string.
Parameters:
- str: The string to trim.
- sep: The separator.
Returns:
- string: The trimmed string.
func TrimSpace ¶ added in v0.1.5
TrimSpace trims leading and trailing white space from a string.
Parameters:
- str: The string to trim.
Returns:
- string: The trimmed string.
func TrimSuffix ¶ added in v0.1.5
TrimSuffix trims the suffix from a string.
Parameters:
- str: The string to trim.
- suffix: The suffix to trim.
Returns:
- string: The trimmed string.
Types ¶
type ErrBadFormat ¶ added in v0.1.5
type ErrBadFormat struct {
// contains filtered or unexported fields
}
ErrBadFormat is the error type for when formats are invalid during parsing, especially from strings to enums.
func NewErrBadFormat ¶ added in v0.1.5
func NewErrBadFormat(msg string) *ErrBadFormat
NewErrBadFormat returns a new ErrBadFormat with the given message.
Parameters:
- msg: The message of the error.
Returns:
- *ErrBadFormat: The newly created error. It is never `nil`.
Format:
"bad format: <msg>"
Where, <msg> is the message of the error. Defaults to errors.DEFAULT_ERR_MSG if empty.
func (ErrBadFormat) Error ¶ added in v0.1.5
func (e ErrBadFormat) Error() string
Error implements error.