stringUtils

package
v0.0.0-...-2e001e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 5 Imported by: 8

Documentation

Overview

Package stringUtils provides various string utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abbreviate

func Abbreviate(str string, maxWidth int) string

Abbreviate abbreviates a string using ellipses.

func AbbreviateWithOffset

func AbbreviateWithOffset(str string, offset int, maxWidth int) string

AbbreviateWithOffset abbreviates a string using ellipses at a specific offset.

func AppendIfMissing

func AppendIfMissing(str string, suffix string, suffixes ...string) string

AppendIfMissing appends a suffix to a string if missing.

func AppendIfMissingIgnoreCase

func AppendIfMissingIgnoreCase(str string, suffix string, suffixes ...string) string

AppendIfMissingIgnoreCase appends a suffix to a string if missing (ignoring case).

func Capitalize

func Capitalize(str string) string

Capitalize capitalizes a string changing the first letter to title case. No other letters are changed.

func Chomp

func Chomp(str string) string

Chomp removes one newline from end of a string if it's there, otherwise leave it alone. A newline is "\n", "\r", or "\r\n".

func Chop

func Chop(str string) string

Chop removes the last character from a string. If the string ends in \r\n, then remove both of them.

func Contains

func Contains(str string, search string) bool

Contains checks if string contains a search string.

func ContainsAny

func ContainsAny(str string, search ...string) bool

ContainsAny checks if the string contains any of the string in the given array.

func ContainsAnyCharacter

func ContainsAnyCharacter(str string, search string) bool

ContainsAnyCharacter checks if the string contains any of the character in the given string.

func ContainsIgnoreCase

func ContainsIgnoreCase(str string, search string) bool

ContainsIgnoreCase checks if the string contains the searched string ignoring case.

func ContainsNone

func ContainsNone(str string, search ...string) bool

ContainsNone checks if the string contains no occurrence of searched string.

func ContainsNoneCharacter

func ContainsNoneCharacter(str string, search string) bool

ContainsNoneCharacter checks if the string contains no occurrence of searched string.

func ContainsOnly

func ContainsOnly(str string, search ...string) bool

ContainsOnly checks if a string contains only some strings.

func DefaultString

func DefaultString(str string, defaultStr string) string

Returns either the passed in String, or if the String is Empty, the value of defaultStr.

func EndsWith

func EndsWith(str string, suffix string) bool

EndsWith check if a string ends with a specified suffix.

func EndsWithAny

func EndsWithAny(str string, suffixes ...string) bool

EndsWithAny check if a string ends with any of an array of specified strings.

func EndsWithAnyIgnoreCase

func EndsWithAnyIgnoreCase(str string, suffixes ...string) bool

EndsWithAnyIgnoreCase check if a string ends with any of an array of specified strings (ignoring case).

func EndsWithIgnoreCase

func EndsWithIgnoreCase(str string, suffix string) bool

EndsWithIgnoreCase case insensitive check if a string ends with a specified suffix.

func IsAllLowerCase

func IsAllLowerCase(str string) bool

IsAllLowerCase checks if the string contains only lowercase characters.

func IsAllUpperCase

func IsAllUpperCase(str string) bool

IsAllUpperCase checks if the string contains only uppercase characters.

func IsAlpha

func IsAlpha(str string) bool

IsAlpha checks if the string contains only Unicode letters.

func IsAlphaSpace

func IsAlphaSpace(str string) bool

IsAlphaSpace checks if the string contains only Unicode letters and spaces.

func IsAlphanumeric

func IsAlphanumeric(str string) bool

IsAlphanumeric checks if the string contains only Unicode letters and digits.

func IsAlphanumericSpace

func IsAlphanumericSpace(str string) bool

IsAlphanumericSpace checks if the string contains only Unicode letters, digits and spaces.

func IsAnyBlank

func IsAnyBlank(strings ...string) bool

IsAnyBlank checks if any one of the strings are empty or containing only whitespaces.

func IsAnyEmpty

func IsAnyEmpty(strings ...string) bool

IsAnyEmpty checks if any one of the given strings are empty.

func IsBlank

func IsBlank(s string) bool

IsBlank checks if a string is whitespace or empty

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if a string is empty.

func IsNoneBlank

func IsNoneBlank(strings ...string) bool

IsNoneBlank checks if none of the strings are empty or containing only whitespaces.

func IsNoneEmpty

func IsNoneEmpty(strings ...string) bool

IsNoneEmpty checks if none of the strings are empty.

func IsNotBlank

func IsNotBlank(s string) bool

IsNotBlank checks if a string is not empty or containing only whitespaces.

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty checks if a string is not empty.

func IsNumeric

func IsNumeric(str string) bool

IsNumeric checks if the string contains only digits.

func IsNumericSpace

func IsNumericSpace(str string) bool

IsNumericSpace checks if the string contains only digits and whitespace.

func IsWhitespace

func IsWhitespace(str string) bool

IsWhitespace checks if the string contains only whitespace.

func Join

func Join(a []string, sep string) string

Join joins an array of strings into a string where each item of the array is separated with a separator.

func JoinBool

