Documentation ¶
Overview ¶
Package strconv implements conversions to and from string representations of basic data types.
Index ¶
- Variables
- func Atob(str string) (value bool, err os.Error)
- func Atof32(s string) (f float32, err os.Error)
- func Atof64(s string) (f float64, err os.Error)
- func AtofN(s string, n int) (f float64, err os.Error)
- func Atoi(s string) (i int, err os.Error)
- func Atoi64(s string) (i int64, err os.Error)
- func Atoui(s string) (i uint, err os.Error)
- func Atoui64(s string) (n uint64, err os.Error)
- func Btoa(b bool) string
- func Btoi64(s string, base int) (i int64, err os.Error)
- func Btoui64(s string, b int) (n uint64, err os.Error)
- func CanBackquote(s string) bool
- func Ftoa32(f float32, fmt byte, prec int) string
- func Ftoa64(f float64, fmt byte, prec int) string
- func FtoaN(f float64, fmt byte, prec int, n int) string
- func Itoa(i int) string
- func Itoa64(i int64) string
- func Itob(i int, base uint) string
- func Itob64(i int64, base uint) string
- func Quote(s string) string
- func QuoteRune(rune int) string
- func QuoteRuneToASCII(rune int) string
- func QuoteToASCII(s string) string
- func Uitoa(i uint) string
- func Uitoa64(i uint64) string
- func Uitob(i uint, base uint) string
- func Uitob64(u uint64, base uint) string
- func Unquote(s string) (t string, err os.Error)
- func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string, err os.Error)
- type NumError
Constants ¶
This section is empty.
Variables ¶
var IntSize = computeIntsize()
Functions ¶
func Atob ¶
Atob returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.
func Atof32 ¶
Atof32 converts the string s to a 32-bit floating-point number.
If s is well-formed and near a valid floating point number, Atof32 returns the nearest floating point number rounded using IEEE754 unbiased rounding.
The errors that Atof32 returns have concrete type *NumError and include err.Num = s.
If s is not syntactically well-formed, Atof32 returns err.Error = os.EINVAL.
If s is syntactically well-formed but is more than 1/2 ULP away from the largest floating point number of the given size, Atof32 returns f = ±Inf, err.Error = os.ERANGE.
func Atof64 ¶
Atof64 converts the string s to a 64-bit floating-point number. Except for the type of its result, its definition is the same as that of Atof32.
func AtofN ¶
AtofN converts the string s to a 64-bit floating-point number, but it rounds the result assuming that it will be stored in a value of n bits (32 or 64).
func Atoui64 ¶
Atoui64 interprets a string s as a decimal number and returns the corresponding value n.
Atoui64 returns err == os.EINVAL if s is empty or contains invalid digits. It returns err == os.ERANGE if s cannot be represented by a uint64.
func Btoui64 ¶
Btoui64 interprets a string s in an arbitrary base b (2 to 36) and returns the corresponding value n. If b == 0, the base is taken from the string prefix: base 16 for "0x", base 8 for "0", and base 10 otherwise.
The errors that Btoui64 returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Error = os.EINVAL; if the value corresponding to s cannot be represented by a uint64, err.Error = os.ERANGE.
func CanBackquote ¶
CanBackquote returns whether the string s would be a valid Go string literal if enclosed in backquotes.
func Ftoa32 ¶
Ftoa32 converts the 32-bit floating-point number f to a string, according to the format fmt and precision prec.
The format fmt is one of 'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), or 'G' ('E' for large exponents, 'f' otherwise).
The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the total number of digits. The special precision -1 uses the smallest number of digits necessary such that Atof32 will return f exactly.
Ftoa32(f) is not the same as Ftoa64(float32(f)), because correct rounding and the number of digits needed to identify f depend on the precision of the representation.
func FtoaN ¶
FtoaN converts the 64-bit floating-point number f to a string, according to the format fmt and precision prec, but it rounds the result assuming that it was obtained from a floating-point value of n bits (32 or 64).
func Quote ¶
Quote returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by unicode.IsPrint.
func QuoteRune ¶
QuoteRune returns a single-quoted Go character literal representing the rune. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-printable characters as defined by unicode.IsPrint.
func QuoteRuneToASCII ¶
QuoteRuneToASCII returns a single-quoted Go character literal representing the rune. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by unicode.IsPrint.
func QuoteToASCII ¶
QuoteToASCII returns a double-quoted Go string literal representing s. The returned string uses Go escape sequences (\t, \n, \xFF, \u0100) for non-ASCII characters and non-printable characters as defined by unicode.IsPrint.
func Unquote ¶
Unquote interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes. (If s is single-quoted, it would be a Go character literal; Unquote returns the corresponding one-character string.)
func UnquoteChar ¶
UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values:
- value, the decoded Unicode code point or byte value;
- multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
- tail, the remainder of the string after the character; and
- an error that will be nil if the character is syntactically valid.
The second argument, quote, specifies the type of literal being parsed and therefore which escaped quote character is permitted. If set to a single quote, it permits the sequence \' and disallows unescaped '. If set to a double quote, it permits \" and disallows unescaped ". If set to zero, it does not permit either escape and allows both quote characters to appear unescaped.