Documentation
¶
Overview ¶
Package token contains functions for working with a string as a token.
Index ¶
- Variables
- func Append(caser Caser, t string, elems ...string) string
- func AppendRune(caser Caser, t string, runes ...rune) string
- func FirstRune(s string) (rune, bool)
- func HasLower(s string) bool
- func IsEmpty(s string) bool
- func IsNumber(s string, additionalRules NumberRules) bool
- func LowerFirst(caser Caser, s string) string
- func Reverse(caser Caser, s string) string
- func ToLower(caser Caser, s string) string
- func ToUpper(caser Caser, s string) string
- func UpperFirst(caser Caser, s string) string
- func UpperFirstLowerRest(caser Caser, s string) string
- func Write(b *strings.Builder, caser Caser, e string)
- func WriteLower(b *strings.Builder, caser Caser, s string)
- func WriteRune(b *strings.Builder, caser Caser, r rune)
- func WriteSplitLower(b *strings.Builder, caser Caser, sep string, elems ...string)
- func WriteSplitLowerFirstUpperRest(b *strings.Builder, caser Caser, sep string, s string)
- func WriteSplitLowerFirstUpperRestRunes(b *strings.Builder, caser Caser, sep string, s []rune)
- func WriteSplitLowerRunes(b *strings.Builder, caser Caser, sep string, s []rune)
- func WriteSplitUpper(b *strings.Builder, caser Caser, sep string, elems ...string)
- func WriteSplitUpperRunes(b *strings.Builder, caser Caser, sep string, s []rune)
- func WriteUpper(b *strings.Builder, caser Caser, s string)
- func WriteUpperFirstLowerRest(b *strings.Builder, caser Caser, s string)
- type Caser
- type NumberRules
- type Unicode
Constants ¶
This section is empty.
Variables ¶
var ( // Turkish is a Caser which uses unicode.TurkishCase rules. TurkishCaser = &unicode.TurkishCase // AzeriCaser is a Caser which uses unicode.AzeriCase rules. AzeriCaser = &unicode.AzeriCase )
var DefaultCaser = Unicode{}
Functions ¶
func AppendRune ¶
AppendRune append the rune to the current token.
func HasLower ¶ added in v0.7.0
HasLower returns true if any rune in the token is a unicode lowercase letter.
func IsNumber ¶ added in v0.7.0
func IsNumber(s string, additionalRules NumberRules) bool
IsNumber reports true if the string is considered a valid number based on the following rules:
- If the Token is composed only of numbers
- If the Token is prefixed with any of the following: + - . v V # and followed by a number
- Numbers may only be separated by a single '.' and '.' may be the first rune or proceeded by a number, '+', or '-'
- A single 'e' or 'E' may only be used in the exponent portion of a number
- 'e' or 'E' may be followed
- ',' must be preceded by a number and followed by a number
- if additionalRules is not nil and the rune is present in the map, the result of the provided func overrides the rules above
func LowerFirst ¶ added in v0.7.0
LowerFirst lower cases the first rune of s
func ToUpper ¶ added in v0.7.0
ToLUpper upper cases cases each rune of s using caser and writes to b
func UpperFirst ¶ added in v0.7.0
UpperFirst title cases the first rune of s
func UpperFirstLowerRest ¶ added in v0.7.0
UpperFirstLowerRest title cases the first rune and lower cases the rest of s
func WriteLower ¶ added in v0.7.5
WriteLower uses caser to lower case the runes in s and writes to b
func WriteSplitLower ¶ added in v0.7.5
WriteSplitLower writes all strings in elems separated by sep and written as lower case
func WriteSplitLowerFirstUpperRest ¶ added in v0.7.5
WriteLowerFirstUpperRest writes the first rune as upper case and the rest are separated by sep and written as lower case
func WriteSplitLowerFirstUpperRestRunes ¶ added in v0.8.2
WriteSplitLowerFirstUpperRestRunes writes the first rune as upper case and the rest are separated by sep and written as lower case
func WriteSplitLowerRunes ¶ added in v0.8.2
WriteSplitUpper writes all runes in elems separated by sep and written as lower case
func WriteSplitUpper ¶ added in v0.7.5
WriteSplitUpper writes all strings in elems separated by sep and written as upper case
func WriteSplitUpperRunes ¶ added in v0.8.2
WriteSplitUpperRunes uses caser to upper case each rune and writes each to b, separated by sep
func WriteUpper ¶ added in v0.7.5
WriteUpper uses caser to upper case the runes in s and writes to b
Types ¶
type Caser ¶ added in v0.3.0
type Caser interface {
// ToLower maps the rune to lower case
ToLower(r rune) rune
// ToUpper maps the rune to upper case
ToUpper(r rune) rune
// ToTitle maps the rune to title case
ToTitle(r rune) rune
}
Caser is satisfied by types which can map runes to their lowercase and uppercase equivalents.
func CaserOrDefault ¶ added in v0.3.0
CaserOrDefault returns the default caser if caser is nil.
type NumberRules ¶ added in v0.7.0
NumberRules are a set of rules for determining if rune r at index of val should be considered a number
Example:
NumberRules{
'$': func(i int, r rune, v string) bool {
return i == 0
},
}
type Unicode ¶ added in v0.3.0
type Unicode struct{}
Unicode is a Caser which uses the default unicode casing functions.