func JoinBool(a []bool, sep string) string

JoinBool is the same as Join but joining boolean.

func JoinFloat64

func JoinFloat64(a []float64, sep string) string

JoinFloat64 is the same as Join but joining float64. The default format given to strconv.FormatFloat is 'G' and bitSize is 32.

func JoinFloat64WithFormatAndPrecision

func JoinFloat64WithFormatAndPrecision(a []float64, fmt byte, precision int, sep string) string

JoinFloat64WithFormatAndPrecision is the same as Join but joining float64 with a custom precision (bitSize) and format.

func JoinInt

func JoinInt(a []int, sep string) string

JoinInt is the same as Join but joining integers.

func JoinInt64

func JoinInt64(a []int64, sep string) string

JoinInt64 is the same as Join but joining int64.

func JoinUint64

func JoinUint64(ints []uint64, sep string) string

JoinUint64 is the same as Join but joining uint64.

func Left

func Left(str string, size int) string

Left gets the leftmost len characters of a string.

func LowerCase

func LowerCase(str string) string

LowerCase converts a string to lower case.

func Mid

func Mid(str string, pos int, size int) string

Mid gets size characters from the middle of a string.

func Overlay

func Overlay(str string, overlay string, start int, end int) string

Overlay overlays part of a string with another string.

func PrependIfMissing

func PrependIfMissing(str string, prefix string, prefixes ...string) string

PrependIfMissing prepends the prefix to the start of the string if the string does not already start with any of the prefixes.

func PrependIfMissingIgnoreCase

func PrependIfMissingIgnoreCase(str string, prefix string, prefixes ...string) string

PrependIfMissing prepends the prefix to the start of the string if the string does not already start, case-insensitive, with any of the prefixes.

func Remove

func Remove(str string, remove string) string

Remove removes all occurrences of a substring from within the source string.

func RemoveEnd

func RemoveEnd(str string, remove string) string

RemoveEnd removes a substring only if it is at the end of a source string, otherwise returns the source string.

func RemoveEndIgnoreCase

func RemoveEndIgnoreCase(str string, remove string) string

RemoveEndIgnoreCase is the case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.

func RemovePattern

func RemovePattern(str string, pattern string) string

RemovePattern removes each substring of the source string that matches the given regular expression

func RemoveStart

func RemoveStart(str string, remove string) string

RemoveStart removes a substring only if it is at the beginning of a source string, otherwise returns the source string

func RemoveStartIgnoreCase

func RemoveStartIgnoreCase(str string, remove string) string

RemoveStartIgnoreCase is the case insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string.

func Repeat

func Repeat(str string, repeat int) string

Repeat repeats a string `repeat` times to form a new string.

func RepeatWithSeparator

func RepeatWithSeparator(str string, sep string, repeat int) string

RepeatWithSeparator repeats a string `repeat` times to form a new String, with a string separator injected each time.

func Reverse

func Reverse(s string) string

Reverse reverses a string.

func ReverseDelimited

func ReverseDelimited(str string, del string) string

ReverseDelimited reverses a string separated by a delimiter.

func Right(str string, size int) string

Right gets the rightmost len characters of a string.

func StartsWith

func StartsWith(str string, prefix string) bool

StartsWith check if a string starts with a specified prefix.

func StartsWithAny

func StartsWithAny(str string, prefixes ...string) bool

StartsWithAny check if a string starts with any of an array of specified strings.

func StartsWithAnyIgnoreCase

func StartsWithAnyIgnoreCase(str string, prefixes ...string) bool

StartsWithAnyIgnoreCase check if a string starts with any of an array of specified strings (ignoring case).

func StartsWithIgnoreCase

func StartsWithIgnoreCase(str string, prefix string) bool

StartsWithIgnoreCase case insensitive check if a string starts with a specified prefix.

func Strip

func Strip(str string) string

Strip strips whitespace from the start and end of a String.

func StripEnd

func StripEnd(str string) string

StripEnd strips whitespace from the end of a String.

func StripStart

func StripStart(str string) string

StripStart strips whitespace from the start of a String.

func SubstringAfter

func SubstringAfter(str string, sep string) string

SubstringAfter gets the substring after the first occurrence of a separator.

func SubstringAfterLast

func SubstringAfterLast(str string, sep string) string

SubstringAfterLast gets the substring after the last occurrence of a separator.

func SubstringBefore

func SubstringBefore(str string, sep string) string

SubstringBefore gets the substring before the first occurrence of a separator.

func SubstringBeforeLast

func SubstringBeforeLast(str string, sep string) string

SubstringBeforeLast gets the substring before the last occurrence of a separator.

func SwapCase

func SwapCase(str string) string

SwapCase swaps the case of a String changing upper and title case to lower case, and lower case to upper case.

func Trim

func Trim(str string) string

Trim removes control characters from both ends of this string.

func Uncapitalize

func Uncapitalize(str string) string

Uncapitalize uncapitalizes a String, changing the first letter to lower case.

func UpperCase

func UpperCase(str string) string

UpperCase converts a string to upper case.

func Wrap

func Wrap(str string, wrapWith string) string

Wrap wraps a string with another string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL