strings

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 9 Imported by: 0

README

strings

Extension of Go standard strings library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ASCIILetters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
var ASCIILowercase = "abcdefghijklmnopqrstuvwxyz"
View Source
var ASCIIUppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
var ASCIIWhitespace = " \t\n\r\x0b\x0c"
View Source
var Center = xstrings.Center
View Source
var Count = xstrings.Count
View Source
var Delete = xstrings.Delete
View Source
var Digits = "0123456789"
View Source
var ExpandTabs = xstrings.ExpandTabs
View Source
var FirstRuneToLower = xstrings.FirstRuneToLower
View Source
var FirstRuneToUpper = xstrings.FirstRuneToUpper
View Source
var HexDigits = "0123456789abcdefABCDEF"
View Source
var Insert = xstrings.Insert
View Source
var JustifyLeft = xstrings.LeftJustify
View Source
var JustifyRight = xstrings.RightJustify
View Source
var OctDigits = "01234567"
View Source
var Partition = xstrings.Partition
View Source
var PartitionLast = xstrings.LastPartition
View Source
var Punctuation = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~."
View Source
var Reverse = xstrings.Reverse
View Source
var RuneWidth = xstrings.RuneWidth
View Source
var Scrub = xstrings.Scrub
View Source
var Shuffle = xstrings.Shuffle
View Source
var ShuffleSource = xstrings.ShuffleSource
View Source
var Slice = xstrings.Slice
View Source
var Squeeze = xstrings.Squeeze
View Source
var Successor = xstrings.Successor
View Source
var SwapCase = xstrings.SwapCase
View Source
var ToCamelCase = xstrings.ToCamelCase
View Source
var ToKebabCase = xstrings.ToKebabCase
View Source
var ToSnakeCase = xstrings.ToSnakeCase
View Source
var Translate = xstrings.Translate
View Source
var TrimSpace = strings.TrimSpace

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

View Source
var ValidUTF8 = utf8.Valid

ValidUTF8 reports whether string consists entirely of valid UTF-8-encoded runes.

View Source
var Whitespace = "" /* 156-byte string literal not displayed */
View Source
var Width = xstrings.Width
View Source
var WordCount = xstrings.WordCount
View Source
var WordSplit = xstrings.WordSplit

Functions

func ASCII added in v1.0.0

func ASCII(s string) string

func Digest added in v1.0.0

func Digest(s string, options ...Option) string

Digest return a digest of a string It is based on the hexadecimal (lowercase) representation of SHA-512. Specify the option WithMaxLen to shorten the 64 byte representation

func Fields added in v1.0.0

func Fields(s string, sep string, joiner string, i ...int) string

func IsANSI

func IsANSI(str string) bool

IsANSI returns true if the entire string contains only ANSI characters. On empty string, the function returns true.

func IsASCII

func IsASCII(str string) bool

IsASCII returns true if the entire string contains only ASCII characters. On empty string, the function returns true.

func IsNumber

func IsNumber(str string) bool

IsNumber returns true if the entire string contains only ASCII digits On empty string, the function returns false

func Latin1 added in v1.0.0

func Latin1(s string) string

func NewTranslator

func NewTranslator(pattern string) *xstrings.Translator

func ParseBrackets

func ParseBrackets(s string, lr rune, rr rune, options ...Option) (result [][]int, balanced bool)

Options:

WithNotEscaped: `lr` and `rr` are not escaped
WithEscapeRune('...'): replace the default escape rune with another rune

Examples:

ParseBrackets("a(b(c))", '(', ')') -> [[1 6] [3 5]], true
ParseBrackets("é(b(é))", '(', ')') -> [[2 8] [4 7]], true
ParseBrackets("aébécèè", 'é', 'è') -> [[1 9] [4 7]], true
ParseBrackets(`(bb\)c\(dd)e`, '(', ')') -> [[1 11]], true
ParseBrackets(`Ë(bb\)c\(dd)e`, '(', ')') -> [[2 12]], true
ParseBrackets(`Ë(bb\)c\(dd)e`, '(', ')', WithNotEscaped) -> [[2 6], [9, 12]], true

func Split

func Split(s string, r rune, options ...Option) []string

Split splits a string on a rune to a slice of strings. Options:

WithNotEscaped: true | false (default): indicates if the rune can be escaped to prevent splitting.
WithEscapeRune: escape character. Default '\'.
                The escape character is only special before the rune and the escape character itself.
WithKeepEscape: true | false (default): indicates if the escape characters are to be present after splitting

func SubString added in v1.0.0

func SubString(s string, i ...int) string

func TrimSpaceLeft added in v1.0.0

func TrimSpaceLeft(s string) string

TrimSpaceLeft returns a slice of the string s, with all leading white space removed, whitespace as defined by Unicode.

func TrimSpaceRight added in v1.0.0

func TrimSpaceRight(s string) string

TrimSpaceRight returns a slice of the string s, with all trailing white space removed, whitespace as defined by Unicode.

func UnEscape

func UnEscape(s string, escapeset string, escape rune) string

UnEscape replaces the escape rune, followed by a rune out of a specific set (escapeset), with the latter. If the only rune in the set is the escape character, it is af every rune belongs to the escapeset. (the escape rune is always added to this set) If the escape character is not followed by any rune (at the end of the string), it is added to the result

Examples:

UnEscape(`a\b`, `b`, '\\') -> `ab`
UnEscape(`a\b`, `c`, '\\') -> `a\b`
UnEscape(`a\\b`, `c`, '\\') -> `a\b`
UnEscape(`ab\`, `c`, '\\') -> `ab\`
UnEscape(`ab\\`, `c`, '\\') -> `ab\`
UnEscape(`a\\b\\`, `\`, '\\') -> `ab\`

func WithKeepEscape

func WithKeepEscape(c *Config)

func WithNotEscaped

func WithNotEscaped(c *Config)

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewCfg

func NewCfg(opts []Option) Config

type Option

type Option func(*Config)

func WithEscapeRune

func WithEscapeRune(escape rune) Option

func WithId

func WithId(id string) Option

func WithMaxLen added in v1.0.0

func WithMaxLen(maxlen int) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithSuffix

func WithSuffix(suffix string) Option

Jump to

Keyboard shortcuts

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