Documentation
¶
Index ¶
- func Contains(text, search string) bool
- func CountOccurrences(text, search string) int
- func ParseKeyValue(input string, delimiters ...string) (value string, err error)
- func Split(data, separator string) (result []string)
- type Text
- func (t *Text) CamelCaseLower() *Text
- func (t *Text) CamelCaseUpper() *Text
- func (t *Text) RemoveTilde() *Text
- func (t *Text) Replace(old, newStr string) *Text
- func (t *Text) String() string
- func (t *Text) ToLower() *Text
- func (t *Text) ToSnakeCaseLower(sep ...string) *Text
- func (t *Text) ToSnakeCaseUpper(sep ...string) *Text
- func (t *Text) ToUpper() *Text
- func (t *Text) Trim() *Text
- func (t *Text) TrimPrefix(prefix string) *Text
- func (t *Text) TrimSuffix(suffix string) *Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v0.0.8
Contains checks if the string 'search' is present in 'text' Returns true if found, false otherwise This matches the behavior of the standard library strings.Contains
func CountOccurrences ¶ added in v0.0.8
CountOccurrences checks how many times the string 'search' is present in 'text' eg: "hello world" with search "world" will return 1
func ParseKeyValue ¶ added in v0.0.10
ParseKeyValue extracts the value part from a "key:value" formatted string. By default, it uses ":" as the delimiter but accepts an optional custom delimiter. The function returns the value part and an error (nil if successful).
Examples:
value, err := ParseKeyValue("name:John") // value = "John", err = nil value, err := ParseKeyValue("data=123", "=") // value = "123", err = nil value, err := ParseKeyValue("invalid-string") // value = "", err = error containing "delimiter ':' not found in string invalid-string"
Types ¶
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text struct to store the content of the text
func (*Text) CamelCaseLower ¶
converts text to camelCase (first word lowercase) eg: "Hello world" -> "helloWorld"
func (*Text) CamelCaseUpper ¶
converts text to PascalCase (all words capitalized) eg: "hello world" -> "HelloWorld"
func (*Text) Replace ¶ added in v0.0.7
Replace replaces all occurrences of old with new in the text content eg: "hello world" with old "world" and new "universe" will return "hello universe"
func (*Text) ToSnakeCaseLower ¶
snakeCase converts a string to snake_case format with optional separator. If no separator is provided, underscore "_" is used as default. Example:
Input: "camelCase" -> Output: "camel_case" Input: "PascalCase", "-" -> Output: "pascal-case" Input: "APIResponse" -> Output: "api_response" Input: "user123Name", "." -> Output: "user123.name"
ToSnakeCaseLower converts text to snake_case format
func (*Text) ToSnakeCaseUpper ¶
ToSnakeCaseUpper converts text to Snake_Case format
func (*Text) Trim ¶ added in v0.0.7
Trim removes spaces at the beginning and end of the text content eg: " hello world " will return "hello world"
func (*Text) TrimPrefix ¶ added in v0.0.9
TrimPrefix removes the specified prefix from the text content if it exists eg: "prefix-hello" with prefix "prefix-" will return "hello"
func (*Text) TrimSuffix ¶ added in v0.0.7
TrimSuffix removes the specified suffix from the text content if it exists eg: "hello.txt" with suffix ".txt" will return "hello"