diff options
Diffstat (limited to 'libgo/go/fmt/doc.go')
-rw-r--r-- | libgo/go/fmt/doc.go | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/libgo/go/fmt/doc.go b/libgo/go/fmt/doc.go index c312914..a2faecb 100644 --- a/libgo/go/fmt/doc.go +++ b/libgo/go/fmt/doc.go @@ -48,13 +48,10 @@ Pointer: %p base 16 notation, with leading 0x - There is no 'u' flag. Integers are printed unsigned if they have unsigned type. - Similarly, there is no need to specify the size of the operand (int8, int64). - The default format for %v is: bool: %t int, int8 etc.: %d - uint, uint8 etc.: %d, %x if printed with %#v + uint, uint8 etc.: %d, %#x if printed with %#v float32, complex64, etc: %g string: %s chan: %p @@ -177,6 +174,9 @@ that type has a String method. Such pathologies are rare, however, and the package does not protect against them. + When printing a struct, fmt cannot and therefore does not invoke + formatting methods such as Error or String on unexported fields. + Explicit argument indexes: In Printf, Sprintf, and Fprintf, the default behavior is for each @@ -247,31 +247,42 @@ Scanln, Fscanln and Sscanln stop scanning at a newline and require that the items be followed by a newline or EOF. - Scanf, Fscanf and Sscanf require that (after skipping spaces) - newlines in the format are matched by newlines in the input - and vice versa. This behavior differs from the corresponding - routines in C, which uniformly treat newlines as spaces. - - When scanning with Scanf, Fscanf, and Sscanf, all non-empty - runs of space characters (except newline) are equivalent - to a single space in both the format and the input. With - that proviso, text in the format string must match the input - text; scanning stops if it does not, with the return value - of the function indicating the number of arguments scanned. - Scanf, Fscanf, and Sscanf parse the arguments according to a - format string, analogous to that of Printf. For example, %x - will scan an integer as a hexadecimal number, and %v will scan - the default representation format for the value. - - The formats behave analogously to those of Printf with the - following exceptions: - - %p is not implemented - %T is not implemented - %e %E %f %F %g %G are all equivalent and scan any floating point or complex value - %s and %v on strings scan a space-delimited token - Flags # and + are not implemented. + format string, analogous to that of Printf. In the text that + follows, 'space' means any Unicode whitespace character + except newline. + + In the format string, a verb introduced by the % character + consumes and parses input; these verbs are described in more + detail below. A character other than %, space, or newline in + the format consumes exactly that input character, which must + be present. A newline with zero or more spaces before it in + the format string consumes zero or more spaces in the input + followed by a single newline or the end of the input. A space + following a newline in the format string consumes zero or more + spaces in the input. Otherwise, any run of one or more spaces + in the format string consumes as many spaces as possible in + the input. Unless the run of spaces in the format string + appears adjacent to a newline, the run must consume at least + one space from the input or find the end of the input. + + The handling of spaces and newlines differs from that of C's + scanf family: in C, newlines are treated as any other space, + and it is never an error when a run of spaces in the format + string finds no spaces to consume in the input. + + The verbs behave analogously to those of Printf. + For example, %x will scan an integer as a hexadecimal number, + and %v will scan the default representation format for the value. + The Printf verbs %p and %T and the flags # and + are not implemented, + and the verbs %e %E %f %F %g and %G are all equivalent and scan any + floating-point or complex value. + + Input processed by verbs is implicitly space-delimited: the + implementation of every verb except %c starts by discarding + leading spaces from the remaining input, and the %s verb + (and %v reading into a string) stops consuming input at the first + space or newline character. The familiar base-setting prefixes 0 (octal) and 0x (hexadecimal) are accepted when scanning integers without @@ -300,6 +311,9 @@ All arguments to be scanned must be either pointers to basic types or implementations of the Scanner interface. + Like Scanf and Fscanf, Sscanf need not consume its entire input. + There is no way to recover how much of the input string Sscanf used. + Note: Fscan etc. can read one character (rune) past the input they return, which means that a loop calling a scan routine may skip some of the input. This is usually a problem only |