Documentation
¶
Overview ¶
Package strings defines strings helpers.
Index ¶
- func CaesarDecrypt(input string, shift int) string
- func CaesarEncrypt(input string, shift int) string
- func CommonPrefix(input ...string) string
- func CommonSuffix(input ...string) string
- func IsValidEmail(email string) bool
- func Reverse(input string) string
- func Rot13Decode(input string) string
- func Rot13Encode(input string) string
- func RunLengthDecode(encoded string) (string, error)
- func RunLengthEncode(input string) string
- func SanitizeEmail(email string) string
- func SubstringSearch(input, substring string, options SubstringSearchOptions) []string
- func Title(input string) string
- func ToTitle(input string, exceptions []string) string
- func Tokenize(input string, customDelimiters string) []string
- func Truncate(input string, opts *TruncateOptions) string
- type SubstringSearchOptions
- type TruncateOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaesarDecrypt ¶
CaesarDecrypt decrypts a string encrypted with the Caesar cipher and a given shift.
func CaesarEncrypt ¶
CaesarEncrypt encrypts a string using the Caesar cipher with a given shift.
func CommonPrefix ¶
CommonPrefix returns the longest common prefix of the given strings. If no strings are provided, it returns an empty string. If only one string is provided, it returns that string. For example, CommonPrefix("nation", "national", "nasty") returns "na".
func CommonSuffix ¶
CommonSuffix returns the longest common suffix of the given strings. If no strings are provided, it returns an empty string. If only one string is provided, it returns that string. For example, CommonSuffix("testing", "running", "jumping") returns "ing".
func IsValidEmail ¶
IsValidEmail checks if a given string is a valid email address.
func Reverse ¶
Reverse returns a reversed version of the input string. It correctly handles Unicode characters. For example:
Reverse("hello") returns "olleh" Reverse("世界") returns "界世"
func Rot13Decode ¶
Rot13Decode decodes a string encoded with the ROT13 cipher.
func Rot13Encode ¶
Rot13Encode encodes a string using the ROT13 cipher.
func RunLengthDecode ¶
RunLengthDecode takes a Run-Length Encoded string and returns the decoded string or an error + the orignal encoded string
func RunLengthEncode ¶
RunLengthEncode takes a string and returns its Run-Length Encoded representation or the original string if the encoding did not achieve any compression
func SanitizeEmail ¶
SanitizeEmail removes leading and trailing whitespace from an email address.
func SubstringSearch ¶
func SubstringSearch(input, substring string, options SubstringSearchOptions) []string
SubstringSearch performs substring search in a string and optionally returns indexes.
func ToTitle ¶
ToTitle converts a string to title case, capitalizing the first letter of each word. It excludes exceptions specified in the exceptions slice.
func Tokenize ¶
Tokenize splits a given string into words based on whitespace and custom delimiters.
func Truncate ¶
func Truncate(input string, opts *TruncateOptions) string
Truncate shortens a given input string based on provided options. Parameters: - input: the original string to truncate. - opts: optional settings to specify truncation length and omission suffix. If opts is nil or certain fields are unspecified, defaults are applied: Length defaults to 12 and Omission defaults to "...".
Types ¶
type SubstringSearchOptions ¶
type SubstringSearchOptions struct { CaseInsensitive bool // Perform case-insensitive search ReturnIndexes bool // Return the starting indexes of found substrings }
SubstringSearchOptions contains options for substring search.
type TruncateOptions ¶
TruncateOptions represents optional parameters for the Truncate function.