std/strconv
import "github.com/eugenioenko/goalchemy/std/strconv"Package strconv converts between integers, Booleans, and their string forms, and formats floating-point numbers.
const IntSize = 64IntSize is the size in bits of an int or uint value.
var ErrRange = errors.New("value out of range")ErrRange indicates that a value is out of range for the target type.
var ErrSyntax = errors.New("invalid syntax")ErrSyntax indicates that a value does not have the right syntax for the target type.
AppendFloat
Section titled “AppendFloat”func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byteAppendFloat appends the string form of the floating-point number f, as generated by FormatFloat, to dst and returns the extended buffer.
AppendInt
Section titled “AppendInt”func AppendInt(dst []byte, i int64, base int) []byteAppendInt appends the string form of i in the given base to dst.
AppendQuote
Section titled “AppendQuote”func AppendQuote(dst []byte, s string) []byteAppendQuote appends the double-quoted Go string literal of s to dst.
AppendQuoteRune
Section titled “AppendQuoteRune”func AppendQuoteRune(dst []byte, r rune) []byteAppendQuoteRune appends the single-quoted character literal of r to dst.
AppendQuoteRuneToASCII
Section titled “AppendQuoteRuneToASCII”func AppendQuoteRuneToASCII(dst []byte, r rune) []byteAppendQuoteRuneToASCII appends the ASCII-only character literal of r to dst.
AppendQuoteToASCII
Section titled “AppendQuoteToASCII”func AppendQuoteToASCII(dst []byte, s string) []byteAppendQuoteToASCII appends the ASCII-only quoted form of s to dst.
AppendUint
Section titled “AppendUint”func AppendUint(dst []byte, u uint64, base int) []byteAppendUint appends the string form of u in the given base to dst.
func Atoi(s string) (int, error)Atoi parses a decimal int, accepting an optional sign.
CanBackquote
Section titled “CanBackquote”func CanBackquote(s string) boolCanBackquote reports whether s can be represented unchanged as a single-line backquoted string without control characters other than tab.
FormatBool
Section titled “FormatBool”func FormatBool(b bool) stringFormatBool returns “true” or “false”.
FormatFloat
Section titled “FormatFloat”func FormatFloat(f float64, fmt byte, prec, bitSize int) stringFormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec. It rounds the result assuming that the original was obtained from a floating-point value of bitSize bits (32 for float32, 64 for float64). The format fmt is one of ‘b’ (-ddddp±ddd), ‘e’ (-d.dddde±dd), ‘E’ (-d.ddddE±dd), ‘f’ (-ddd.dddd), ‘g’ (‘e’ for large exponents, ‘f’ otherwise), ‘G’ (‘E’ for large exponents, ‘f’ otherwise), ‘x’ (-0xd.ddddp±ddd) or ‘X’ (-0Xd.ddddP±ddd). The precision prec controls the number of digits (excluding the exponent) printed by the ‘e’, ‘E’, ‘f’, ‘g’, ‘G’, ‘x’, and ‘X’ formats. For ‘e’, ‘E’, ‘f’, ‘x’, and ‘X’, it is the number of digits after the decimal point. For ‘g’ and ‘G’ it is the maximum number of significant digits (trailing zeros are removed). The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.
FormatInt
Section titled “FormatInt”func FormatInt(i int64, base int) stringFormatInt returns i in the given base, 2 to 36, using lowercase letters.
FormatUint
Section titled “FormatUint”func FormatUint(u uint64, base int) stringFormatUint returns u in the given base, 2 to 36, using lowercase letters.
IsPrint
Section titled “IsPrint”func IsPrint(r rune) boolIsPrint reports whether r is printable as defined by Go: letters, marks, numbers, punctuation, symbols and the ASCII space.
func Itoa(i int) stringItoa returns the decimal form of i.
ParseBool
Section titled “ParseBool”func ParseBool(str string) (bool, error)ParseBool accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, and False.
ParseFloat
Section titled “ParseFloat”func ParseFloat(s string, bitSize int) (float64, error)ParseFloat converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64. It accepts Go’s decimal and hexadecimal floating-point syntax, with “NaN”, “Inf” and “Infinity” in any case, and returns the nearest value under IEEE 754 round-half-to-even. Errors are *NumError values wrapping ErrSyntax or ErrRange; on ErrRange the result is ±Inf.
ParseInt
Section titled “ParseInt”func ParseInt(s string, base int, bitSize int) (int64, error)ParseInt parses a signed integer like ParseUint and checks that it fits in bitSize bits (0 means 64).
ParseUint
Section titled “ParseUint”func ParseUint(s string, base int, bitSize int) (uint64, error)ParseUint parses s in the given base (0 or 2 to 36) and checks that the result fits in bitSize bits (0 means 64). Base 0 accepts 0b, 0o, 0, and 0x prefixes and underscores between digits.
func Quote(s string) stringQuote returns s as a double-quoted Go string literal, escaping non-printable runes and invalid UTF-8 bytes.
QuoteRune
Section titled “QuoteRune”func QuoteRune(r rune) stringQuoteRune returns r as a single-quoted Go character literal. An invalid rune is quoted as the Unicode replacement character.
QuoteRuneToASCII
Section titled “QuoteRuneToASCII”func QuoteRuneToASCII(r rune) stringQuoteRuneToASCII is like QuoteRune but escapes every non-ASCII rune.
QuoteToASCII
Section titled “QuoteToASCII”func QuoteToASCII(s string) stringQuoteToASCII is like Quote but escapes every non-ASCII rune.
type NumError
Section titled “type NumError”type NumError struct { Func string Num string Err error}NumError records a failed conversion.
NumError.Error
Section titled “NumError.Error”func (e *NumError) Error() stringNumError.Unwrap
Section titled “NumError.Unwrap”func (e *NumError) Unwrap() error