Documentation ¶
Overview ¶
Package numberconverter converts contemporary English language numbers ("negative one million three hundred thousand") into signed integers (-1_300_000), and back. numtowords and wordstonum.
Index ¶
- func Etoi(buf []rune) (int64, error)
- func EtoiGeneric[T util.Integer](buf []rune) (T, error)
- func EtoiReplaceAll(str string) string
- func EtoiReplaceAllFunc(str string, f func(i int64) bool) string
- func EtoiString(str string) (int64, error)
- func EtoiStringGeneric[T util.Integer](str string) (T, error)
- func FindAllEnglishNumber(str string, n int) []string
- func FindAllEnglishNumberIndex(str string, n int) [][]int
- func FindEnglishNumber(str string) string
- func FindEnglishNumberIndex(str string) []int
- func Itoe(num int64) string
- func ItoeGeneric[T util.Integer](num T) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Etoi ¶
Etoi (English to Integer) will convert the first instance of an english language number string into an int64. An input of "five" would return 5. This function may not error on some English syntax errors. It assumes correct English.
func EtoiGeneric ¶
EtoiGeneric also converts an english language string into a signed integer, but is generic. This function uses bare type coercion and may result in funky numbers being returned! If you want to guarantee a conversion, consider the non generic version.
func EtoiReplaceAll ¶ added in v0.3.0
EtoiReplaceAll wraps EtoiReplaceAllFunc by always replacing matches.
func EtoiReplaceAllFunc ¶ added in v0.3.0
EtoiReplaceAllFunc allows a user replace all the instances of an English number in a given string with its numerical representation if the given function returns true. The given function is passed the integer representation of the matched English number.
func EtoiString ¶ added in v0.3.0
EtoiString wraps Etoi, converting the given string to a rune array
func EtoiStringGeneric ¶ added in v0.3.0
EtoiStringGeneric allows generic usage of EtoiString. Like EtoiGeneric, it also uses bare type coercion: use types with a lower maximum than int64 at your own risk!
func FindAllEnglishNumber ¶ added in v0.3.0
FindAllEnglishNumber wraps FindAllEnglishNumberIndex but returns a list of strings rather than indexes.
func FindAllEnglishNumberIndex ¶ added in v0.3.0
FindAllEnglishNumberIndex searches a given string for English numbers, returning their indexes in an array. The parameter 'n' specifies the maximum number of numbers returned. If n=-1, all numbers are returned.
func FindEnglishNumber ¶ added in v0.3.0
FindEnglishNumber wraps FindAllEnglishNumber with n=1
func FindEnglishNumberIndex ¶ added in v0.3.0
FindEnglishNumberIndex wraps FindAllEnglishNumberIndex with n=1
func Itoe ¶
Itoe (Integer to English) will convert an int64 into an English language string. For example, an input of 5 would produce "five". The style of the output is always consistent—lower case, no 'and', and hyphenation of numbers 21 to 99.
func ItoeGeneric ¶
Function ItoeGeneric performs the same function as Itoe but is generic.
Types ¶
This section is empty.