text

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotFoundIndex is the position index for string not found in searching functions.
	NotFoundIndex = -1
)

Variables

View Source
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

func CaseCamel(s string) string

CaseCamel converts a string to CamelCase.

Example: CaseCamel("any_kind_of_string") -> AnyKindOfString

func CaseCamelLower

func CaseCamelLower(s string) string

CaseCamelLower converts a string to lowerCamelCase.

Example: CaseCamelLower("any_kind_of_string") -> anyKindOfString

func CaseConvert

func CaseConvert(s string, caseType CaseType) string

CaseConvert converts a string to the specified naming convention. Use CaseTypeMatch to match the case type from string.

func CaseDelimited

func CaseDelimited(s string, del byte) string

CaseDelimited converts a string to snake.case.delimited.

Example: CaseDelimited("AnyKindOfString", '.') -> any.kind.of.string

func CaseDelimitedScreaming

func CaseDelimitedScreaming(s string, del uint8, screaming bool) string

CaseDelimitedScreaming converts a string to DELIMITED.SCREAMING.CASE or delimited.screaming.case.

Example: CaseDelimitedScreaming("AnyKindOfString", '.') -> ANY.KIND.OF.STRING

func CaseKebab

func CaseKebab(s string) string

CaseKebab converts a string to kebab-case.

Example: CaseKebab("AnyKindOfString") -> any-kind-of-string

func CaseKebabScreaming

func CaseKebabScreaming(s string) string

CaseKebabScreaming converts a string to KEBAB-CASE-SCREAMING.

Example: CaseKebab("AnyKindOfString") -> ANY-KIND-OF-STRING

func CaseSnake

func CaseSnake(s string) string

CaseSnake converts a string to snake_case.

Example: CaseSnake("AnyKindOfString") -> any_kind_of_string

func CaseSnakeFirstUpper

func CaseSnakeFirstUpper(word string, underscore ...string) string

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

func CaseSnakeScreaming(s string) string

CaseSnakeScreaming converts a string to SNAKE_CASE_SCREAMING.

Example: CaseSnakeScreaming("AnyKindOfString") -> ANY_KIND_OF_STRING

func Chr

func Chr(ascii int) string

Chr return the ascii string of a number(0-255).

Example: Chr(65) -> "A"

func Equal

func Equal(a, b string) bool

Equal reports whether `a` and `b`, interpreted as UTF-8 strings, are equal under Unicode case-folding, case-insensitively.

func HideStr

func HideStr(str string, percent int, hide string) string

HideStr replaces part of the string `str` to `hide` by `percentage` from the `middle`. It considers parameter `str` as unicode string.

func InArray

func InArray(s string, a []string) bool

InArray checks whether string `s` in slice `a`.

func Nl2Br

func Nl2Br(str string, isXhtml ...bool) string

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

func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string

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

func OctStr(str string) string

OctStr converts string container octal string to its original string, for example, to Chinese string.

Example: OctStr("\346\200\241") -> 怡

func Ord

func Ord(char string) int

Ord converts the first byte of a string to a value between 0 and 255.

Example: Chr("A") -> 65

func PrefixArray

func PrefixArray(array []string, prefix string)

PrefixArray adds `prefix` string for each item of `array`.

Example: PrefixArray(["a","b"], "gf_") -> ["gf_a", "gf_b"]

func Reverse

func Reverse(str string) string

Reverse returns a string which is the reverse of `str`.

Example: Reverse("123456") -> "654321"

func SearchArray

func SearchArray(a []string, s string) int

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 Snack

func Snack(p string) string

func SubEx added in v1.0.4

func SubEx(mode string, origin string, find string) string

func ToLower

func ToLower(s string) string

ToLower returns a copy of the string s with all Unicode letters mapped to their lower case.

func TrimLeft

func TrimLeft(str string, characterMask ...string) string

TrimLeft strips whitespace (or other characters) from the beginning of a string.

func WordWrap

func WordWrap(str string, width int, br string) string

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

func YamlUnMarshal(f string, v any) error

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

func CaseTypeMatch(caseStr string) CaseType

CaseTypeMatch matches the case type from string.

Jump to

Keyboard shortcuts

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