strconv

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 6 Imported by: 0

Documentation

Overview

The strconv package implements conversions to and from string representations of basic data types.

Index

Constants

This section is empty.

Variables

View Source
var FloatSize = floatsize()

Floatsize gives the size of the float type, either 32 or 64.

View Source
var IntSize = computeIntsize()

Functions

func Atof

func Atof(s string) (f float, err os.Error)

Atof is like Atof32 or Atof64, depending on the size of float.

func Atof32

func Atof32(s string) (f float32, err os.Error)

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

func Atof64(s string) (f float64, err os.Error)

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 Atoi

func Atoi(s string) (i int, err os.Error)

Atoi is like Atoi64 but returns its result as an int.

func Atoi64

func Atoi64(s string) (i int64, err os.Error)

Atoi64 is like Atoui64 but allows signed numbers and returns its result in an int64.

func Atoui

func Atoui(s string) (i uint, err os.Error)

Atoui is like Atoui64 but returns its result as a uint.

func Atoui64

func Atoui64(s string) (n uint64, err os.Error)

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 Btoi64

func Btoi64(s string, base int) (i int64, err os.Error)

Btoi64 is like Btoui64 but allows signed numbers and returns its result in an int64.

func Btoui64

func Btoui64(s string, b int) (n uint64, err os.Error)

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

func CanBackquote(s string) bool

CanBackquote returns whether the string s would be a valid Go string literal if enclosed in backquotes.

func Ftoa

func Ftoa(f float, fmt byte, prec int) string

Ftoa behaves as Ftoa32 or Ftoa64, depending on the size of the float type.

func Ftoa32

func Ftoa32(f float32, fmt byte, prec int) string

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), 'f' (-ddd.dddd, no exponent), or 'g' ('e' for large exponents, 'f' otherwise).

The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'f', and 'g' formats. For 'e' and 'f' it is the number of digits after the decimal point. For '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 Ftoa64

func Ftoa64(f float64, fmt byte, prec int) string

Ftoa64 is like Ftoa32 but converts a 64-bit floating-point number.

func Itoa

func Itoa(i int) string

Itoa returns the decimal string representation of i.

func Itoa64

func Itoa64(i int64) string

Itoa64 returns the decimal string representation of i.

func Itob

func Itob(i int, base uint) string

Itob returns the string representation of i in the given base.

func Itob64

func Itob64(i int64, base uint) string

Itob64 returns the string representation of i in the given base.

func Quote

func Quote(s string) string

Quote returns a double-quoted Go string literal representing s. The returned string s uses Go escape sequences (\t, \n, \xFF, \u0100) for control characters and non-ASCII characters.

func Uitoa

func Uitoa(i uint) string

Uitoa returns the decimal string representation of i.

func Uitoa64

func Uitoa64(i uint64) string

Uitoa64 returns the decimal string representation of i.

func Uitob

func Uitob(i uint, base uint) string

Uitob returns the string representation of i in the given base.

func Uitob64

func Uitob64(u uint64, base uint) string

Uitob64 returns the string representation of i in the given base.

func Unquote

func Unquote(s string) (t string, err os.Error)

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

func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string, err os.Error)

UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values:

  1. value, the decoded Unicode code point or byte value;
  2. multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
  3. tail, the remainder of the string after the character; and
  4. 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.

Types

type NumError

type NumError struct {
	Num   string
	Error os.Error
}

func (*NumError) String

func (e *NumError) String() string

Jump to

Keyboard shortcuts

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