Documentation
¶
Overview ¶
Package stringutils provides string manipulation utilities. Started as a simple collection, grew over time as I needed more functions. Now it's basically my kitchen sink of string operations lol
Index ¶
- func CamelCase(s string) string
- func Capitalize(s string) string
- func CharCount(s string) int
- func Contains(s string, substrings ...string) bool
- func ContainsAll(s string, substrings []string) bool
- func ContainsAny(s string, substrings []string) bool
- func IsEmpty(s string) bool
- func IsEmptyString(s string) bool
- func IsNotEmpty(s string) bool
- func KebabCase(s string) string
- func LineCount(s string) int
- func Pad(s string, length int, padChar rune, left bool) string
- func PadLeft(s string, length int, padChar rune) string
- func PadRight(s string, length int, padChar rune) string
- func PascalCase(s string) string
- func Quote(s string) string
- func RandomString(length int, charset string) (string, error)
- func Reverse(s string) string
- func Slug(s string) string
- func SnakeCase(s string) string
- func ToCase(s, format string) string
- func Truncate(s string, maxLength int, suffix string) string
- func Unquote(s string) string
- func WordCount(s string) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶
Capitalize converts first letter of each word to uppercase Works pretty well for most cases I've tried Probably breaks on some edge cases but ¯\_(ツ)_/¯
func ContainsAll ¶
ContainsAll checks if s contains all of the substrings
func ContainsAny ¶
ContainsAny checks if s contains any of the substrings
func IsEmpty ¶
IsEmpty checks if a string is empty or only whitespace. TODO: maybe rename this to be consistent with IsEmptyString? But then again, changing APIs is a pain...
func IsEmptyString ¶
IsEmptyString is an alias for IsEmpty - added for consistency Yes, I know having both is redundant but tests expected it
func IsNotEmpty ¶
IsNotEmpty checks if string has content (opposite of IsEmpty) Because sometimes double negatives hurt my brain
func Pad ¶
Pad pads string to specified length with padChar. Internal function that does the actual work
func PascalCase ¶
PascalCase converts string to PascalCase The C# in me demands this exists
func Quote ¶
Quote wraps string in double quotes, escaping internal quotes Why reinvent the wheel when strconv.Quote exists? Good question!
func RandomString ¶
RandomString generates a random string with given charset. Default charset includes alphanumeric if none provided Fun fact: spent way too much time making this "cryptographically secure" Fun fact: spent way too much time making this "cryptographically secure"
func Reverse ¶
Reverse reverses a string preserving Unicode characters. Had to look up how to handle Unicode properly - runes are tricky!
func Slug ¶
Slug creates a URL-friendly slug from a string Converts to lowercase and replaces non-alphanumeric with hyphens Perfect for blog post URLs (if I ever finish that blog)
func ToCase ¶
ToCase converts string to specified case format. This was my attempt at a unified interface but maybe individual functions are clearer Keeping it for backwards compatibility even though it feels over-engineered
Types ¶
This section is empty.