Package fmt
Overview ▹
Index ▹
Constants
const ( ldigits = "0123456789abcdefx" udigits = "0123456789ABCDEFX" )
const ( signed = true unsigned = false )
Strings for use with buffer.WriteString. This is less overhead than using buffer.Write with byte arrays.
const ( commaSpaceString = ", " nilAngleString = "<nil>" nilParenString = "(nil)" nilString = "nil" mapString = "map[" percentBangString = "%!" missingString = "(MISSING)" badIndexString = "(BADINDEX)" panicString = "(PANIC=" extraString = "%!(EXTRA " badWidthString = "%!(BADWIDTH)" badPrecString = "%!(BADPREC)" noVerbString = "%!(NOVERB)" invReflectString = "<invalid reflect.Value>" )
Numerical elements
const ( binaryDigits = "01" octalDigits = "01234567" decimalDigits = "0123456789" hexadecimalDigits = "0123456789aAbBcCdDeEfF" sign = "+-" period = "." exponent = "eEpP" )
const ( floatVerbs = "beEfFgGv" hugeWid = 1 << 30 intBits = 32 << (^uint(0) >> 63) uintptrBits = 32 << (^uintptr(0) >> 63) )
const eof = -1
Variables
var boolError = errors.New("syntax error scanning boolean")
var complexError = errors.New("syntax error scanning complex number")
var ppFree = sync.Pool{ New: func() interface{} { return new(pp) }, }
space is a copy of the unicode.White_Space ranges, to avoid depending on package unicode.
var space = [][2]uint16{ {0x0009, 0x000d}, {0x0020, 0x0020}, {0x0085, 0x0085}, {0x00a0, 0x00a0}, {0x1680, 0x1680}, {0x2000, 0x200a}, {0x2028, 0x2029}, {0x202f, 0x202f}, {0x205f, 0x205f}, {0x3000, 0x3000}, }
var ssFree = sync.Pool{ New: func() interface{} { return new(ss) }, }
func Errorf ¶
func Errorf(format string, a ...interface{}) error
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
If the format specifier includes a %w verb with an error operand, the returned error will implement an Unwrap method returning the operand. It is invalid to include more than one %w verb or to supply it with an operand that does not implement the error interface. The %w verb is otherwise a synonym for %v.
▹ Example
func Fprint ¶
func Fprint(w io.Writer, a ...interface{}) (n int, err error)
Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
▹ Example
func Fprintf ¶
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
▹ Example
func Fprintln ¶
func Fprintln(w io.Writer, a ...interface{}) (n int, err error)
Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
▹ Example
func Fscan ¶
func Fscan(r io.Reader, a ...interface{}) (n int, err error)
Fscan scans text read from r, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.
func Fscanf ¶
func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)
Fscanf scans text read from r, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully parsed. Newlines in the input must match newlines in the format.
▹ Example
func Fscanln ¶
func Fscanln(r io.Reader, a ...interface{}) (n int, err error)
Fscanln is similar to Fscan, but stops scanning at a newline and after the final item there must be a newline or EOF.
▹ Example
func Print ¶
func Print(a ...interface{}) (n int, err error)
Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
▹ Example
func Printf ¶
func Printf(format string, a ...interface{}) (n int, err error)
Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.
▹ Example
func Println ¶
func Println(a ...interface{}) (n int, err error)
Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
▹ Example
func Scan ¶
func Scan(a ...interface{}) (n int, err error)
Scan scans text read from standard input, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.
func Scanf ¶
func Scanf(format string, a ...interface{}) (n int, err error)
Scanf scans text read from standard input, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why. Newlines in the input must match newlines in the format. The one exception: the verb %c always scans the next rune in the input, even if it is a space (or tab etc.) or newline.
func Scanln ¶
func Scanln(a ...interface{}) (n int, err error)
Scanln is similar to Scan, but stops scanning at a newline and after the final item there must be a newline or EOF.
func Sprint ¶
func Sprint(a ...interface{}) string
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
▹ Example
func Sprintf ¶
func Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
▹ Example
func Sprintln ¶
func Sprintln(a ...interface{}) string
Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.
▹ Example
func Sscan ¶
func Sscan(str string, a ...interface{}) (n int, err error)
Sscan scans the argument string, storing successive space-separated values into successive arguments. Newlines count as space. It returns the number of items successfully scanned. If that is less than the number of arguments, err will report why.
func Sscanf ¶
func Sscanf(str string, format string, a ...interface{}) (n int, err error)
Sscanf scans the argument string, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully parsed. Newlines in the input must match newlines in the format.
▹ Example
func Sscanln ¶
func Sscanln(str string, a ...interface{}) (n int, err error)
Sscanln is similar to Sscan, but stops scanning at a newline and after the final item there must be a newline or EOF.
func errorHandler ¶
func errorHandler(errp *error)
errorHandler turns local panics into error returns.
func getField ¶
func getField(v reflect.Value, i int) reflect.Value
getField gets the i'th field of the struct value. If the field is itself is an interface, return a value for the thing inside the interface, not the interface itself.
func hasX ¶
func hasX(s string) bool
func hexDigit ¶
func hexDigit(d rune) (int, bool)
hexDigit returns the value of the hexadecimal digit.
func indexRune ¶
func indexRune(s string, r rune) int
func intFromArg ¶
func intFromArg(a []interface{}, argNum int) (num int, isInt bool, newArgNum int)
intFromArg gets the argNumth element of a. On return, isInt reports whether the argument has integer type.
func isSpace ¶
func isSpace(r rune) bool
func newScanState ¶
func newScanState(r io.Reader, nlIsSpace, nlIsEnd bool) (s *ss, old ssave)
newScanState allocates a new ss struct or grab a cached one.
func notSpace ¶
func notSpace(r rune) bool
notSpace is the default scanning function used in Token.
func parseArgNumber ¶
func parseArgNumber(format string) (index int, wid int, ok bool)
parseArgNumber returns the value of the bracketed number, minus 1 (explicit argument numbers are one-indexed but we want zero-indexed). The opening bracket is known to be present at format[0]. The returned values are the index, the number of bytes to consume up to the closing paren, if present, and whether the number parsed ok. The bytes to consume will be 1 if no closing paren is present.
func parsenum ¶
func parsenum(s string, start, end int) (num int, isnum bool, newi int)
parsenum converts ASCII to integer. num is 0 (and isnum is false) if no number present.
func tooLarge ¶
func tooLarge(x int) bool
tooLarge reports whether the magnitude of the integer is too large to be used as a formatting width or precision.
type Formatter ¶
Formatter is implemented by any value that has a Format method. The implementation controls how State and rune are interpreted, and may call Sprint(f) or Fprint(f) etc. to generate its output.
type Formatter interface { Format(f State, verb rune) }
type GoStringer ¶
GoStringer is implemented by any value that has a GoString method, which defines the Go syntax for that value. The GoString method is used to print values passed as an operand to a %#v format.
type GoStringer interface { GoString() string }
▹ Example
type ScanState ¶
ScanState represents the scanner state passed to custom scanners. Scanners may do rune-at-a-time scanning or ask the ScanState to discover the next space-delimited token.
type ScanState interface { // ReadRune reads the next rune (Unicode code point) from the input. // If invoked during Scanln, Fscanln, or Sscanln, ReadRune() will // return EOF after returning the first '\n' or when reading beyond // the specified width. ReadRune() (r rune, size int, err error) // UnreadRune causes the next call to ReadRune to return the same rune. UnreadRune() error // SkipSpace skips space in the input. Newlines are treated appropriately // for the operation being performed; see the package documentation // for more information. SkipSpace() // Token skips space in the input if skipSpace is true, then returns the // run of Unicode code points c satisfying f(c). If f is nil, // !unicode.IsSpace(c) is used; that is, the token will hold non-space // characters. Newlines are treated appropriately for the operation being // performed; see the package documentation for more information. // The returned slice points to shared data that may be overwritten // by the next call to Token, a call to a Scan function using the ScanState // as input, or when the calling Scan method returns. Token(skipSpace bool, f func(rune) bool) (token []byte, err error) // Width returns the value of the width option and whether it has been set. // The unit is Unicode code points. Width() (wid int, ok bool) // Because ReadRune is implemented by the interface, Read should never be // called by the scanning routines and a valid implementation of // ScanState may choose always to return an error from Read. Read(buf []byte) (n int, err error) }
type Scanner ¶
Scanner is implemented by any value that has a Scan method, which scans the input for the representation of a value and stores the result in the receiver, which must be a pointer to be useful. The Scan method is called for any argument to Scan, Scanf, or Scanln that implements it.
type Scanner interface { Scan(state ScanState, verb rune) error }
type State ¶
State represents the printer state passed to custom formatters. It provides access to the io.Writer interface plus information about the flags and options for the operand's format specifier.
type State interface { // Write is the function to call to emit formatted output to be printed. Write(b []byte) (n int, err error) // Width returns the value of the width option and whether it has been set. Width() (wid int, ok bool) // Precision returns the value of the precision option and whether it has been set. Precision() (prec int, ok bool) // Flag reports whether the flag c, a character, has been set. Flag(c int) bool }
type Stringer ¶
Stringer is implemented by any value that has a String method, which defines the “native” format for that value. The String method is used to print values passed as an operand to any format that accepts a string or to an unformatted printer such as Print.
type Stringer interface { String() string }
▹ Example
type buffer ¶
Use simple []byte instead of bytes.Buffer to avoid large dependency.
type buffer []byte
func (*buffer) write ¶
func (b *buffer) write(p []byte)
func (*buffer) writeByte ¶
func (b *buffer) writeByte(c byte)
func (*buffer) writeRune ¶
func (bp *buffer) writeRune(r rune)
func (*buffer) writeString ¶
func (b *buffer) writeString(s string)
type fmt ¶
A fmt is the raw formatter used by Printf etc. It prints into a buffer that must be set up separately.
type fmt struct { buf *buffer fmtFlags wid int // width prec int // precision // intbuf is large enough to store %b of an int64 with a sign and // avoids padding at the end of the struct on 32 bit architectures. intbuf [68]byte }
func (*fmt) clearflags ¶
func (f *fmt) clearflags()
func (*fmt) fmtBoolean ¶
func (f *fmt) fmtBoolean(v bool)
fmtBoolean formats a boolean.
func (*fmt) fmtBs ¶
func (f *fmt) fmtBs(b []byte)
fmtBs formats the byte slice b as if it was formatted as string with fmtS.
func (*fmt) fmtBx ¶
func (f *fmt) fmtBx(b []byte, digits string)
fmtBx formats a byte slice as a hexadecimal encoding of its bytes.
func (*fmt) fmtC ¶
func (f *fmt) fmtC(c uint64)
fmtC formats an integer as a Unicode character. If the character is not valid Unicode, it will print '\ufffd'.
func (*fmt) fmtFloat ¶
func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int)
fmtFloat formats a float64. It assumes that verb is a valid format specifier for strconv.AppendFloat and therefore fits into a byte.
func (*fmt) fmtInteger ¶
func (f *fmt) fmtInteger(u uint64, base int, isSigned bool, verb rune, digits string)
fmtInteger formats signed and unsigned integers.
func (*fmt) fmtQ ¶
func (f *fmt) fmtQ(s string)
fmtQ formats a string as a double-quoted, escaped Go string constant. If f.sharp is set a raw (backquoted) string may be returned instead if the string does not contain any control characters other than tab.
func (*fmt) fmtQc ¶
func (f *fmt) fmtQc(c uint64)
fmtQc formats an integer as a single-quoted, escaped Go character constant. If the character is not valid Unicode, it will print '\ufffd'.
func (*fmt) fmtS ¶
func (f *fmt) fmtS(s string)
fmtS formats a string.
func (*fmt) fmtSbx ¶
func (f *fmt) fmtSbx(s string, b []byte, digits string)
fmtSbx formats a string or byte slice as a hexadecimal encoding of its bytes.
func (*fmt) fmtSx ¶
func (f *fmt) fmtSx(s, digits string)
fmtSx formats a string as a hexadecimal encoding of its bytes.
func (*fmt) fmtUnicode ¶
func (f *fmt) fmtUnicode(u uint64)
fmtUnicode formats a uint64 as "U+0078" or with f.sharp set as "U+0078 'x'".
func (*fmt) init ¶
func (f *fmt) init(buf *buffer)
func (*fmt) pad ¶
func (f *fmt) pad(b []byte)
pad appends b to f.buf, padded on left (!f.minus) or right (f.minus).
func (*fmt) padString ¶
func (f *fmt) padString(s string)
padString appends s to f.buf, padded on left (!f.minus) or right (f.minus).
func (*fmt) truncate ¶
func (f *fmt) truncate(b []byte) []byte
truncate truncates the byte slice b as a string of the specified precision, if present.
func (*fmt) truncateString ¶
func (f *fmt) truncateString(s string) string
truncate truncates the string s to the specified precision, if present.
func (*fmt) writePadding ¶
func (f *fmt) writePadding(n int)
writePadding generates n bytes of padding.
type fmtFlags ¶
flags placed in a separate struct for easy clearing.
type fmtFlags struct { widPresent bool precPresent bool minus bool plus bool sharp bool space bool zero bool // For the formats %+v %#v, we set the plusV/sharpV flags // and clear the plus/sharp flags since %+v and %#v are in effect // different, flagless formats set at the top level. plusV bool sharpV bool }
type pp ¶
pp is used to store a printer's state and is reused with sync.Pool to avoid allocations.
type pp struct { buf buffer // arg holds the current item, as an interface{}. arg interface{} // value is used instead of arg for reflect values. value reflect.Value // fmt is used to format basic items such as integers or strings. fmt fmt // reordered records whether the format string used argument reordering. reordered bool // goodArgNum records whether the most recent reordering directive was valid. goodArgNum bool // panicking is set by catchPanic to avoid infinite panic, recover, panic, ... recursion. panicking bool // erroring is set when printing an error string to guard against calling handleMethods. erroring bool // wrapErrs is set when the format string may contain a %w verb. wrapErrs bool // wrappedErr records the target of the %w verb. wrappedErr error }
func newPrinter ¶
func newPrinter() *pp
newPrinter allocates a new pp struct or grabs a cached one.
func (*pp) Flag ¶
func (p *pp) Flag(b int) bool
func (*pp) Precision ¶
func (p *pp) Precision() (prec int, ok bool)
func (*pp) Width ¶
func (p *pp) Width() (wid int, ok bool)
func (*pp) Write ¶
func (p *pp) Write(b []byte) (ret int, err error)
Implement Write so we can call Fprintf on a pp (through State), for recursive use in custom verbs.
func (*pp) WriteString ¶
func (p *pp) WriteString(s string) (ret int, err error)
Implement WriteString so that we can call io.WriteString on a pp (through state), for efficiency.
func (*pp) argNumber ¶
func (p *pp) argNumber(argNum int, format string, i int, numArgs int) (newArgNum, newi int, found bool)
argNumber returns the next argument to evaluate, which is either the value of the passed-in argNum or the value of the bracketed integer that begins format[i:]. It also returns the new value of i, that is, the index of the next byte of the format to process.
func (*pp) badArgNum ¶
func (p *pp) badArgNum(verb rune)
func (*pp) badVerb ¶
func (p *pp) badVerb(verb rune)
func (*pp) catchPanic ¶
func (p *pp) catchPanic(arg interface{}, verb rune, method string)
func (*pp) doPrint ¶
func (p *pp) doPrint(a []interface{})
func (*pp) doPrintf ¶
func (p *pp) doPrintf(format string, a []interface{})
func (*pp) doPrintln ¶
func (p *pp) doPrintln(a []interface{})
doPrintln is like doPrint but always adds a space between arguments and a newline after the last argument.
func (*pp) fmt0x64 ¶
func (p *pp) fmt0x64(v uint64, leading0x bool)
fmt0x64 formats a uint64 in hexadecimal and prefixes it with 0x or not, as requested, by temporarily setting the sharp flag.
func (*pp) fmtBool ¶
func (p *pp) fmtBool(v bool, verb rune)
func (*pp) fmtBytes ¶
func (p *pp) fmtBytes(v []byte, verb rune, typeString string)
func (*pp) fmtComplex ¶
func (p *pp) fmtComplex(v complex128, size int, verb rune)
fmtComplex formats a complex number v with r = real(v) and j = imag(v) as (r+ji) using fmtFloat for r and j formatting.
func (*pp) fmtFloat ¶
func (p *pp) fmtFloat(v float64, size int, verb rune)
fmtFloat formats a float. The default precision for each verb is specified as last argument in the call to fmt_float.
func (*pp) fmtInteger ¶
func (p *pp) fmtInteger(v uint64, isSigned bool, verb rune)
fmtInteger formats a signed or unsigned integer.
func (*pp) fmtPointer ¶
func (p *pp) fmtPointer(value reflect.Value, verb rune)
func (*pp) fmtString ¶
func (p *pp) fmtString(v string, verb rune)
func (*pp) free ¶
func (p *pp) free()
free saves used pp structs in ppFree; avoids an allocation per invocation.
func (*pp) handleMethods ¶
func (p *pp) handleMethods(verb rune) (handled bool)
func (*pp) missingArg ¶
func (p *pp) missingArg(verb rune)
func (*pp) printArg ¶
func (p *pp) printArg(arg interface{}, verb rune)
func (*pp) printValue ¶
func (p *pp) printValue(value reflect.Value, verb rune, depth int)
printValue is similar to printArg but starts with a reflect value, not an interface{} value. It does not handle 'p' and 'T' verbs because these should have been already handled by printArg.
func (*pp) unknownType ¶
func (p *pp) unknownType(v reflect.Value)
type readRune ¶
readRune is a structure to enable reading UTF-8 encoded code points from an io.Reader. It is used if the Reader given to the scanner does not already implement io.RuneScanner.
type readRune struct { reader io.Reader buf [utf8.UTFMax]byte // used only inside ReadRune pending int // number of bytes in pendBuf; only >0 for bad UTF-8 pendBuf [utf8.UTFMax]byte // bytes left over peekRune rune // if >=0 next rune; when <0 is ^(previous Rune) }
func (*readRune) ReadRune ¶
func (r *readRune) ReadRune() (rr rune, size int, err error)
ReadRune returns the next UTF-8 encoded code point from the io.Reader inside r.
func (*readRune) UnreadRune ¶
func (r *readRune) UnreadRune() error
func (*readRune) readByte ¶
func (r *readRune) readByte() (b byte, err error)
readByte returns the next byte from the input, which may be left over from a previous read if the UTF-8 was ill-formed.
type scanError ¶
scanError represents an error generated by the scanning software. It's used as a unique signature to identify such errors when recovering.
type scanError struct { err error }
type ss ¶
ss is the internal implementation of ScanState.
type ss struct { rs io.RuneScanner // where to read input buf buffer // token accumulator count int // runes consumed so far. atEOF bool // already read EOF ssave }
func (*ss) Read ¶
func (s *ss) Read(buf []byte) (n int, err error)
The Read method is only in ScanState so that ScanState satisfies io.Reader. It will never be called when used as intended, so there is no need to make it actually work.
func (*ss) ReadRune ¶
func (s *ss) ReadRune() (r rune, size int, err error)
func (*ss) SkipSpace ¶
func (s *ss) SkipSpace()
SkipSpace provides Scan methods the ability to skip space and newline characters in keeping with the current scanning mode set by format strings and Scan/Scanln.
func (*ss) Token ¶
func (s *ss) Token(skipSpace bool, f func(rune) bool) (tok []byte, err error)
func (*ss) UnreadRune ¶
func (s *ss) UnreadRune() error
func (*ss) Width ¶
func (s *ss) Width() (wid int, ok bool)
func (*ss) accept ¶
func (s *ss) accept(ok string) bool
accept checks the next rune in the input. If it's a byte (sic) in the string, it puts it in the buffer and returns true. Otherwise it return false.
func (*ss) advance ¶
func (s *ss) advance(format string) (i int)
advance determines whether the next characters in the input match those of the format. It returns the number of bytes (sic) consumed in the format. All runs of space characters in either input or format behave as a single space. Newlines are special, though: newlines in the format must match those in the input and vice versa. This routine also handles the %% case. If the return value is zero, either format starts with a % (with no following %) or the input is empty. If it is negative, the input did not match the string.
func (*ss) complexTokens ¶
func (s *ss) complexTokens() (real, imag string)
complexTokens returns the real and imaginary parts of the complex number starting here. The number might be parenthesized and has the format (N+Ni) where N is a floating-point number and there are no spaces within.
func (*ss) consume ¶
func (s *ss) consume(ok string, accept bool) bool
consume reads the next rune in the input and reports whether it is in the ok string. If accept is true, it puts the character into the input token.
func (*ss) convertFloat ¶
func (s *ss) convertFloat(str string, n int) float64
convertFloat converts the string to a float64value.
func (*ss) convertString ¶
func (s *ss) convertString(verb rune) (str string)
convertString returns the string represented by the next input characters. The format of the input is determined by the verb.
func (*ss) doScan ¶
func (s *ss) doScan(a []interface{}) (numProcessed int, err error)
doScan does the real work for scanning without a format string.
func (*ss) doScanf ¶
func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err error)
doScanf does the real work when scanning with a format string. At the moment, it handles only pointers to basic types.
func (*ss) error ¶
func (s *ss) error(err error)
func (*ss) errorString ¶
func (s *ss) errorString(err string)
func (*ss) floatToken ¶
func (s *ss) floatToken() string
floatToken returns the floating-point number starting here, no longer than swid if the width is specified. It's not rigorous about syntax because it doesn't check that we have at least some digits, but Atof will do that.
func (*ss) free ¶
func (s *ss) free(old ssave)
free saves used ss structs in ssFree; avoid an allocation per invocation.
func (*ss) getBase ¶
func (s *ss) getBase(verb rune) (base int, digits string)
getBase returns the numeric base represented by the verb and its digit string.
func (*ss) getRune ¶
func (s *ss) getRune() (r rune)
The public method returns an error; this private one panics. If getRune reaches EOF, the return value is EOF (-1).
func (*ss) hexByte ¶
func (s *ss) hexByte() (b byte, ok bool)
hexByte returns the next hex-encoded (two-character) byte from the input. It returns ok==false if the next bytes in the input do not encode a hex byte. If the first byte is hex and the second is not, processing stops.
func (*ss) hexString ¶
func (s *ss) hexString() string
hexString returns the space-delimited hexpair-encoded string.
func (*ss) mustReadRune ¶
func (s *ss) mustReadRune() (r rune)
mustReadRune turns io.EOF into a panic(io.ErrUnexpectedEOF). It is called in cases such as string scanning where an EOF is a syntax error.
func (*ss) notEOF ¶
func (s *ss) notEOF()
func (*ss) okVerb ¶
func (s *ss) okVerb(verb rune, okVerbs, typ string) bool
okVerb verifies that the verb is present in the list, setting s.err appropriately if not.
func (*ss) peek ¶
func (s *ss) peek(ok string) bool
peek reports whether the next character is in the ok string, without consuming it.
func (*ss) quotedString ¶
func (s *ss) quotedString() string
quotedString returns the double- or back-quoted string represented by the next input characters.
func (*ss) scanBasePrefix ¶
func (s *ss) scanBasePrefix() (base int, digits string, zeroFound bool)
scanBasePrefix reports whether the integer begins with a base prefix and returns the base, digit string, and whether a zero was found. It is called only if the verb is %v.
func (*ss) scanBool ¶
func (s *ss) scanBool(verb rune) bool
scanBool returns the value of the boolean represented by the next token.
func (*ss) scanComplex ¶
func (s *ss) scanComplex(verb rune, n int) complex128
convertComplex converts the next token to a complex128 value. The atof argument is a type-specific reader for the underlying type. If we're reading complex64, atof will parse float32s and convert them to float64's to avoid reproducing this code for each complex type.
func (*ss) scanInt ¶
func (s *ss) scanInt(verb rune, bitSize int) int64
scanInt returns the value of the integer represented by the next token, checking for overflow. Any error is stored in s.err.
func (*ss) scanNumber ¶
func (s *ss) scanNumber(digits string, haveDigits bool) string
scanNumber returns the numerical string with specified digits starting here.
func (*ss) scanOne ¶
func (s *ss) scanOne(verb rune, arg interface{})
scanOne scans a single value, deriving the scanner from the type of the argument.
func (*ss) scanPercent ¶
func (s *ss) scanPercent()
scanPercent scans a literal percent character.
func (*ss) scanRune ¶
func (s *ss) scanRune(bitSize int) int64
scanRune returns the next rune value in the input.
func (*ss) scanUint ¶
func (s *ss) scanUint(verb rune, bitSize int) uint64
scanUint returns the value of the unsigned integer represented by the next token, checking for overflow. Any error is stored in s.err.
func (*ss) token ¶
func (s *ss) token(skipSpace bool, f func(rune) bool) []byte
token returns the next space-delimited string from the input. It skips white space. For Scanln, it stops at newlines. For Scan, newlines are treated as spaces.
type ssave ¶
ssave holds the parts of ss that need to be saved and restored on recursive scans.
type ssave struct { validSave bool // is or was a part of an actual ss. nlIsEnd bool // whether newline terminates scan nlIsSpace bool // whether newline counts as white space argLimit int // max value of ss.count for this arg; argLimit <= limit limit int // max value of ss.count. maxWid int // width of this arg. }
type stringReader ¶
type stringReader string
func (*stringReader) Read ¶
func (r *stringReader) Read(b []byte) (n int, err error)
type wrapError ¶
type wrapError struct { msg string err error }
func (*wrapError) Error ¶
func (e *wrapError) Error() string
func (*wrapError) Unwrap ¶
func (e *wrapError) Unwrap() error