Documentation
¶
Index ¶
- Constants
- Variables
- func AsciiEqualFold(s, t []byte) bool
- func Between(s, left, right string) string
- func BetweenF(left, right string) func(string) string
- func Camelize(s string) string
- func Capitalize(s string) string
- func CharAt(s string, index int) string
- func CharAtF(index int) func(string) string
- func ChompLeft(s, prefix string) string
- func ChompLeftF(prefix string) func(string) string
- func ChompRight(s, suffix string) string
- func ChompRightF(suffix string) func(string) string
- func Classify(s string) string
- func ClassifyF(s string) func(string) string
- func Clean(s string) string
- func Dasherize(s string) string
- func DecodeHTMLEntities(s string) string
- func DotCase(s string) string
- func EnsurePrefix(s, prefix string) string
- func EnsurePrefixF(prefix string) func(string) string
- func EnsureSuffix(s, suffix string) string
- func EnsureSuffixF(suffix string) func(string) string
- func EnumValueName(s string) string
- func EqualFoldRight(s, t []byte) bool
- func EscapeHTML(s string) string
- func FoldFunc(s []byte) func(s, t []byte) bool
- func GetBuilder() *strings.Builder
- func GoCamelCase(s string) string
- func GoSanitized(s string) string
- func Humanize(s string) string
- func Iif(condition bool, truthy string, falsey string) string
- func IndexOf(s string, needle string, start int) int
- func Indices(str, substr string) []int
- func IsAllBlank[S ~string](ss ...S) bool
- func IsAllEmpty[S ~string](ss ...S) bool
- func IsAlpha(s string) bool
- func IsAlphaNumeric(s string) bool
- func IsAnyBlank[S ~string](ss ...S) bool
- func IsAnyEmpty[S ~string](ss ...S) bool
- func IsBlank[S ~string](s S) bool
- func IsEmpty[S ~string](s S) bool
- func IsLower(s string) bool
- func IsNotBlank[S ~string](s S) bool
- func IsNotEmpty[S ~string](s S) bool
- func IsNumeric(s string) bool
- func IsUpper(s string) bool
- func IsValidNumber(s string) bool
- func JSONCamelCase(s string) string
- func JSONSnakeCase(s string) string
- func JoinBool[E ~bool](es []E, sep string) string
- func JoinFloat[E constraints.Float](es []E, sep string) string
- func JoinInt[E constraints.Signed](es []E, sep string) string
- func JoinUint[E constraints.Unsigned](es []E, sep string) string
- func KebabCase(s string) string
- func Left(s string, n int) string
- func LeftF(n int) func(string) string
- func LeftOf(s string, needle string) string
- func Letters(s string) []string
- func Lines(s string) []string
- func Map(arr []string, iterator func(string) string) []string
- func MapEntryName(s string) string
- func Match(s, pattern string) bool
- func MatchAll(str string, pattern string) []string
- func Max[S ~string](a, b S) S
- func Min[S ~string](a, b S) S
- func Pad(s, c string, n int) string
- func PadF(c string, n int) func(string) string
- func PadLeft(s, c string, n int) string
- func PadLeftF(c string, n int) func(string) string
- func PadRight(s, c string, n int) string
- func PadRightF(c string, n int) func(string) string
- func Pipe(s string, funcs ...func(string) string) string
- func PutBuilder(buf *strings.Builder)
- func QuoteItems(arr []string) []string
- func Remove(s string, chars string) string
- func ReplaceF(old, new string, n int) func(string) string
- func ReplaceFunc(str string, f func(rune) string) string
- func ReplacePattern(s, pattern, repl string) string
- func ReplacePatternF(pattern, repl string) func(string) string
- func Reverse(s string) string
- func Right(s string, n int) string
- func RightF(n int) func(string) string
- func RightOf(s string, prefix string) string
- func SetTemplateDelimiters(opening, closing string)
- func SimpleLetterEqualFold(s, t []byte) bool
- func Slice(s string, start, end int) string
- func SliceContains(slice []string, val string) bool
- func SliceF(start, end int) func(string) string
- func SliceIndexOf(slice []string, val string) int
- func Slugify(s string) string
- func StripPunctuation(s string) string
- func StripTags(s string, tags ...string) string
- func Substr(s string, index int, n int) string
- func SubstrF(index, n int) func(string) string
- func Template(s string, values map[string]interface{}) string
- func TemplateDelimiters() (opening string, closing string)
- func TemplateWithDelimiters(s string, values map[string]interface{}, opening, closing string) string
- func ToArgv(s string) []string
- func ToBool(s string) bool
- func ToBoolOr(s string, defaultValue bool) bool
- func ToFloat32Or(s string, defaultValue float32) float32
- func ToFloat64Or(s string, defaultValue float64) float64
- func ToIntOr(s string, defaultValue int) int
- func TrimEnumPrefix(s, prefix string) string
- func Underscore(s string) string
- func UnescapeHTML(s string) string
- func WrapHTML(s string, tag string, attrs map[string]string) string
- func WrapHTMLF(tag string, attrs map[string]string) func(string) string
- type Builder
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) Len() int
- func (b *Builder) Reset()
- func (b *Builder) String() string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteBool(bl bool) error
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteFloat(f float64, fmt byte, prec, bitSize int) error
- func (b *Builder) WriteInt(i int64, base int) error
- func (b *Builder) WriteQuote(s string) error
- func (b *Builder) WriteQuoteRune(r rune) error
- func (b *Builder) WriteQuoteRuneToASCII(r rune) error
- func (b *Builder) WriteQuoteRuneToGraphic(r rune) error
- func (b *Builder) WriteQuoteToASCII(s string) error
- func (b *Builder) WriteQuoteToGraphic(s string) error
- func (b *Builder) WriteRune(r rune) (int, error)
- func (b *Builder) WriteString(s string) (int, error)
- func (b *Builder) WriteUint(i uint64, base int) error
Examples ¶
- Between
- BetweenF
- Camelize
- Capitalize
- CharAt
- CharAtF
- ChompLeft
- ChompLeftF
- ChompRight
- ChompRightF
- Classify
- Clean
- Dasherize
- DecodeHTMLEntities
- EnsurePrefix
- EnsurePrefixF
- EnsureSuffix
- Humanize
- Iif
- IndexOf
- IsAlpha
- IsAlphaNumeric
- IsEmpty
- IsLower
- IsNumeric
- IsUpper
- Left
- LeftOf
- Lines
- Match
- Pad
- PadLeft
- PadRight
- Pipe
- ReplaceF
- ReplacePattern
- ReplacePatternF
- Reverse
- Right
- RightF
- RightOf
- SliceContains
- SliceIndexOf
- Slugify
- StripPunctuation
- StripTags
- Substr
- Template
- TemplateWithDelimiters
- ToArgv
- ToBool
- ToBoolOr
- ToIntOr
- Underscore
- WrapHTML
- WrapHTMLF
Constants ¶
const ( // DefaultBuilderSize is the default size of the Builder in bytes. DefaultBuilderSize = 1024 // MaxBuilderSize is the maximum size of the Builder in bytes. MaxBuilderSize = 4096 )
Variables ¶
var ToFloatOr = ToFloat64Or
ToFloatOr parses s as a float64 or returns defaultValue.
Parameters:
- s: the string to parse.
- defaultValue: the default value.
Returns:
- float64: the parsed float64 or defaultValue.
var (
Verbose = false
)
Verbose enables console output for functions that have counterparts in Go's standard packages.
Functions ¶
func AsciiEqualFold ¶
AsciiEqualFold is a specialization of bytes.EqualFold for use when s is all ASCII (but may contain non-letters) and contains no special-folding letters. See comments on FoldFunc.
Parameters:
- s: the source bytes.
- t: the target bytes.
Returns:
- bool: true if the strings are equal under folding.
func Between ¶
Between extracts a string between left and right strings.
Parameters:
- s: the source string.
- left: the left delimiter.
- right: the right delimiter.
Returns:
- string: the substring between left and right.
Example ¶
import "strings"
eg(1, Between("<a>foo</a>", "<a>", "</a>"))
eg(2, Between("<a>foo</a></a>", "<a>", "</a>"))
eg(3, Between("<a><a>foo</a></a>", "<a>", "</a>"))
eg(4, Between("<a><a>foo</a></a>", "<a>", "</a>"))
eg(5, Between("<a>foo", "<a>", "</a>"))
eg(6, Between("Some strings } are very {weird}, dont you think?", "{", "}"))
eg(7, Between("This is ateststring", "", "test"))
eg(8, Between("This is ateststring", "test", ""))
Output: 1: foo 2: foo 3: <a>foo 4: <a>foo 5: 6: weird 7: This is a 8: string
func BetweenF ¶
BetweenF is the filter form for Between.
Parameters:
- left: the left delimiter.
- right: the right delimiter.
Returns:
- func(string) string: a function that extracts the substring.
Example ¶
eg(1, Pipe("abc", BetweenF("a", "c")))
Output: 1: b
func Camelize ¶
Camelize returns a new string which removes any underscores or dashes and converts a string into camel casing.
Parameters:
- s: the string to camelize.
Returns:
- string: the camelized string.
Example ¶
eg(1, Camelize("data_rate"))
eg(2, Camelize("background-color"))
eg(3, Camelize("-moz-something"))
eg(4, Camelize("_car_speed_"))
eg(5, Camelize("yes_we_can"))
Output: 1: dataRate 2: backgroundColor 3: MozSomething 4: CarSpeed 5: yesWeCan
func Capitalize ¶
Capitalize uppercases the first char of s and lowercases the rest.
Parameters:
- s: the string to capitalize.
Returns:
- string: the capitalized string.
Example ¶
eg(1, Capitalize("abc"))
eg(2, Capitalize("ABC"))
Output: 1: Abc 2: Abc
func CharAt ¶
CharAt returns a string from the character at the specified position.
Parameters:
- s: the source string.
- index: the position.
Returns:
- string: the character at the specified position.
Example ¶
eg(1, CharAt("abc", 1))
eg(2, CharAt("", -1))
eg(3, CharAt("", 0))
eg(4, CharAt("", 10))
eg(5, CharAt("abc", -1))
eg(6, CharAt("abc", 10))
Output: 1: b 2: 3: 4: 5: 6:
func CharAtF ¶
CharAtF is the filter form of CharAt.
Parameters:
- index: the position.
Returns:
- func(string) string: a function that returns the character at the specified position.
Example ¶
eg(1, Pipe("abc", CharAtF(1)))
Output: 1: b
func ChompLeft ¶
ChompLeft removes prefix at the start of a string.
Parameters:
- s: the source string.
- prefix: the prefix to remove.
Returns:
- string: the string with the prefix removed.
Example ¶
eg(1, ChompLeft("foobar", "foo"))
eg(2, ChompLeft("foobar", "bar"))
eg(3, ChompLeft("", "foo"))
eg(4, ChompLeft("", ""))
eg(5, ChompLeft("foo", ""))
Output: 1: bar 2: foobar 3: 4: 5: foo
func ChompLeftF ¶
ChompLeftF is the filter form of ChompLeft.
Parameters:
- prefix: the prefix to remove.
Returns:
- func(string) string: a function that removes the prefix.
Example ¶
eg(1, Pipe("abc", ChompLeftF("ab")))
Output: 1: c
func ChompRight ¶
ChompRight removes suffix from end of s.
Parameters:
- s: the source string.
- suffix: the suffix to remove.
Returns:
- string: the string with the suffix removed.
Example ¶
eg(1, ChompRight("foobar", "foo"))
eg(2, ChompRight("foobar", "bar"))
eg(3, ChompRight("", "foo"))
eg(4, ChompRight("", ""))
Output: 1: foobar 2: foo 3: 4:
func ChompRightF ¶
ChompRightF is the filter form of ChompRight.
Parameters:
- suffix: the suffix to remove.
Returns:
- func(string) string: a function that removes the suffix.
Example ¶
eg(1, Pipe("abc", ChompRightF("bc")))
Output: 1: a
func Classify ¶
Classify returns a camelized string with the first letter upper cased.
Parameters:
- s: the string to classify.
Returns:
- string: the classified string.
Example ¶
eg(1, Classify("data_rate"))
eg(2, Classify("background-color"))
eg(3, Classify("-moz-something"))
eg(4, Classify("_car_speed_"))
eg(5, Classify("yes_we_can"))
Output: 1: DataRate 2: BackgroundColor 3: MozSomething 4: CarSpeed 5: YesWeCan
func ClassifyF ¶
ClassifyF is the filter form of Classify.
Parameters:
- s: the string to classify.
Returns:
- func(string) string: a function that classifies the string.
func Clean ¶
Clean compresses all adjacent whitespace to a single space and trims s.
Parameters:
- s: the string to clean.
Returns:
- string: the cleaned string.
Example ¶
eg(1, Clean("clean"))
eg(2, Clean(""))
eg(3, Clean(" please\t clean \t \n me "))
Output: 1: clean 2: 3: please clean me
func Dasherize ¶
Dasherize converts a camel cased string into a string delimited by dashes.
Parameters:
- s: the string to dasherize.
Returns:
- string: the dasherized string.
Example ¶
eg(1, Dasherize("dataRate"))
eg(2, Dasherize("CarSpeed"))
eg(3, Dasherize("yesWeCan"))
eg(4, Dasherize(""))
eg(5, Dasherize("ABC"))
Output: 1: data-rate 2: -car-speed 3: yes-we-can 4: 5: -a-b-c
func DecodeHTMLEntities ¶
DecodeHTMLEntities decodes HTML entities into their proper string representation. DecodeHTMLEntities is an alias for html.UnescapeString.
Parameters:
- s: the string to decode.
Returns:
- string: the decoded string.
Example ¶
eg(1, DecodeHTMLEntities("Ken Thompson & Dennis Ritchie"))
eg(2, DecodeHTMLEntities("3 < 4"))
eg(3, DecodeHTMLEntities("http://"))
Output: 1: Ken Thompson & Dennis Ritchie 2: 3 < 4 3: http://
func DotCase ¶ added in v0.3.9
DotCase converts an arbitrary string to a dot-case string (e.g., service.name).
Parameters:
- s: the string to convert.
Returns:
- string: the dot-cased string.
func EnsurePrefix ¶
EnsurePrefix ensures s starts with prefix.
Parameters:
- s: the source string.
- prefix: the prefix to ensure.
Returns:
- string: the string with the prefix.
Example ¶
eg(1, EnsurePrefix("foobar", "foo"))
eg(2, EnsurePrefix("bar", "foo"))
eg(3, EnsurePrefix("", ""))
eg(4, EnsurePrefix("foo", ""))
eg(5, EnsurePrefix("", "foo"))
Output: 1: foobar 2: foobar 3: 4: foo 5: foo
func EnsurePrefixF ¶
EnsurePrefixF is the filter form of EnsurePrefix.
Parameters:
- prefix: the prefix to ensure.
Returns:
- func(string) string: a function that ensures the prefix.
Example ¶
eg(1, Pipe("dir", EnsurePrefixF("./")))
Output: 1: ./dir
func EnsureSuffix ¶
EnsureSuffix ensures s ends with suffix.
Parameters:
- s: the source string.
- suffix: the suffix to ensure.
Returns:
- string: the string with the suffix.
Example ¶
eg(1, EnsureSuffix("foobar", "bar"))
eg(2, EnsureSuffix("foo", "bar"))
eg(3, EnsureSuffix("", ""))
eg(4, EnsureSuffix("foo", ""))
eg(5, EnsureSuffix("", "bar"))
Output: 1: foobar 2: foobar 3: 4: foo 5: bar
func EnsureSuffixF ¶
EnsureSuffixF is the filter form of EnsureSuffix.
Parameters:
- suffix: the suffix to ensure.
Returns:
- func(string) string: a function that ensures the suffix.
func EnumValueName ¶
EnumValueName derives the camel-cased enum value name. See protoc v3.8.0: src/google/protobuf/descriptor.cc:297-313
Parameters:
- s: the enum value.
Returns:
- string: the camel-cased enum value name.
func EqualFoldRight ¶
EqualFoldRight is a specialization of bytes.EqualFold when s is known to be all ASCII (including punctuation), but contains an 's', 'S', 'k', or 'K', requiring a Unicode fold on the bytes in t. See comments on FoldFunc.
Parameters:
- s: the source bytes.
- t: the target bytes.
Returns:
- bool: true if the strings are equal under folding.
func EscapeHTML ¶
EscapeHTML is an alias for html.EscapeString.
Parameters:
- s: the string to escape.
Returns:
- string: the escaped string.
func FoldFunc ¶
FoldFunc returns one of four different case folding equivalence functions, from most general (and slow) to fastest:
- bytes.EqualFold, if the key s contains any non-ASCII UTF-8
- EqualFoldRight, if s contains special folding ASCII ('k', 'K', 's', 'S')
- AsciiEqualFold, no special, but includes non-letters (including _)
- SimpleLetterEqualFold, no specials, no non-letters.
The letters S and K are special because they map to 3 runes, not just 2:
- S maps to s and to U+017F 'ſ' Latin small letter long s
- k maps to K and to U+212A 'K' Kelvin sign
See https://play.golang.org/p/tTxjOc0OGo
The returned function is specialized for matching against s and should only be given s. It's not curried for performance reasons.
Parameters:
- s: the byte slice to match against.
Returns:
- func(s, t []byte) bool: a case folding function.
func GetBuilder ¶
GetBuilder retrieves a strings.Builder from the pool.
Returns:
- *strings.Builder: a Builder from the pool.
func GoCamelCase ¶
GoCamelCase camel-cases a protobuf name for use as a Go identifier.
If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.
Parameters:
- s: the string to convert.
Returns:
- string: the camel-cased string.
func GoSanitized ¶
GoSanitized converts a string to a valid Go identifier.
Parameters:
- s: the string to convert.
Returns:
- string: a valid Go identifier.
func Humanize ¶
Humanize transforms s into a human friendly form.
Parameters:
- s: the string to humanize.
Returns:
- string: the humanized string.
Example ¶
eg(1, Humanize("the_humanize_string_method"))
eg(2, Humanize("ThehumanizeStringMethod"))
eg(3, Humanize("the humanize string method"))
Output: 1: The humanize string method 2: Thehumanize string method 3: The humanize string method
func Iif ¶
Iif is short for immediate if. If condition is true return truthy else falsey.
Parameters:
- condition: the condition.
- truthy: the value to return if condition is true.
- falsey: the value to return if condition is false.
Returns:
- string: truthy or falsey.
Example ¶
eg(1, Iif(true, "T", "F")) eg(2, Iif(false, "T", "F"))
Output: 1: T 2: F
func IndexOf ¶
IndexOf finds the index of needle in s starting from start.
Parameters:
- s: the source string.
- needle: the substring to find.
- start: the starting index.
Returns:
- int: the index of needle, or -1 if not found.
Example ¶
eg(1, IndexOf("abcdef", "a", 0))
eg(2, IndexOf("abcdef", "a", 3))
eg(3, IndexOf("abcdef", "a", -2))
eg(4, IndexOf("abcdef", "a", 10))
eg(5, IndexOf("", "a", 0))
eg(6, IndexOf("abcdef", "", 2))
eg(7, IndexOf("abcdef", "", 1000))
Output: 1: 0 2: -1 3: -1 4: -1 5: -1 6: 2 7: 6
func Indices ¶
Indices returns all starting indices of substr in str.
Parameters:
- str: the source string.
- substr: the substring to find.
Returns:
- []int: all starting indices of substr.
func IsAllBlank ¶
IsAllBlank checks if all of the CharSequences are empty ("") or whitespace only.
Parameters:
- ss: the strings to check.
Returns:
- bool: true if all strings are blank.
func IsAllEmpty ¶
IsAllEmpty checks if all of the strings are empty ("").
Parameters:
- ss: the strings to check.
Returns:
- bool: true if all strings are empty.
func IsAlpha ¶
IsAlpha returns true if a string contains only letters from ASCII (a-z,A-Z). Other letters from other languages are not supported.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is alphabetic.
Example ¶
eg(1, IsAlpha("afaf"))
eg(2, IsAlpha("FJslfjkasfs"))
eg(3, IsAlpha("áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ"))
eg(4, IsAlpha("adflj43faljsdf"))
eg(5, IsAlpha("33"))
eg(6, IsAlpha("TT....TTTafafetstYY"))
eg(7, IsAlpha("-áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ"))
Output: 1: true 2: true 3: true 4: false 5: false 6: false 7: false
func IsAlphaNumeric ¶
IsAlphaNumeric returns true if a string contains letters and digits.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is alphanumeric.
Example ¶
eg(1, IsAlphaNumeric("afaf35353afaf"))
eg(2, IsAlphaNumeric("FFFF99fff"))
eg(3, IsAlphaNumeric("99"))
eg(4, IsAlphaNumeric("afff"))
eg(5, IsAlphaNumeric("Infinity"))
eg(6, IsAlphaNumeric("áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ1234567890"))
eg(7, IsAlphaNumeric("-Infinity"))
eg(8, IsAlphaNumeric("-33"))
eg(9, IsAlphaNumeric("aaff.."))
eg(10, IsAlphaNumeric(".áéúóúÁÉÍÓÚãõÃÕàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛäëïöüÄËÏÖÜçÇ1234567890"))
Output: 1: true 2: true 3: true 4: true 5: true 6: true 7: false 8: false 9: false 10: false
func IsAnyBlank ¶
IsAnyBlank checks if any of the string are empty ("") or whitespace only.
Parameters:
- ss: the strings to check.
Returns:
- bool: true if any string is blank.
func IsAnyEmpty ¶
IsAnyEmpty checks if any of the strings are empty ("").
Parameters:
- ss: the strings to check.
Returns:
- bool: true if any string is empty.
func IsBlank ¶
IsBlank checks if a string is empty ("") or whitespace only.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is blank.
func IsEmpty ¶
IsEmpty returns true if the string is solely composed of whitespace.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is empty.
Example ¶
eg(1, IsEmpty(" "))
eg(2, IsEmpty("\t\t\t "))
eg(3, IsEmpty("\t\n "))
eg(4, IsEmpty("hi"))
Output: 1: true 2: true 3: true 4: false
func IsLower ¶
IsLower returns true if s is comprised of all lower case characters.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is all lowercase.
Example ¶
eg(1, IsLower("a"))
eg(2, IsLower("A"))
eg(3, IsLower("abc"))
eg(4, IsLower("aBc"))
eg(5, IsLower("áéúóúãõàèìòùâêîôûäëïöüç"))
eg(6, IsLower("hi jp"))
eg(7, IsLower("ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÇ"))
eg(8, IsLower("áéúóúãõàèìòùâêîôûäëïöüçÁ"))
eg(9, IsLower("áéúóúãõàèìòùâêîôû äëïöüç"))
Output: 1: true 2: false 3: true 4: false 5: true 6: false 7: false 8: false 9: false
func IsNotBlank ¶
IsNotBlank checks if a string is not empty ("") and not whitespace only.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is not blank.
func IsNotEmpty ¶
IsNotEmpty checks if a string is not empty ("").
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is not empty.
func IsNumeric ¶
IsNumeric returns true if a string contains only digits from 0-9. Other digits not in Latin (such as Arabic) are not currently supported.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is numeric.
Example ¶
eg(1, IsNumeric("3"))
eg(2, IsNumeric("34.22"))
eg(3, IsNumeric("-22.33"))
eg(4, IsNumeric("NaN"))
eg(5, IsNumeric("Infinity"))
eg(6, IsNumeric("-Infinity"))
eg(7, IsNumeric("JP"))
eg(8, IsNumeric("-5"))
eg(9, IsNumeric("00099242424"))
Output: 1: true 2: false 3: false 4: false 5: false 6: false 7: false 8: false 9: true
func IsUpper ¶
IsUpper returns true if s contains all upper case characters.
Parameters:
- s: the string to check.
Returns:
- bool: true if the string is all uppercase.
Example ¶
eg(1, IsUpper("a"))
eg(2, IsUpper("A"))
eg(3, IsUpper("ABC"))
eg(4, IsUpper("aBc"))
eg(5, IsUpper("áéúóúãõàèìòùâêîôûäëïöüç"))
eg(6, IsUpper("HI JP"))
eg(7, IsUpper("ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÇ"))
eg(8, IsUpper("áéúóúãõàèìòùâêîôûäëïöüçÁ"))
eg(9, IsUpper("ÁÉÍÓÚÃÕÀÈÌÒÙÂÊÎ ÔÛÄËÏÖÜÇ"))
Output: 1: false 2: true 3: true 4: false 5: false 6: false 7: true 8: false 9: false
func IsValidNumber ¶
IsValidNumber reports whether s is a valid number.
Parameters:
- s: the string to check.
Returns:
- bool: true if s is a valid number.
func JSONCamelCase ¶
JSONCamelCase converts a snake_case identifier to a camelCase identifier, according to the protobuf JSON specification.
Parameters:
- s: the string to convert.
Returns:
- string: the camel-cased string.
func JSONSnakeCase ¶
JSONSnakeCase converts a camelCase identifier to a snake_case identifier, according to the protobuf JSON specification.
Parameters:
- s: the string to convert.
Returns:
- string: the snake-cased string.
func JoinBool ¶
JoinBool joins a slice of booleans into a string.
Parameters:
- es: the slice of booleans.
- sep: the separator.
Returns:
- string: the joined string.
func JoinFloat ¶
func JoinFloat[E constraints.Float](es []E, sep string) string
JoinFloat joins a slice of floats into a string.
Parameters:
- es: the slice of floats.
- sep: the separator.
Returns:
- string: the joined string.
func JoinInt ¶
func JoinInt[E constraints.Signed](es []E, sep string) string
JoinInt joins a slice of signed integers into a string.
Parameters:
- es: the slice of integers.
- sep: the separator.
Returns:
- string: the joined string.
func JoinUint ¶
func JoinUint[E constraints.Unsigned](es []E, sep string) string
JoinUint joins a slice of unsigned integers into a string.
Parameters:
- es: the slice of unsigned integers.
- sep: the separator.
Returns:
- string: the joined string.
func KebabCase ¶ added in v0.3.9
KebabCase converts an arbitrary string to a kebab-case string that complies with domain name specifications.
Parameters:
- s: the string to convert.
Returns:
- string: the kebab-cased string.
func Left ¶
Left returns the left substring of length n.
Parameters:
- s: the source string.
- n: the length.
Returns:
- string: the left substring.
Example ¶
eg(1, Left("abcdef", 0))
eg(2, Left("abcdef", 1))
eg(3, Left("abcdef", 4))
eg(4, Left("abcdef", -2))
Output: 1: 2: a 3: abcd 4: ef
func LeftF ¶
LeftF is the filter form of Left.
Parameters:
- n: the length.
Returns:
- func(string) string: a function that returns the left substring.
func LeftOf ¶
LeftOf returns the substring left of needle.
Parameters:
- s: the source string.
- needle: the delimiter.
Returns:
- string: the substring left of needle.
Example ¶
eg(1, LeftOf("abcdef", "def"))
eg(2, LeftOf("abcdef", "abc"))
eg(3, LeftOf("abcdef", ""))
eg(4, LeftOf("", "abc"))
eg(5, LeftOf("abcdef", "xyz"))
Output: 1: abc 2: 3: abcdef 4: 5:
func Letters ¶
Letters returns an array of runes as strings so it can be indexed into.
Parameters:
- s: the source string.
Returns:
- []string: an array of runes as strings.
func Lines ¶
Lines converts windows newlines to unix newlines then converts to an array of lines.
Parameters:
- s: the source string.
Returns:
- []string: an array of lines.
Example ¶
eg(1, Lines("a\r\nb\nc\r\n"))
eg(2, Lines("a\r\nb\nc\r\nd"))
Output: 1: [a b c ] 2: [a b c d]
func Map ¶
Map maps an array's items through an iterator.
Parameters:
- arr: the array to map.
- iterator: the mapping function.
Returns:
- []string: the mapped array.
func MapEntryName ¶
MapEntryName derives the name of the map entry message given the field name. See protoc v3.8.0: src/google/protobuf/descriptor.cc:254-276,6057
Parameters:
- s: the field name.
Returns:
- string: the map entry message name.
func Match ¶
Match returns true if pattern matches the string.
Parameters:
- s: the source string.
- pattern: the regexp pattern.
Returns:
- bool: true if pattern matches.
Example ¶
eg(1, Match("foobar", `^fo.*r$`))
eg(2, Match("foobar", `^fo.*x$`))
eg(3, Match("", `^fo.*x$`))
Output: 1: true 2: false 3: false
func MatchAll ¶
MatchAll returns all matches of pattern in str.
Parameters:
- str: the source string.
- pattern: the regexp pattern.
Returns:
- []string: all matches.
func Max ¶
func Max[S ~string](a, b S) S
Max returns the greater of a and b.
Parameters:
- a: the first string.
- b: the second string.
Returns:
- S: the greater string.
func Min ¶
func Min[S ~string](a, b S) S
Min returns the lesser of a and b.
Parameters:
- a: the first string.
- b: the second string.
Returns:
- S: the lesser string.
func Pad ¶
Pad pads string s on both sides with c until it has length of n.
Parameters:
- s: the string to pad.
- c: the padding character.
- n: the desired length.
Returns:
- string: the padded string.
Example ¶
eg(1, Pad("hello", "x", 5))
eg(2, Pad("hello", "x", 10))
eg(3, Pad("hello", "x", 11))
eg(4, Pad("hello", "x", 6))
eg(5, Pad("hello", "x", 1))
Output: 1: hello 2: xxxhelloxx 3: xxxhelloxxx 4: xhello 5: hello
func PadF ¶
PadF is the filter form of Pad.
Parameters:
- c: the padding character.
- n: the desired length.
Returns:
- func(string) string: a function that pads the string.
func PadLeft ¶
PadLeft pads s on left side with c until it has length of n.
Parameters:
- s: the string to pad.
- c: the padding character.
- n: the desired length.
Returns:
- string: the left-padded string.
Example ¶
eg(1, PadLeft("hello", "x", 5))
eg(2, PadLeft("hello", "x", 10))
eg(3, PadLeft("hello", "x", 11))
eg(4, PadLeft("hello", "x", 6))
eg(5, PadLeft("hello", "x", 1))
Output: 1: hello 2: xxxxxhello 3: xxxxxxhello 4: xhello 5: hello
func PadLeftF ¶
PadLeftF is the filter form of PadLeft.
Parameters:
- c: the padding character.
- n: the desired length.
Returns:
- func(string) string: a function that left-pads the string.
func PadRight ¶
PadRight pads s on right side with c until it has length of n.
Parameters:
- s: the string to pad.
- c: the padding character.
- n: the desired length.
Returns:
- string: the right-padded string.
Example ¶
eg(1, PadRight("hello", "x", 5))
eg(2, PadRight("hello", "x", 10))
eg(3, PadRight("hello", "x", 11))
eg(4, PadRight("hello", "x", 6))
eg(5, PadRight("hello", "x", 1))
Output: 1: hello 2: helloxxxxx 3: helloxxxxxx 4: hellox 5: hello
func PadRightF ¶
PadRightF is the filter form of PadRight.
Parameters:
- c: the padding character.
- n: the desired length.
Returns:
- func(string) string: a function that right-pads the string.
func Pipe ¶
Pipe pipes s through one or more string filters.
Parameters:
- s: the source string.
- funcs: the filter functions.
Returns:
- string: the piped string.
Example ¶
eg(1, Pipe("\nabcdef \n", Clean, BetweenF("a", "f"), ChompLeftF("bc")))
Output: 1: de
func PutBuilder ¶
PutBuilder returns a strings.Builder to the pool.
Parameters:
- buf: the Builder to return.
func QuoteItems ¶
QuoteItems quotes all items in array, mostly for debugging.
Parameters:
- arr: the array to quote.
Returns:
- []string: the quoted items.
func Remove ¶
Remove takes a string candidate and a string of chars to remove from the candidate.
Parameters:
- s: the source string.
- chars: the characters to remove.
Returns:
- string: the string with characters removed.
func ReplaceF ¶
ReplaceF is the filter form of strings.Replace.
Parameters:
- old: the substring to replace.
- new: the replacement substring.
- n: the number of replacements.
Returns:
- func(string) string: a function that replaces substrings.
Example ¶
eg(1, Pipe("abcdefab", ReplaceF("ab", "x", -1)))
eg(2, Pipe("abcdefab", ReplaceF("ab", "x", 1)))
eg(3, Pipe("abcdefab", ReplaceF("ab", "x", 0)))
Output: 1: xcdefx 2: xcdefab 3: abcdefab
func ReplaceFunc ¶
ReplaceFunc replaces each rune in str with the result of f.
Parameters:
- str: the source string.
- f: the replacement function.
Returns:
- string: the replaced string.
func ReplacePattern ¶
ReplacePattern replaces string with regexp string. ReplacePattern returns a copy of src, replacing matches of the Regexp with the replacement string repl. Inside repl, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first submatch.
Parameters:
- s: the source string.
- pattern: the regexp pattern.
- repl: the replacement string.
Returns:
- string: the replaced string.
Example ¶
eg(1, ReplacePattern("aabbcc", `a`, "x"))
Output: 1: xxbbcc
func ReplacePatternF ¶
ReplacePatternF is the filter form of ReplacePattern.
Parameters:
- pattern: the regexp pattern.
- repl: the replacement string.
Returns:
- func(string) string: a function that replaces patterns.
Example ¶
eg(1, Pipe("aabbcc", ReplacePatternF(`a`, "x")))
Output: 1: xxbbcc
func Reverse ¶
Reverse reverses a string.
Parameters:
- s: the string to reverse.
Returns:
- string: the reversed string.
Example ¶
eg(1, Reverse("abc"))
eg(2, Reverse("中文"))
Output: 1: cba 2: 文中
func Right ¶
Right returns the right substring of length n.
Parameters:
- s: the source string.
- n: the length.
Returns:
- string: the right substring.
Example ¶
eg(1, Right("abcdef", 0))
eg(2, Right("abcdef", 1))
eg(3, Right("abcdef", 4))
eg(4, Right("abcdef", -2))
Output: 1: 2: f 3: cdef 4: ab
func RightF ¶
RightF is the filter form of Right.
Parameters:
- n: the length.
Returns:
- func(string) string: a function that returns the right substring.
Example ¶
eg(1, Pipe("abcdef", RightF(3)))
Output: 1: def
func RightOf ¶
RightOf returns the substring to the right of prefix.
Parameters:
- s: the source string.
- prefix: the prefix.
Returns:
- string: the substring to the right of prefix.
Example ¶
eg(1, RightOf("abcdef", "abc"))
eg(2, RightOf("abcdef", "def"))
eg(3, RightOf("abcdef", ""))
eg(4, RightOf("", "abc"))
eg(5, RightOf("abcdef", "xyz"))
Output: 1: def 2: 3: abcdef 4: 5:
func SetTemplateDelimiters ¶
func SetTemplateDelimiters(opening, closing string)
SetTemplateDelimiters sets the delimiters for Template function. Defaults to "{{" and "}}".
Parameters:
- opening: the opening delimiter.
- closing: the closing delimiter.
func SimpleLetterEqualFold ¶
SimpleLetterEqualFold is a specialization of bytes.EqualFold for use when s is all ASCII letters (no underscores, etc) and also doesn't contain 'k', 'K', 's', or 'S'. See comments on FoldFunc.
Parameters:
- s: the source bytes.
- t: the target bytes.
Returns:
- bool: true if the strings are equal under folding.
func Slice ¶
Slice slices a string. If end is negative then it is from the end of the string.
Parameters:
- s: the source string.
- start: the start index.
- end: the end index.
Returns:
- string: the sliced string.
func SliceContains ¶
SliceContains determines whether val is an element in slice.
Parameters:
- slice: the slice to search.
- val: the value to find.
Returns:
- bool: true if val is in the slice.
Example ¶
eg(1, SliceContains([]string{"foo", "bar"}, "foo"))
eg(2, SliceContains(nil, "foo"))
eg(3, SliceContains([]string{"foo", "bar"}, "bah"))
eg(4, SliceContains([]string{"foo", "bar"}, ""))
Output: 1: true 2: false 3: false 4: false
func SliceF ¶
SliceF is the filter form of Slice.
Parameters:
- start: the start index.
- end: the end index.
Returns:
- func(string) string: a function that slices the string.
func SliceIndexOf ¶
SliceIndexOf gets the index of val in slice. Returns -1 if not found.
Parameters:
- slice: the slice to search.
- val: the value to find.
Returns:
- int: the index of val, or -1 if not found.
Example ¶
eg(1, SliceIndexOf([]string{"foo", "bar"}, "foo"))
eg(2, SliceIndexOf(nil, "foo"))
eg(3, SliceIndexOf([]string{"foo", "bar"}, "bah"))
eg(4, SliceIndexOf([]string{"foo", "bar"}, ""))
eg(5, SliceIndexOf([]string{"foo", "bar"}, "bar"))
Output: 1: 0 2: -1 3: -1 4: -1 5: 1
func Slugify ¶
Slugify converts s into a dasherized string suitable for URL segment.
Parameters:
- s: the string to slugify.
Returns:
- string: the slugified string.
Example ¶
eg(1, Slugify("foo bar"))
eg(2, Slugify("foo/bar bah"))
eg(3, Slugify("foo-bar--bah"))
Output: 1: foo-bar 2: foobar-bah 3: foo-bar-bah
func StripPunctuation ¶
StripPunctuation strips punctuation from string.
Parameters:
- s: the string to strip.
Returns:
- string: the string without punctuation.
Example ¶
eg(1, StripPunctuation("My, st[ring] *full* of %punct)"))
Output: 1: My string full of punct
func StripTags ¶
StripTags strips all of the html tags or tags specified by the parameters.
Parameters:
- s: the source string.
- tags: the tags to strip (optional).
Returns:
- string: the string with tags stripped.
Example ¶
eg(1, StripTags("<p>just <b>some</b> text</p>"))
eg(2, StripTags("<p>just <b>some</b> text</p>", "p"))
eg(3, StripTags("<a><p>just <b>some</b> text</p></a>", "a", "p"))
eg(4, StripTags("<a><p>just <b>some</b> text</p></a>", "b"))
Output: 1: just some text 2: just <b>some</b> text 3: just <b>some</b> text 4: <a><p>just some text</p></a>
func Substr ¶
Substr returns a substring of s starting at index of length n.
Parameters:
- s: the source string.
- index: the start index.
- n: the length.
Returns:
- string: the substring.
Example ¶
eg(1, Substr("abcdef", 2, -1))
eg(2, Substr("abcdef", 2, 0))
eg(3, Substr("abcdef", 2, 1))
eg(4, Substr("abcdef", 2, 3))
eg(5, Substr("abcdef", 2, 4))
eg(6, Substr("abcdef", 2, 100))
eg(7, Substr("abcdef", 0, 1))
Output: 1: 2: 3: c 4: cde 5: cdef 6: cdef 7: a
func SubstrF ¶
SubstrF is the filter form of Substr.
Parameters:
- index: the start index.
- n: the length.
Returns:
- func(string) string: a function that returns the substring.
func Template ¶
Template is a string template which replaces template placeholders delimited by "{{" and "}}" with values from map. The global delimiters may be set with SetTemplateDelimiters.
Parameters:
- s: the template string.
- values: the map of values.
Returns:
- string: the templated string.
Example ¶
eg(1, Template("Hello {{name}} at {{date-year}}", map[string]interface{}{"name": "foo", "date-year": 2014}))
eg(2, Template("Hello {{name}}", map[string]interface{}{"name": ""}))
SetTemplateDelimiters("{", "}")
eg(3, Template("Hello {name} at {date-year}", map[string]interface{}{"name": "foo", "date-year": 2014}))
Output: 1: Hello foo at 2014 2: Hello 3: Hello foo at 2014
func TemplateDelimiters ¶
TemplateDelimiters returns the opening and closing delimiters for Template.
Returns:
- opening: the opening delimiter.
- closing: the closing delimiter.
func TemplateWithDelimiters ¶
func TemplateWithDelimiters(s string, values map[string]interface{}, opening, closing string) string
TemplateWithDelimiters is a string template with user-definable opening and closing delimiters.
Parameters:
- s: the template string.
- values: the map of values.
- opening: the opening delimiter.
- closing: the closing delimiter.
Returns:
- string: the templated string.
Example ¶
eg(1, TemplateWithDelimiters("Hello {{name}} at {{date-year}}", map[string]interface{}{"name": "foo", "date-year": 2014}, "{{", "}}"))
eg(2, TemplateWithDelimiters("Hello #{name} at #{date-year}", map[string]interface{}{"name": "foo", "date-year": 2014}, "#{", "}"))
eg(3, TemplateWithDelimiters("Hello (name) at (date-year)", map[string]interface{}{"name": "foo", "date-year": 2014}, "(", ")"))
eg(4, TemplateWithDelimiters("Hello [name] at [date-year]", map[string]interface{}{"name": "foo", "date-year": 2014}, "[", "]"))
eg(5, TemplateWithDelimiters("Hello *name* at *date-year*", map[string]interface{}{"name": "foo", "date-year": 2014}, "*", "*"))
eg(6, TemplateWithDelimiters("Hello $name$ at $date-year$", map[string]interface{}{"name": "foo", "date-year": 2014}, "$", "$"))
Output: 1: Hello foo at 2014 2: Hello foo at 2014 3: Hello foo at 2014 4: Hello foo at 2014 5: Hello foo at 2014 6: Hello foo at 2014
func ToArgv ¶
ToArgv converts string s into an argv for exec.
Parameters:
- s: the string to convert.
Returns:
- []string: the argv.
Example ¶
eg(1, QuoteItems(ToArgv(`GO_ENV=test gosu --watch foo@release "some quoted string 'inside'"`))) eg(2, QuoteItems(ToArgv(`gosu foo\ bar`))) eg(3, QuoteItems(ToArgv(`gosu --test="some arg" -w -s a=123`)))
Output: 1: ["GO_ENV=test" "gosu" "--watch" "foo@release" "some quoted string 'inside'"] 2: ["gosu" "foo bar"] 3: ["gosu" "--test=some arg" "-w" "-s" "a=123"]
func ToBool ¶
ToBool fuzzily converts truthy values.
Parameters:
- s: the string to convert.
Returns:
- bool: true if the string is truthy.
Example ¶
eg(1, ToBool("true"))
eg(2, ToBool("yes"))
eg(3, ToBool("1"))
eg(4, ToBool("on"))
eg(5, ToBool("false"))
eg(6, ToBool("no"))
eg(7, ToBool("0"))
eg(8, ToBool("off"))
eg(9, ToBool(""))
eg(10, ToBool("?"))
Output: 1: true 2: true 3: true 4: true 5: false 6: false 7: false 8: false 9: false 10: false
func ToBoolOr ¶
ToBoolOr parses s as a bool or returns defaultValue.
Parameters:
- s: the string to parse.
- defaultValue: the default value.
Returns:
- bool: the parsed bool or defaultValue.
Example ¶
eg(1, ToBoolOr("foo", true))
eg(2, ToBoolOr("foo", false))
eg(3, ToBoolOr("true", false))
eg(4, ToBoolOr("", true))
Output: 1: true 2: false 3: true 4: true
func ToFloat32Or ¶
ToFloat32Or parses s as a float32 or returns defaultValue on error.
Parameters:
- s: the string to parse.
- defaultValue: the default value.
Returns:
- float32: the parsed float32 or defaultValue.
func ToFloat64Or ¶
ToFloat64Or parses s as a float64 or returns defaultValue.
Parameters:
- s: the string to parse.
- defaultValue: the default value.
Returns:
- float64: the parsed float64 or defaultValue.
func ToIntOr ¶
ToIntOr parses s as an int or returns defaultValue.
Parameters:
- s: the string to parse.
- defaultValue: the default value.
Returns:
- int: the parsed int or defaultValue.
Example ¶
eg(1, ToIntOr("foo", 0))
eg(2, ToIntOr("", 1))
eg(3, ToIntOr("100", 0))
eg(4, ToIntOr("-1", 1))
Output: 1: 0 2: 1 3: 100 4: -1
func TrimEnumPrefix ¶
TrimEnumPrefix trims the enum name prefix from an enum value name, where the prefix is all lowercase without underscores. See protoc v3.8.0: src/google/protobuf/descriptor.cc:330-375
Parameters:
- s: the enum value name.
- prefix: the prefix to trim.
Returns:
- string: the trimmed enum value name.
func Underscore ¶
Underscore returns converted camel cased string into a string delimited by underscores.
Parameters:
- s: the string to convert.
Returns:
- string: the underscored string.
Example ¶
eg(1, Underscore("fooBar"))
eg(2, Underscore("FooBar"))
eg(3, Underscore(""))
eg(4, Underscore("x"))
Output: 1: foo_bar 2: _foo_bar 3: 4: x
func UnescapeHTML ¶
UnescapeHTML is an alias for html.UnescapeString.
Parameters:
- s: the string to unescape.
Returns:
- string: the unescaped string.
func WrapHTML ¶
WrapHTML wraps s within HTML tag having attributes attrs. Note, WrapHTML does not escape s value.
Parameters:
- s: the string to wrap.
- tag: the HTML tag.
- attrs: the HTML attributes.
Returns:
- string: the wrapped HTML string.
Example ¶
eg(1, WrapHTML("foo", "span", nil))
eg(2, WrapHTML("foo", "", nil))
eg(3, WrapHTML("foo", "", map[string]string{"class": "bar"}))
Output: 1: <span>foo</span> 2: <div>foo</div> 3: <div class="bar">foo</div>
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder wraps strings.Builder with nil-check lazy initialization.
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder creates a new Builder.
Returns:
- *Builder: a new Builder.
func NewBuilderBuilder ¶
NewBuilderBuilder creates a new Builder from an existing strings.Builder.
Parameters:
- b: the strings.Builder to wrap.
Returns:
- *Builder: a new Builder.
func (*Builder) Cap ¶
Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.
Returns:
- int: the capacity of the underlying byte slice.
func (*Builder) Grow ¶
Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.
Parameters:
- n: the number of bytes to grow.
func (*Builder) Len ¶
Len returns the number of accumulated bytes; b.Len() == len(b.String()).
Returns:
- int: the number of accumulated bytes.
func (*Builder) String ¶
String returns the accumulated string.
Returns:
- string: the accumulated string.
func (*Builder) Write ¶
Write appends the contents of p to b's buffer. Write always returns len(p), nil.
Parameters:
- p: the bytes to write.
Returns:
- int: the number of bytes written.
- error: always nil.
func (*Builder) WriteBool ¶
WriteBool appends "true" or "false".
Parameters:
- bl: the boolean to write.
Returns:
- error: any error encountered.
func (*Builder) WriteByte ¶
WriteByte appends the byte c to b's buffer. The returned error is always nil.
Parameters:
- c: the byte to write.
Returns:
- error: always nil.
func (*Builder) WriteFloat ¶
WriteFloat appends the string form of the floating-point number f.
Parameters:
- f: the float to write.
- fmt: the format.
- prec: the precision.
- bitSize: the bit size.
Returns:
- error: any error encountered.
func (*Builder) WriteInt ¶
WriteInt appends the string form of the integer i.
Parameters:
- i: the integer to write.
- base: the base to use.
Returns:
- error: any error encountered.
func (*Builder) WriteQuote ¶
WriteQuote appends a double-quoted Go string literal representing s.
Parameters:
- s: the string to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteQuoteRune ¶
WriteQuoteRune appends a single-quoted Go character literal representing the rune.
Parameters:
- r: the rune to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteQuoteRuneToASCII ¶
WriteQuoteRuneToASCII appends a single-quoted Go character literal representing the rune.
Parameters:
- r: the rune to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteQuoteRuneToGraphic ¶
WriteQuoteRuneToGraphic appends a single-quoted Go character literal representing the rune.
Parameters:
- r: the rune to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteQuoteToASCII ¶
WriteQuoteToASCII appends a double-quoted Go string literal representing s.
Parameters:
- s: the string to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteQuoteToGraphic ¶
WriteQuoteToGraphic appends a double-quoted Go string literal representing s.
Parameters:
- s: the string to quote.
Returns:
- error: any error encountered.
func (*Builder) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.
Parameters:
- r: the rune to write.
Returns:
- int: the length of the rune.
- error: always nil.
func (*Builder) WriteString ¶
WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.
Parameters:
- s: the string to write.
Returns:
- int: the length of the string.
- error: always nil.