token

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package token contains functions for working with a string as a token.

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
var DefaultCaser = Unicode{}

Functions

func Append

func Append(caser Caser, t string, elems ...string) string

Append appends all of elems to t

func AppendRune

func AppendRune(caser Caser, t string, runes ...rune) string

AppendRune append the rune to the current token.

func FirstRune added in v0.7.0

func FirstRune(s string) (rune, bool)

FirstRune returns the first rune of s

func HasLower added in v0.7.0

func HasLower(s string) bool

HasLower returns true if any rune in the token is a unicode lowercase letter.

func IsEmpty added in v0.7.0

func IsEmpty(s string) bool

IsEmpty reports whether s has a len of 0

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

func LowerFirst(caser Caser, s string) string

LowerFirst lower cases the first rune of s

func Reverse added in v0.7.0

func Reverse(caser Caser, s string) string

Reverse reverses s

func ToLower added in v0.7.0

func ToLower(caser Caser, s string) string

ToLower lower cases each rune of s using caser and writes to b

func ToUpper added in v0.7.0

func ToUpper(caser Caser, s string) string

ToLUpper upper cases cases each rune of s using caser and writes to b

func UpperFirst added in v0.7.0

func UpperFirst(caser Caser, s string) string

UpperFirst title cases the first rune of s

func UpperFirstLowerRest added in v0.7.0

func UpperFirstLowerRest(caser Caser, s string) string

UpperFirstLowerRest title cases the first rune and lower cases the rest of s

func Write added in v0.7.5

func Write(b *strings.Builder, caser Caser, e string)

Write writes e to b

func WriteLower added in v0.7.5

func WriteLower(b *strings.Builder, caser Caser, s string)

WriteLower uses caser to lower case the runes in s and writes to b

func WriteRune added in v0.7.5

func WriteRune(b *strings.Builder, caser Caser, r rune)

WriteRune writes the runes to the b.

func WriteSplitLower added in v0.7.5

func WriteSplitLower(b *strings.Builder, caser Caser, sep string, elems ...string)

WriteSplitLower writes all strings in elems separated by sep and written as lower case

func WriteSplitLowerFirstUpperRest added in v0.7.5

func WriteSplitLowerFirstUpperRest(b *strings.Builder, caser Caser, sep string, s string)

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

func WriteSplitLowerFirstUpperRestRunes(b *strings.Builder, caser Caser, sep string, s []rune)

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

func WriteSplitLowerRunes(b *strings.Builder, caser Caser, sep string, s []rune)

WriteSplitUpper writes all runes in elems separated by sep and written as lower case

func WriteSplitUpper added in v0.7.5

func WriteSplitUpper(b *strings.Builder, caser Caser, sep string, elems ...string)

WriteSplitUpper writes all strings in elems separated by sep and written as upper case

func WriteSplitUpperRunes added in v0.8.2

func WriteSplitUpperRunes(b *strings.Builder, caser Caser, sep string, s []rune)

WriteSplitUpperRunes uses caser to upper case each rune and writes each to b, separated by sep

func WriteUpper added in v0.7.5

func WriteUpper(b *strings.Builder, caser Caser, s string)

WriteUpper uses caser to upper case the runes in s and writes to b

func WriteUpperFirstLowerRest added in v0.7.5

func WriteUpperFirstLowerRest(b *strings.Builder, caser Caser, s string)

WriteUpperFirstLowerRest writes the first rune as upper case and the rest as lower case

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

func CaserOrDefault(caser Caser) Caser

CaserOrDefault returns the default caser if caser is nil.

type NumberRules added in v0.7.0

type NumberRules map[rune]func(index int, r rune, val string) bool

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.

func (Unicode) ToLower added in v0.3.0

func (Unicode) ToLower(r rune) rune

ToUpper maps the rune to lower case using unicode.ToLower

func (Unicode) ToTitle added in v0.3.0

func (Unicode) ToTitle(r rune) rune

ToTitle maps the rune to title case using unicode.ToTitle.

func (Unicode) ToUpper added in v0.3.0

func (Unicode) ToUpper(r rune) rune

ToUpper maps the rune to upper case using unicode.ToUpper

Jump to

Keyboard shortcuts

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