Documentation ¶
Index ¶
- Constants
- Variables
- func CaseCamel(s string) string
- func CaseCamelLower(s string) string
- func CaseConvert(s string, caseType CaseType) string
- func CaseDelimited(s string, del byte) string
- func CaseDelimitedScreaming(s string, del uint8, screaming bool) string
- func CaseKebab(s string) string
- func CaseKebabScreaming(s string) string
- func CaseSnake(s string) string
- func CaseSnakeFirstUpper(word string, underscore ...string) string
- func CaseSnakeScreaming(s string) string
- func Chr(ascii int) string
- func Equal(a, b string) bool
- func HideStr(str string, percent int, hide string) string
- func InArray(a []string, s string) bool
- func Nl2Br(str string, isXhtml ...bool) string
- func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string
- func OctStr(str string) string
- func Ord(char string) int
- func PrefixArray(array []string, prefix string)
- func Reverse(str string) string
- func SearchArray(a []string, s string) int
- func Snack(p string) string
- func ToLower(s string) string
- func TrimLeft(str string, characterMask ...string) string
- func WordWrap(str string, width int, br string) string
- func YamlUnMarshal(f string, v any) error
- type CaseType
Constants ¶
const (
// NotFoundIndex is the position index for string not found in searching functions.
NotFoundIndex = -1
)
Variables ¶
var ( // DefaultTrimChars are the characters which are stripped by Trim* functions in default. DefaultTrimChars = string([]byte{ '\t', '\v', '\n', '\r', '\f', ' ', 0x00, 0x85, 0xA0, }) )
Functions ¶
func CaseCamel ¶
CaseCamel converts a string to CamelCase.
Example: CaseCamel("any_kind_of_string") -> AnyKindOfString
func CaseCamelLower ¶
CaseCamelLower converts a string to lowerCamelCase.
Example: CaseCamelLower("any_kind_of_string") -> anyKindOfString
func CaseConvert ¶
CaseConvert converts a string to the specified naming convention. Use CaseTypeMatch to match the case type from string.
func CaseDelimited ¶
CaseDelimited converts a string to snake.case.delimited.
Example: CaseDelimited("AnyKindOfString", '.') -> any.kind.of.string
func CaseDelimitedScreaming ¶
CaseDelimitedScreaming converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case.
Example: CaseDelimitedScreaming("AnyKindOfString", '.') -> ANY.KIND.OF.STRING
func CaseKebab ¶
CaseKebab converts a string to kebab-case.
Example: CaseKebab("AnyKindOfString") -> any-kind-of-string
func CaseKebabScreaming ¶
CaseKebabScreaming converts a string to KEBAB-CASE-SCREAMING.
Example: CaseKebab("AnyKindOfString") -> ANY-KIND-OF-STRING
func CaseSnake ¶
CaseSnake converts a string to snake_case.
Example: CaseSnake("AnyKindOfString") -> any_kind_of_string
func CaseSnakeFirstUpper ¶
CaseSnakeFirstUpper converts a string like "RGBCodeMd5" to "rgb_code_md5". TODO for efficiency should change regexp to traversing string in future.
Example: CaseSnakeFirstUpper("RGBCodeMd5") -> rgb_code_md5
func CaseSnakeScreaming ¶
CaseSnakeScreaming converts a string to SNAKE_CASE_SCREAMING.
Example: CaseSnakeScreaming("AnyKindOfString") -> ANY_KIND_OF_STRING
func Equal ¶
Equal reports whether `a` and `b`, interpreted as UTF-8 strings, are equal under Unicode case-folding, case-insensitively.
func HideStr ¶
HideStr replaces part of the string `str` to `hide` by `percentage` from the `middle`. It considers parameter `str` as unicode string.
func Nl2Br ¶
Nl2Br inserts HTML line breaks(`br`|<br />) before all newlines in a string: \n\r, \r\n, \r, \n. It considers parameter `str` as unicode string.
func NumberFormat ¶
NumberFormat formats a number with grouped thousands. Parameter `decimals`: Sets the number of decimal points. Parameter `decPoint`: Sets the separator for the decimal point. Parameter `thousandsSep`: Sets the thousands' separator. See http://php.net/manual/en/function.number-format.php.
Example: NumberFormat(1234.56, 2, ".", "") -> 1234,56 NumberFormat(1234.56, 2, ",", " ") -> 1 234,56
func OctStr ¶
OctStr converts string container octal string to its original string, for example, to Chinese string.
Example: OctStr("\346\200\241") -> 怡
func Ord ¶
Ord converts the first byte of a string to a value between 0 and 255.
Example: Chr("A") -> 65
func PrefixArray ¶
PrefixArray adds `prefix` string for each item of `array`.
Example: PrefixArray(["a","b"], "gf_") -> ["gf_a", "gf_b"]
func Reverse ¶
Reverse returns a string which is the reverse of `str`.
Example: Reverse("123456") -> "654321"
func SearchArray ¶
SearchArray searches string `s` in string slice `a` case-sensitively, returns its index in `a`. If `s` is not found in `a`, it returns -1.
func ToLower ¶
ToLower returns a copy of the string s with all Unicode letters mapped to their lower case.
func WordWrap ¶
WordWrap wraps a string to a given number of characters. This function supports cut parameters of both english and chinese punctuations. TODO: Enable custom cut parameter, see http://php.net/manual/en/function.wordwrap.php.
func YamlUnMarshal ¶ added in v1.0.3
Types ¶
type CaseType ¶
type CaseType string
CaseType is the type for Case.
const ( Camel CaseType = "Camel" CamelLower CaseType = "CamelLower" Snake CaseType = "Snake" SnakeFirstUpper CaseType = "SnakeFirstUpper" SnakeScreaming CaseType = "SnakeScreaming" Kebab CaseType = "Kebab" KebabScreaming CaseType = "KebabScreaming" Lower CaseType = "Lower" )
The case type constants.
func CaseTypeMatch ¶
CaseTypeMatch matches the case type from string.