[TestEndToEnd] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestEndToEnd] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 [1] // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 9ebf966b2645 1 slip 1. Line 3. for Friday read Thursday The text above is as printed. (exit 0) [TestEndToEnd] tmux capture-pane -p $ /tmp/tipin-bin3949945277/tipin show notes.md | head -n 6; echo DONE 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 [1] // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous DONE $ [TestStates] $ tipin notes.md 11 "for nothing read a blank line" Slip 1 tipped in at line 11 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestStates] $ tipin notes.md 6 "for Package fmt read package fmt" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestStates] $ tipin show notes.md 1 Tipped in, first. 2 Tipped in, second. 3 Tipped in, third. 4 // Copyright 2009 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 /* 9 [2] Package fmt implements formatted I/O with functions analogous 10 to C's printf and scanf. The format 'verbs' are derived from C's but 11 are simpler. 12 13 # Printing 14 [1] 15 The verbs: 16 17 General: 18 19 %v the value in a default format 20 when printing structs, the plus flag (%+v) adds field names 21 %#v a Go-syntax representation of the value 22 %T a Go-syntax representation of the type of the value 23 %% a literal percent sign; consumes no value 24 25 Boolean: 26 27 %t the word true or false 28 29 Integer: 30 31 %b base 2 32 %c the character represented by the corresponding Unicode code point 33 %d base 10 34 %o base 8 35 %O base 8 with 0o prefix 36 %q a single-quoted character literal safely escaped with Go syntax. 37 %x base 16, with lower-case letters for a-f 38 %X base 16, with upper-case letters for A-F 39 %U Unicode format: U+1234; same as "U+%04X" 40 41 Floating-point and complex constituents: 42 43 %b decimalless scientific notation with exponent a power of two, 44 in the manner of strconv.FormatFloat with the 'b' format, 45 e.g. -123456p-78 46 %e scientific notation, e.g. -1.234456e+78 47 %E scientific notation, e.g. -1.234456E+78 48 %f decimal point but no exponent, e.g. 123.456 49 %F synonym for %f 50 %g %e for large exponents, %f otherwise. Precision is discussed below. 51 %G %E for large exponents, %F otherwise 52 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 53 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 54 55 String and slice of bytes (treated equivalently with these verbs): 56 57 %s the uninterpreted bytes of the string or slice 58 %q a double-quoted string safely escaped with Go syntax 59 %x base 16, lower-case, two characters per byte 60 %X base 16, upper-case, two characters per byte 61 62 Slice: 63 64 %p address of 0th element in base 16 notation, with leading 0x 65 66 Pointer: 67 68 %p base 16 notation, with leading 0x 69 The %b, %d, %o, %x and %X verbs also work with pointers, 70 formatting the value exactly as if it were an integer. 71 72 The default format for %v is: 73 74 bool: %t 75 int, int8 etc.: %d 76 uint, uint8 etc.: %d, %#x if printed with %#v 77 float32, complex64, etc: %g 78 string: %s 79 chan: %p 80 pointer: %p 81 82 For compound objects, the elements are printed using these rules, recursively, 83 laid out like this: 84 85 struct: {field0 field1 ...} 86 array, slice: [elem0 elem1 ...] 87 maps: map[key1:value1 key2:value2 ...] 88 pointer to above: &{}, &[], &map[] 89 90 Width is specified by an optional decimal number immediately preceding the verb. 91 If absent, the width is whatever is necessary to represent the value. 92 Precision is specified after the (optional) width by a period followed by a 93 decimal number. If no period is present, a default precision is used. 94 A period with no following number specifies a precision of zero. 95 Examples: 96 97 %f default width, default precision 98 %9f width 9, default precision 99 %.2f default width, precision 2 100 %9.2f width 9, precision 2 101 %9.f width 9, precision 0 102 103 Width and precision are measured in units of Unicode code points, 104 that is, runes. (This differs from C's printf where the 105 units are always measured in bytes.) Either or both of the flags 106 may be replaced with the character '*', causing their values to be 107 obtained from the next operand (preceding the one to format), 108 which must be of type int. 109 110 For most values, width is the minimum number of runes to output, 111 padding the formatted form with spaces if necessary. 112 113 For strings, byte slices and byte arrays, however, precision 114 limits the length of the input to be formatted (not the size of 115 the output), truncating if necessary. Normally it is measured in 116 runes, but for these types when formatted with the %x or %X format 117 it is measured in bytes. 118 119 For floating-point values, width sets the minimum width of the field and 120 precision sets the number of places after the decimal, if appropriate, 121 except that for %g/%G precision sets the maximum number of significant 122 digits (trailing zeros are removed). For example, given 12.345 the format 123 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 124 and %#g is 6; for %g it is the smallest number of digits necessary to identify 125 the value uniquely. 126 127 For complex numbers, the width and precision apply to the two 128 components independently and the result is parenthesized, so %f applied 129 to 1.2+3.4i produces (1.200000+3.400000i). 130 131 When formatting a single integer code point or a rune string (type []rune) 132 with %q, invalid Unicode code points are changed to the Unicode replacement 133 character, U+FFFD, as in strconv.QuoteRune. 134 135 Other flags: 136 137 '+' always print a sign for numeric values; 138 guarantee ASCII-only output for %q (%+q) 139 '-' pad with spaces on the right rather than the left (left-justify the field) 140 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 141 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 142 for %q, print a raw (backquoted) string if strconv.CanBackquote 143 returns true; 144 always print a decimal point for %e, %E, %f, %F, %g and %G; 145 do not remove trailing zeros for %g and %G; 146 write e.g. U+0078 'x' if the character is printable for %U (%#U). 147 ' ' (space) leave a space for elided sign in numbers (% d); 148 put spaces between bytes printing strings or slices in hex (% x, % X) 149 '0' pad with leading zeros rather than spaces; 150 for numbers, this moves the padding after the sign; 151 ignored for strings, byte slices and byte arrays 152 153 Flags are ignored by verbs that do not expect them. 154 For example there is no alternate decimal format, so %#d and %d 155 behave identically. 156 157 For each Printf-like function, there is also a Print function 158 that takes no format and is equivalent to saying %v for every 159 operand. Another variant Println inserts blanks between 160 operands and appends a newline. 161 162 Regardless of the verb, if an operand is an interface value, 163 the internal concrete value is used, not the interface itself. 164 Thus: 165 166 var i interface{} = 23 167 fmt.Printf("%v\n", i) 168 169 will print 23. 170 171 Except when printed using the verbs %T and %p, special 172 formatting considerations apply for operands that implement 173 certain interfaces. In order of application: 174 175 1. If the operand is a reflect.Value, the operand is replaced by the 176 concrete value that it holds, and printing continues with the next rule. 177 178 2. If an operand implements the Formatter interface, it will 179 be invoked. In this case the interpretation of verbs and flags is 180 controlled by that implementation. 181 182 3. If the %v verb is used with the # flag (%#v) and the operand 183 implements the GoStringer interface, that will be invoked. 184 185 If the format (which is implicitly %v for Println etc.) is valid 186 for a string (%s %q %x %X), or is %v but not %#v, 187 the following two rules apply: 188 189 4. If an operand implements the error interface, the Error method 190 will be invoked to convert the object to a string, which will then 191 be formatted as required by the verb (if any). 192 193 5. If an operand implements method String() string, that method 194 will be invoked to convert the object to a string, which will then 195 be formatted as required by the verb (if any). 196 197 For compound operands such as slices and structs, the format 198 applies to the elements of each operand, recursively, not to the 199 operand as a whole. Thus %q will quote each element of a slice 200 of strings, and %6.2f will control formatting for each element 201 of a floating-point array. 202 203 However, when printing a byte slice with a string-like verb 204 (%s %q %x %X), it is treated identically to a string, as a single item. 205 206 To avoid recursion in cases such as 207 208 type X string 209 func (x X) String() string { return Sprintf("<%s>", x) } 210 211 convert the value before recurring: 212 213 func (x X) String() string { return Sprintf("<%s>", string(x)) } 214 215 Infinite recursion can also be triggered by self-referential data 216 structures, such as a slice that contains itself as an element, if 217 that type has a String method. Such pathologies are rare, however, 218 and the package does not protect against them. 219 220 When printing a struct, fmt cannot and therefore does not invoke 221 formatting methods such as Error or String on unexported fields. 222 223 # Explicit argument indexes 224 225 In Printf, Sprintf, and Fprintf, the default behavior is for each 226 formatting verb to format successive arguments passed in the call. 227 However, the notation [n] immediately before the verb indicates that the 228 nth one-indexed argument is to be formatted instead. The same notation 229 before a '*' for a width or precision selects the argument index holding 230 the value. After processing a bracketed expression [n], subsequent verbs 231 will use arguments n+1, n+2, etc. unless otherwise directed. 232 233 For example, 234 235 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 236 237 will yield "22 11", while 238 239 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 240 241 equivalent to 242 243 fmt.Sprintf("%6.2f", 12.0) 244 245 will yield " 12.00". Because an explicit index affects subsequent verbs, 246 this notation can be used to print the same values multiple times 247 by resetting the index for the first argument to be repeated: 248 249 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 250 251 will yield "16 17 0x10 0x11". 252 253 # Format errors 254 255 If an invalid argument is given for a verb, such as providing 256 a string to %d, the generated string will contain a 257 description of the problem, as in these examples: 258 259 Wrong type or unknown verb: %!verb(type=value) 260 Printf("%d", "hi"): %!d(string=hi) 261 Too many arguments: %!(EXTRA type=value) 262 Printf("hi", "guys"): hi%!(EXTRA string=guys) 263 Too few arguments: %!verb(MISSING) 264 Printf("hi%d"): hi%!d(MISSING) 265 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 266 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 267 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 268 Invalid or invalid use of argument index: %!(BADINDEX) 269 Printf("%*[2]d", 7): %!d(BADINDEX) 270 Printf("%.[2]d", 7): %!d(BADINDEX) 271 272 All errors begin with the string "%!" followed sometimes 273 by a single character (the verb) and end with a parenthesized 274 description. 275 276 If an Error or String method triggers a panic when called by a 277 print routine, the fmt package reformats the error message 278 from the panic, decorating it with an indication that it came 279 through the fmt package. For example, if a String method 280 calls panic("bad"), the resulting formatted message will look 281 like 282 283 %!s(PANIC=bad) 284 285 The %!s just shows the print verb in use when the failure 286 occurred. If the panic is caused by a nil receiver to an Error 287 or String method, however, the output is the undecorated 288 string, "". 289 290 # Scanning 291 292 An analogous set of functions scans formatted text to yield 293 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 294 Fscanf and Fscanln read from a specified io.Reader; Sscan, 295 Sscanf and Sscanln read from an argument string. 296 297 Scan, Fscan, Sscan treat newlines in the input as spaces. 298 299 Scanln, Fscanln and Sscanln stop scanning at a newline and 300 require that the items be followed by a newline or EOF. 301 302 Scanf, Fscanf, and Sscanf parse the arguments according to a 303 format string, analogous to that of Printf. In the text that 304 follows, 'space' means any Unicode whitespace character 305 except newline. 306 307 In the format string, a verb introduced by the % character 308 consumes and parses input; these verbs are described in more 309 detail below. A character other than %, space, or newline in 310 the format consumes exactly that input character, which must 311 be present. A newline with zero or more spaces before it in 312 the format string consumes zero or more spaces in the input 313 followed by a single newline or the end of the input. A space 314 following a newline in the format string consumes zero or more 315 spaces in the input. Otherwise, any run of one or more spaces 316 in the format string consumes as many spaces as possible in 317 the input. Unless the run of spaces in the format string 318 appears adjacent to a newline, the run must consume at least 319 one space from the input or find the end of the input. 320 321 The handling of spaces and newlines differs from that of C's 322 scanf family: in C, newlines are treated as any other space, 323 and it is never an error when a run of spaces in the format 324 string finds no spaces to consume in the input. 325 326 The verbs behave analogously to those of Printf. 327 For example, %x will scan an integer as a hexadecimal number, 328 and %v will scan the default representation format for the value. 329 The Printf verbs %p and %T and the flags # and + are not implemented. 330 For floating-point and complex values, all valid formatting verbs 331 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 332 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 333 and digit-separating underscores (for example: "3.14159_26535_89793"). 334 335 Input processed by verbs is implicitly space-delimited: the 336 implementation of every verb except %c starts by discarding 337 leading spaces from the remaining input, and the %s verb 338 (and %v reading into a string) stops consuming input at the first 339 space or newline character. 340 341 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 342 and 0x (hexadecimal) are accepted when scanning integers 343 without a format or with the %v verb, as are digit-separating 344 underscores. 345 346 Width is interpreted in the input text but there is no 347 syntax for scanning with a precision (no %5.2f, just %5f). 348 If width is provided, it applies after leading spaces are 349 trimmed and specifies the maximum number of runes to read 350 to satisfy the verb. For example, 351 352 Sscanf(" 1234567 ", "%5s%d", &s, &i) 353 354 will set s to "12345" and i to 67 while 355 356 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 357 358 will set s to "12" and i to 34. 359 360 In all the scanning functions, a carriage return followed 361 immediately by a newline is treated as a plain newline 362 (\r\n means the same as \n). 363 364 In all the scanning functions, if an operand implements method 365 Scan (that is, it implements the Scanner interface) that 366 method will be used to scan the text for that operand. Also, 367 if the number of arguments scanned is less than the number of 368 arguments provided, an error is returned. 369 370 All arguments to be scanned must be either pointers to basic 371 types or implementations of the Scanner interface. 372 373 Like Scanf and Fscanf, Sscanf need not consume its entire input. 374 There is no way to recover how much of the input string Sscanf used. 375 376 Note: Fscan etc. can read one character (rune) past the input 377 they return, which means that a loop calling a scan routine 378 may skip some of the input. This is usually a problem only 379 when there is no space between input values. If the reader 380 provided to Fscan implements ReadRune, that method will be used 381 to read characters. If the reader also implements UnreadRune, 382 that method will be used to save the character and successive 383 calls will not lose data. To attach ReadRune and UnreadRune 384 methods to a reader without that capability, use 385 bufio.NewReader. 386 */ 387 package fmt ________________ ERRATA notes.md ed. b3b9dd22ddf3 2 slips 1. Line 14, written at 11. for nothing read a blank line Edition differs; line still fits. 2. Line 9, written at 6. for Package fmt read package fmt Edition differs; line still fits. The text above is as printed. (exit 0) [TestStates] $ tipin notes.md 11 "for nothing read a blank line" Slip 1 tipped in at line 11 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestStates] $ tipin notes.md 6 "for Package fmt read package fmt" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestStates] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 [2] Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 A new line above. 11 12 A new line below. 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 0be437805fae 2 slips 1. No longer fits. Was line 11: "". The slip said: for nothing read a blank line 2. Line 6. for Package fmt read package fmt Edition differs; line still fits. The text above is as printed. (exit 0) [TestStates] $ tipin notes.md 11 "for nothing read a blank line" Slip 1 tipped in at line 11 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestStates] $ tipin notes.md 6 "for Package fmt read package fmt" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestStates] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O, edited. 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 [1] 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. f91a55ab882b 2 slips 1. Line 11. for nothing read a blank line Edition differs; line still fits. 2. No longer fits. Was line 6: "Package fmt implements formatted I/O with functions analogou...". The slip said: for Package fmt read package fmt The text above is as printed. (exit 0) [TestStates] $ tipin notes.md 11 "for nothing read a blank line" Slip 1 tipped in at line 11 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestStates] $ tipin notes.md 6 "for Package fmt read package fmt" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestStates] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 to C's printf and scanf. The format 'verbs' are derived from C's but 7 are simpler. 8 9 # Printing 10 [1] 11 The verbs: 12 13 General: 14 15 %v the value in a default format 16 when printing structs, the plus flag (%+v) adds field names 17 %#v a Go-syntax representation of the value 18 %T a Go-syntax representation of the type of the value 19 %% a literal percent sign; consumes no value 20 21 Boolean: 22 23 %t the word true or false 24 25 Integer: 26 27 %b base 2 28 %c the character represented by the corresponding Unicode code point 29 %d base 10 30 %o base 8 31 %O base 8 with 0o prefix 32 %q a single-quoted character literal safely escaped with Go syntax. 33 %x base 16, with lower-case letters for a-f 34 %X base 16, with upper-case letters for A-F 35 %U Unicode format: U+1234; same as "U+%04X" 36 37 Floating-point and complex constituents: 38 39 %b decimalless scientific notation with exponent a power of two, 40 in the manner of strconv.FormatFloat with the 'b' format, 41 e.g. -123456p-78 42 %e scientific notation, e.g. -1.234456e+78 43 %E scientific notation, e.g. -1.234456E+78 44 %f decimal point but no exponent, e.g. 123.456 45 %F synonym for %f 46 %g %e for large exponents, %f otherwise. Precision is discussed below. 47 %G %E for large exponents, %F otherwise 48 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 49 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 50 51 String and slice of bytes (treated equivalently with these verbs): 52 53 %s the uninterpreted bytes of the string or slice 54 %q a double-quoted string safely escaped with Go syntax 55 %x base 16, lower-case, two characters per byte 56 %X base 16, upper-case, two characters per byte 57 58 Slice: 59 60 %p address of 0th element in base 16 notation, with leading 0x 61 62 Pointer: 63 64 %p base 16 notation, with leading 0x 65 The %b, %d, %o, %x and %X verbs also work with pointers, 66 formatting the value exactly as if it were an integer. 67 68 The default format for %v is: 69 70 bool: %t 71 int, int8 etc.: %d 72 uint, uint8 etc.: %d, %#x if printed with %#v 73 float32, complex64, etc: %g 74 string: %s 75 chan: %p 76 pointer: %p 77 78 For compound objects, the elements are printed using these rules, recursively, 79 laid out like this: 80 81 struct: {field0 field1 ...} 82 array, slice: [elem0 elem1 ...] 83 maps: map[key1:value1 key2:value2 ...] 84 pointer to above: &{}, &[], &map[] 85 86 Width is specified by an optional decimal number immediately preceding the verb. 87 If absent, the width is whatever is necessary to represent the value. 88 Precision is specified after the (optional) width by a period followed by a 89 decimal number. If no period is present, a default precision is used. 90 A period with no following number specifies a precision of zero. 91 Examples: 92 93 %f default width, default precision 94 %9f width 9, default precision 95 %.2f default width, precision 2 96 %9.2f width 9, precision 2 97 %9.f width 9, precision 0 98 99 Width and precision are measured in units of Unicode code points, 100 that is, runes. (This differs from C's printf where the 101 units are always measured in bytes.) Either or both of the flags 102 may be replaced with the character '*', causing their values to be 103 obtained from the next operand (preceding the one to format), 104 which must be of type int. 105 106 For most values, width is the minimum number of runes to output, 107 padding the formatted form with spaces if necessary. 108 109 For strings, byte slices and byte arrays, however, precision 110 limits the length of the input to be formatted (not the size of 111 the output), truncating if necessary. Normally it is measured in 112 runes, but for these types when formatted with the %x or %X format 113 it is measured in bytes. 114 115 For floating-point values, width sets the minimum width of the field and 116 precision sets the number of places after the decimal, if appropriate, 117 except that for %g/%G precision sets the maximum number of significant 118 digits (trailing zeros are removed). For example, given 12.345 the format 119 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 120 and %#g is 6; for %g it is the smallest number of digits necessary to identify 121 the value uniquely. 122 123 For complex numbers, the width and precision apply to the two 124 components independently and the result is parenthesized, so %f applied 125 to 1.2+3.4i produces (1.200000+3.400000i). 126 127 When formatting a single integer code point or a rune string (type []rune) 128 with %q, invalid Unicode code points are changed to the Unicode replacement 129 character, U+FFFD, as in strconv.QuoteRune. 130 131 Other flags: 132 133 '+' always print a sign for numeric values; 134 guarantee ASCII-only output for %q (%+q) 135 '-' pad with spaces on the right rather than the left (left-justify the field) 136 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 137 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 138 for %q, print a raw (backquoted) string if strconv.CanBackquote 139 returns true; 140 always print a decimal point for %e, %E, %f, %F, %g and %G; 141 do not remove trailing zeros for %g and %G; 142 write e.g. U+0078 'x' if the character is printable for %U (%#U). 143 ' ' (space) leave a space for elided sign in numbers (% d); 144 put spaces between bytes printing strings or slices in hex (% x, % X) 145 '0' pad with leading zeros rather than spaces; 146 for numbers, this moves the padding after the sign; 147 ignored for strings, byte slices and byte arrays 148 149 Flags are ignored by verbs that do not expect them. 150 For example there is no alternate decimal format, so %#d and %d 151 behave identically. 152 153 For each Printf-like function, there is also a Print function 154 that takes no format and is equivalent to saying %v for every 155 operand. Another variant Println inserts blanks between 156 operands and appends a newline. 157 158 Regardless of the verb, if an operand is an interface value, 159 the internal concrete value is used, not the interface itself. 160 Thus: 161 162 var i interface{} = 23 163 fmt.Printf("%v\n", i) 164 165 will print 23. 166 167 Except when printed using the verbs %T and %p, special 168 formatting considerations apply for operands that implement 169 certain interfaces. In order of application: 170 171 1. If the operand is a reflect.Value, the operand is replaced by the 172 concrete value that it holds, and printing continues with the next rule. 173 174 2. If an operand implements the Formatter interface, it will 175 be invoked. In this case the interpretation of verbs and flags is 176 controlled by that implementation. 177 178 3. If the %v verb is used with the # flag (%#v) and the operand 179 implements the GoStringer interface, that will be invoked. 180 181 If the format (which is implicitly %v for Println etc.) is valid 182 for a string (%s %q %x %X), or is %v but not %#v, 183 the following two rules apply: 184 185 4. If an operand implements the error interface, the Error method 186 will be invoked to convert the object to a string, which will then 187 be formatted as required by the verb (if any). 188 189 5. If an operand implements method String() string, that method 190 will be invoked to convert the object to a string, which will then 191 be formatted as required by the verb (if any). 192 193 For compound operands such as slices and structs, the format 194 applies to the elements of each operand, recursively, not to the 195 operand as a whole. Thus %q will quote each element of a slice 196 of strings, and %6.2f will control formatting for each element 197 of a floating-point array. 198 199 However, when printing a byte slice with a string-like verb 200 (%s %q %x %X), it is treated identically to a string, as a single item. 201 202 To avoid recursion in cases such as 203 204 type X string 205 func (x X) String() string { return Sprintf("<%s>", x) } 206 207 convert the value before recurring: 208 209 func (x X) String() string { return Sprintf("<%s>", string(x)) } 210 211 Infinite recursion can also be triggered by self-referential data 212 structures, such as a slice that contains itself as an element, if 213 that type has a String method. Such pathologies are rare, however, 214 and the package does not protect against them. 215 216 When printing a struct, fmt cannot and therefore does not invoke 217 formatting methods such as Error or String on unexported fields. 218 219 # Explicit argument indexes 220 221 In Printf, Sprintf, and Fprintf, the default behavior is for each 222 formatting verb to format successive arguments passed in the call. 223 However, the notation [n] immediately before the verb indicates that the 224 nth one-indexed argument is to be formatted instead. The same notation 225 before a '*' for a width or precision selects the argument index holding 226 the value. After processing a bracketed expression [n], subsequent verbs 227 will use arguments n+1, n+2, etc. unless otherwise directed. 228 229 For example, 230 231 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 232 233 will yield "22 11", while 234 235 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 236 237 equivalent to 238 239 fmt.Sprintf("%6.2f", 12.0) 240 241 will yield " 12.00". Because an explicit index affects subsequent verbs, 242 this notation can be used to print the same values multiple times 243 by resetting the index for the first argument to be repeated: 244 245 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 246 247 will yield "16 17 0x10 0x11". 248 249 # Format errors 250 251 If an invalid argument is given for a verb, such as providing 252 a string to %d, the generated string will contain a 253 description of the problem, as in these examples: 254 255 Wrong type or unknown verb: %!verb(type=value) 256 Printf("%d", "hi"): %!d(string=hi) 257 Too many arguments: %!(EXTRA type=value) 258 Printf("hi", "guys"): hi%!(EXTRA string=guys) 259 Too few arguments: %!verb(MISSING) 260 Printf("hi%d"): hi%!d(MISSING) 261 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 262 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 263 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 264 Invalid or invalid use of argument index: %!(BADINDEX) 265 Printf("%*[2]d", 7): %!d(BADINDEX) 266 Printf("%.[2]d", 7): %!d(BADINDEX) 267 268 All errors begin with the string "%!" followed sometimes 269 by a single character (the verb) and end with a parenthesized 270 description. 271 272 If an Error or String method triggers a panic when called by a 273 print routine, the fmt package reformats the error message 274 from the panic, decorating it with an indication that it came 275 through the fmt package. For example, if a String method 276 calls panic("bad"), the resulting formatted message will look 277 like 278 279 %!s(PANIC=bad) 280 281 The %!s just shows the print verb in use when the failure 282 occurred. If the panic is caused by a nil receiver to an Error 283 or String method, however, the output is the undecorated 284 string, "". 285 286 # Scanning 287 288 An analogous set of functions scans formatted text to yield 289 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 290 Fscanf and Fscanln read from a specified io.Reader; Sscan, 291 Sscanf and Sscanln read from an argument string. 292 293 Scan, Fscan, Sscan treat newlines in the input as spaces. 294 295 Scanln, Fscanln and Sscanln stop scanning at a newline and 296 require that the items be followed by a newline or EOF. 297 298 Scanf, Fscanf, and Sscanf parse the arguments according to a 299 format string, analogous to that of Printf. In the text that 300 follows, 'space' means any Unicode whitespace character 301 except newline. 302 303 In the format string, a verb introduced by the % character 304 consumes and parses input; these verbs are described in more 305 detail below. A character other than %, space, or newline in 306 the format consumes exactly that input character, which must 307 be present. A newline with zero or more spaces before it in 308 the format string consumes zero or more spaces in the input 309 followed by a single newline or the end of the input. A space 310 following a newline in the format string consumes zero or more 311 spaces in the input. Otherwise, any run of one or more spaces 312 in the format string consumes as many spaces as possible in 313 the input. Unless the run of spaces in the format string 314 appears adjacent to a newline, the run must consume at least 315 one space from the input or find the end of the input. 316 317 The handling of spaces and newlines differs from that of C's 318 scanf family: in C, newlines are treated as any other space, 319 and it is never an error when a run of spaces in the format 320 string finds no spaces to consume in the input. 321 322 The verbs behave analogously to those of Printf. 323 For example, %x will scan an integer as a hexadecimal number, 324 and %v will scan the default representation format for the value. 325 The Printf verbs %p and %T and the flags # and + are not implemented. 326 For floating-point and complex values, all valid formatting verbs 327 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 328 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 329 and digit-separating underscores (for example: "3.14159_26535_89793"). 330 331 Input processed by verbs is implicitly space-delimited: the 332 implementation of every verb except %c starts by discarding 333 leading spaces from the remaining input, and the %s verb 334 (and %v reading into a string) stops consuming input at the first 335 space or newline character. 336 337 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 338 and 0x (hexadecimal) are accepted when scanning integers 339 without a format or with the %v verb, as are digit-separating 340 underscores. 341 342 Width is interpreted in the input text but there is no 343 syntax for scanning with a precision (no %5.2f, just %5f). 344 If width is provided, it applies after leading spaces are 345 trimmed and specifies the maximum number of runes to read 346 to satisfy the verb. For example, 347 348 Sscanf(" 1234567 ", "%5s%d", &s, &i) 349 350 will set s to "12345" and i to 67 while 351 352 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 353 354 will set s to "12" and i to 34. 355 356 In all the scanning functions, a carriage return followed 357 immediately by a newline is treated as a plain newline 358 (\r\n means the same as \n). 359 360 In all the scanning functions, if an operand implements method 361 Scan (that is, it implements the Scanner interface) that 362 method will be used to scan the text for that operand. Also, 363 if the number of arguments scanned is less than the number of 364 arguments provided, an error is returned. 365 366 All arguments to be scanned must be either pointers to basic 367 types or implementations of the Scanner interface. 368 369 Like Scanf and Fscanf, Sscanf need not consume its entire input. 370 There is no way to recover how much of the input string Sscanf used. 371 372 Note: Fscan etc. can read one character (rune) past the input 373 they return, which means that a loop calling a scan routine 374 may skip some of the input. This is usually a problem only 375 when there is no space between input values. If the reader 376 provided to Fscan implements ReadRune, that method will be used 377 to read characters. If the reader also implements UnreadRune, 378 that method will be used to save the character and successive 379 calls will not lose data. To attach ReadRune and UnreadRune 380 methods to a reader without that capability, use 381 bufio.NewReader. 382 */ 383 package fmt ________________ ERRATA notes.md ed. 8d4e422992cc 2 slips 1. Line 10, written at 11. for nothing read a blank line Edition differs; line still fits. 2. No longer fits. Was line 6: "Package fmt implements formatted I/O with functions analogou...". The slip said: for Package fmt read package fmt The text above is as printed. (exit 0) [TestTwinTableBinary] 92 blank and 176 lone } lines of print.go: deleted, every slip no longer fits; three lines on top, every slip at its line plus 3. [TestOrphans] $ tipin a/notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of a/notes.md. a/notes.md was not touched. Slips are kept in a/notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestOrphans] $ tipin check . ORPHAN a/notes.md.tipin 1 slip, no book. Same edition: drafts/notes-v2.md To reunite: mv 'a/notes.md.tipin' 'drafts/notes-v2.md.tipin' Checked 2 files. 1 orphan. (exit 1) [TestOrphans] $ tipin check . drafts/notes-v2.md 1 slip: 1 fits Checked 2 files. Every slip has its book. (exit 0) [TestOrphans] $ tipin check . NOT A SLIP FILE x.tipin Checked 2 files. 1 not a slip file. (exit 1) [TestOrphans] $ tipin a/notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of a/notes.md. a/notes.md was not touched. Slips are kept in a/notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestOrphans] $ tipin check . ORPHAN a/notes.md.tipin 1 slip, no book. Same edition: drafts/notes-v2.md drafts/notes-v3.md Several candidates. Choose one. Checked 3 files. 1 orphan. (exit 1) [TestOrphans] $ tipin a/notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of a/notes.md. a/notes.md was not touched. Slips are kept in a/notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestOrphans] $ tipin check . ORPHAN a/notes.md.tipin 1 slip, no book. Every slip fits: drafts/notes-v2.md To reunite: mv 'a/notes.md.tipin' 'drafts/notes-v2.md.tipin' Checked 2 files. 1 orphan. (exit 1) [TestOrphans] $ git init -q [TestOrphans] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestOrphans] $ git add . [TestOrphans] $ git commit -q -m book and slips [TestOrphans] $ git mv notes.md renamed.md [TestOrphans] $ tipin check . ORPHAN notes.md.tipin 1 slip, no book. Same edition: renamed.md To reunite: mv 'notes.md.tipin' 'renamed.md.tipin' Checked 2 files. 1 orphan. (exit 1) [TestOrphans] $ git init -q [TestOrphans] $ git add . [TestOrphans] $ git commit -q -m book [TestOrphans] $ git rev-parse HEAD 8b413fc2bf40b2ab0f08063af4351845c6240939 [TestOrphans] $ tipin notes.md 6 "for Package read package" Slip 1 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestOrphans] $ git add . [TestOrphans] $ git commit -q -m slip [TestOrphans] $ git rev-parse HEAD 7ce327b9ec21dc3b7a2003c41f7772a6811a33ca [TestOrphans] $ git commit -q -am a line on top [TestOrphans] $ git rev-parse HEAD 98aa958f0406e1f3b8a7ed41c1099875c3fd1137 [TestOrphans] $ git commit -q -am the slipped line rewritten [TestOrphans] $ git checkout 7ce327b9ec21dc3b7a2003c41f7772a6811a33ca -- notes.md [TestOrphans] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 [1] Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 9ebf966b2645 1 slip 1. Line 6. for Package read package The text above is as printed. (exit 0) [TestOrphans] $ git checkout 98aa958f0406e1f3b8a7ed41c1099875c3fd1137 -- notes.md [TestOrphans] $ tipin show notes.md 1 A line on top. 2 // Copyright 2009 The Go Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 /* 7 [1] Package fmt implements formatted I/O with functions analogous 8 to C's printf and scanf. The format 'verbs' are derived from C's but 9 are simpler. 10 11 # Printing 12 13 The verbs: 14 15 General: 16 17 %v the value in a default format 18 when printing structs, the plus flag (%+v) adds field names 19 %#v a Go-syntax representation of the value 20 %T a Go-syntax representation of the type of the value 21 %% a literal percent sign; consumes no value 22 23 Boolean: 24 25 %t the word true or false 26 27 Integer: 28 29 %b base 2 30 %c the character represented by the corresponding Unicode code point 31 %d base 10 32 %o base 8 33 %O base 8 with 0o prefix 34 %q a single-quoted character literal safely escaped with Go syntax. 35 %x base 16, with lower-case letters for a-f 36 %X base 16, with upper-case letters for A-F 37 %U Unicode format: U+1234; same as "U+%04X" 38 39 Floating-point and complex constituents: 40 41 %b decimalless scientific notation with exponent a power of two, 42 in the manner of strconv.FormatFloat with the 'b' format, 43 e.g. -123456p-78 44 %e scientific notation, e.g. -1.234456e+78 45 %E scientific notation, e.g. -1.234456E+78 46 %f decimal point but no exponent, e.g. 123.456 47 %F synonym for %f 48 %g %e for large exponents, %f otherwise. Precision is discussed below. 49 %G %E for large exponents, %F otherwise 50 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 51 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 52 53 String and slice of bytes (treated equivalently with these verbs): 54 55 %s the uninterpreted bytes of the string or slice 56 %q a double-quoted string safely escaped with Go syntax 57 %x base 16, lower-case, two characters per byte 58 %X base 16, upper-case, two characters per byte 59 60 Slice: 61 62 %p address of 0th element in base 16 notation, with leading 0x 63 64 Pointer: 65 66 %p base 16 notation, with leading 0x 67 The %b, %d, %o, %x and %X verbs also work with pointers, 68 formatting the value exactly as if it were an integer. 69 70 The default format for %v is: 71 72 bool: %t 73 int, int8 etc.: %d 74 uint, uint8 etc.: %d, %#x if printed with %#v 75 float32, complex64, etc: %g 76 string: %s 77 chan: %p 78 pointer: %p 79 80 For compound objects, the elements are printed using these rules, recursively, 81 laid out like this: 82 83 struct: {field0 field1 ...} 84 array, slice: [elem0 elem1 ...] 85 maps: map[key1:value1 key2:value2 ...] 86 pointer to above: &{}, &[], &map[] 87 88 Width is specified by an optional decimal number immediately preceding the verb. 89 If absent, the width is whatever is necessary to represent the value. 90 Precision is specified after the (optional) width by a period followed by a 91 decimal number. If no period is present, a default precision is used. 92 A period with no following number specifies a precision of zero. 93 Examples: 94 95 %f default width, default precision 96 %9f width 9, default precision 97 %.2f default width, precision 2 98 %9.2f width 9, precision 2 99 %9.f width 9, precision 0 100 101 Width and precision are measured in units of Unicode code points, 102 that is, runes. (This differs from C's printf where the 103 units are always measured in bytes.) Either or both of the flags 104 may be replaced with the character '*', causing their values to be 105 obtained from the next operand (preceding the one to format), 106 which must be of type int. 107 108 For most values, width is the minimum number of runes to output, 109 padding the formatted form with spaces if necessary. 110 111 For strings, byte slices and byte arrays, however, precision 112 limits the length of the input to be formatted (not the size of 113 the output), truncating if necessary. Normally it is measured in 114 runes, but for these types when formatted with the %x or %X format 115 it is measured in bytes. 116 117 For floating-point values, width sets the minimum width of the field and 118 precision sets the number of places after the decimal, if appropriate, 119 except that for %g/%G precision sets the maximum number of significant 120 digits (trailing zeros are removed). For example, given 12.345 the format 121 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 122 and %#g is 6; for %g it is the smallest number of digits necessary to identify 123 the value uniquely. 124 125 For complex numbers, the width and precision apply to the two 126 components independently and the result is parenthesized, so %f applied 127 to 1.2+3.4i produces (1.200000+3.400000i). 128 129 When formatting a single integer code point or a rune string (type []rune) 130 with %q, invalid Unicode code points are changed to the Unicode replacement 131 character, U+FFFD, as in strconv.QuoteRune. 132 133 Other flags: 134 135 '+' always print a sign for numeric values; 136 guarantee ASCII-only output for %q (%+q) 137 '-' pad with spaces on the right rather than the left (left-justify the field) 138 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 139 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 140 for %q, print a raw (backquoted) string if strconv.CanBackquote 141 returns true; 142 always print a decimal point for %e, %E, %f, %F, %g and %G; 143 do not remove trailing zeros for %g and %G; 144 write e.g. U+0078 'x' if the character is printable for %U (%#U). 145 ' ' (space) leave a space for elided sign in numbers (% d); 146 put spaces between bytes printing strings or slices in hex (% x, % X) 147 '0' pad with leading zeros rather than spaces; 148 for numbers, this moves the padding after the sign; 149 ignored for strings, byte slices and byte arrays 150 151 Flags are ignored by verbs that do not expect them. 152 For example there is no alternate decimal format, so %#d and %d 153 behave identically. 154 155 For each Printf-like function, there is also a Print function 156 that takes no format and is equivalent to saying %v for every 157 operand. Another variant Println inserts blanks between 158 operands and appends a newline. 159 160 Regardless of the verb, if an operand is an interface value, 161 the internal concrete value is used, not the interface itself. 162 Thus: 163 164 var i interface{} = 23 165 fmt.Printf("%v\n", i) 166 167 will print 23. 168 169 Except when printed using the verbs %T and %p, special 170 formatting considerations apply for operands that implement 171 certain interfaces. In order of application: 172 173 1. If the operand is a reflect.Value, the operand is replaced by the 174 concrete value that it holds, and printing continues with the next rule. 175 176 2. If an operand implements the Formatter interface, it will 177 be invoked. In this case the interpretation of verbs and flags is 178 controlled by that implementation. 179 180 3. If the %v verb is used with the # flag (%#v) and the operand 181 implements the GoStringer interface, that will be invoked. 182 183 If the format (which is implicitly %v for Println etc.) is valid 184 for a string (%s %q %x %X), or is %v but not %#v, 185 the following two rules apply: 186 187 4. If an operand implements the error interface, the Error method 188 will be invoked to convert the object to a string, which will then 189 be formatted as required by the verb (if any). 190 191 5. If an operand implements method String() string, that method 192 will be invoked to convert the object to a string, which will then 193 be formatted as required by the verb (if any). 194 195 For compound operands such as slices and structs, the format 196 applies to the elements of each operand, recursively, not to the 197 operand as a whole. Thus %q will quote each element of a slice 198 of strings, and %6.2f will control formatting for each element 199 of a floating-point array. 200 201 However, when printing a byte slice with a string-like verb 202 (%s %q %x %X), it is treated identically to a string, as a single item. 203 204 To avoid recursion in cases such as 205 206 type X string 207 func (x X) String() string { return Sprintf("<%s>", x) } 208 209 convert the value before recurring: 210 211 func (x X) String() string { return Sprintf("<%s>", string(x)) } 212 213 Infinite recursion can also be triggered by self-referential data 214 structures, such as a slice that contains itself as an element, if 215 that type has a String method. Such pathologies are rare, however, 216 and the package does not protect against them. 217 218 When printing a struct, fmt cannot and therefore does not invoke 219 formatting methods such as Error or String on unexported fields. 220 221 # Explicit argument indexes 222 223 In Printf, Sprintf, and Fprintf, the default behavior is for each 224 formatting verb to format successive arguments passed in the call. 225 However, the notation [n] immediately before the verb indicates that the 226 nth one-indexed argument is to be formatted instead. The same notation 227 before a '*' for a width or precision selects the argument index holding 228 the value. After processing a bracketed expression [n], subsequent verbs 229 will use arguments n+1, n+2, etc. unless otherwise directed. 230 231 For example, 232 233 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 234 235 will yield "22 11", while 236 237 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 238 239 equivalent to 240 241 fmt.Sprintf("%6.2f", 12.0) 242 243 will yield " 12.00". Because an explicit index affects subsequent verbs, 244 this notation can be used to print the same values multiple times 245 by resetting the index for the first argument to be repeated: 246 247 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 248 249 will yield "16 17 0x10 0x11". 250 251 # Format errors 252 253 If an invalid argument is given for a verb, such as providing 254 a string to %d, the generated string will contain a 255 description of the problem, as in these examples: 256 257 Wrong type or unknown verb: %!verb(type=value) 258 Printf("%d", "hi"): %!d(string=hi) 259 Too many arguments: %!(EXTRA type=value) 260 Printf("hi", "guys"): hi%!(EXTRA string=guys) 261 Too few arguments: %!verb(MISSING) 262 Printf("hi%d"): hi%!d(MISSING) 263 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 264 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 265 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 266 Invalid or invalid use of argument index: %!(BADINDEX) 267 Printf("%*[2]d", 7): %!d(BADINDEX) 268 Printf("%.[2]d", 7): %!d(BADINDEX) 269 270 All errors begin with the string "%!" followed sometimes 271 by a single character (the verb) and end with a parenthesized 272 description. 273 274 If an Error or String method triggers a panic when called by a 275 print routine, the fmt package reformats the error message 276 from the panic, decorating it with an indication that it came 277 through the fmt package. For example, if a String method 278 calls panic("bad"), the resulting formatted message will look 279 like 280 281 %!s(PANIC=bad) 282 283 The %!s just shows the print verb in use when the failure 284 occurred. If the panic is caused by a nil receiver to an Error 285 or String method, however, the output is the undecorated 286 string, "". 287 288 # Scanning 289 290 An analogous set of functions scans formatted text to yield 291 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 292 Fscanf and Fscanln read from a specified io.Reader; Sscan, 293 Sscanf and Sscanln read from an argument string. 294 295 Scan, Fscan, Sscan treat newlines in the input as spaces. 296 297 Scanln, Fscanln and Sscanln stop scanning at a newline and 298 require that the items be followed by a newline or EOF. 299 300 Scanf, Fscanf, and Sscanf parse the arguments according to a 301 format string, analogous to that of Printf. In the text that 302 follows, 'space' means any Unicode whitespace character 303 except newline. 304 305 In the format string, a verb introduced by the % character 306 consumes and parses input; these verbs are described in more 307 detail below. A character other than %, space, or newline in 308 the format consumes exactly that input character, which must 309 be present. A newline with zero or more spaces before it in 310 the format string consumes zero or more spaces in the input 311 followed by a single newline or the end of the input. A space 312 following a newline in the format string consumes zero or more 313 spaces in the input. Otherwise, any run of one or more spaces 314 in the format string consumes as many spaces as possible in 315 the input. Unless the run of spaces in the format string 316 appears adjacent to a newline, the run must consume at least 317 one space from the input or find the end of the input. 318 319 The handling of spaces and newlines differs from that of C's 320 scanf family: in C, newlines are treated as any other space, 321 and it is never an error when a run of spaces in the format 322 string finds no spaces to consume in the input. 323 324 The verbs behave analogously to those of Printf. 325 For example, %x will scan an integer as a hexadecimal number, 326 and %v will scan the default representation format for the value. 327 The Printf verbs %p and %T and the flags # and + are not implemented. 328 For floating-point and complex values, all valid formatting verbs 329 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 330 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 331 and digit-separating underscores (for example: "3.14159_26535_89793"). 332 333 Input processed by verbs is implicitly space-delimited: the 334 implementation of every verb except %c starts by discarding 335 leading spaces from the remaining input, and the %s verb 336 (and %v reading into a string) stops consuming input at the first 337 space or newline character. 338 339 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 340 and 0x (hexadecimal) are accepted when scanning integers 341 without a format or with the %v verb, as are digit-separating 342 underscores. 343 344 Width is interpreted in the input text but there is no 345 syntax for scanning with a precision (no %5.2f, just %5f). 346 If width is provided, it applies after leading spaces are 347 trimmed and specifies the maximum number of runes to read 348 to satisfy the verb. For example, 349 350 Sscanf(" 1234567 ", "%5s%d", &s, &i) 351 352 will set s to "12345" and i to 67 while 353 354 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 355 356 will set s to "12" and i to 34. 357 358 In all the scanning functions, a carriage return followed 359 immediately by a newline is treated as a plain newline 360 (\r\n means the same as \n). 361 362 In all the scanning functions, if an operand implements method 363 Scan (that is, it implements the Scanner interface) that 364 method will be used to scan the text for that operand. Also, 365 if the number of arguments scanned is less than the number of 366 arguments provided, an error is returned. 367 368 All arguments to be scanned must be either pointers to basic 369 types or implementations of the Scanner interface. 370 371 Like Scanf and Fscanf, Sscanf need not consume its entire input. 372 There is no way to recover how much of the input string Sscanf used. 373 374 Note: Fscan etc. can read one character (rune) past the input 375 they return, which means that a loop calling a scan routine 376 may skip some of the input. This is usually a problem only 377 when there is no space between input values. If the reader 378 provided to Fscan implements ReadRune, that method will be used 379 to read characters. If the reader also implements UnreadRune, 380 that method will be used to save the character and successive 381 calls will not lose data. To attach ReadRune and UnreadRune 382 methods to a reader without that capability, use 383 bufio.NewReader. 384 */ 385 package fmt ________________ ERRATA notes.md ed. ba113b023598 1 slip 1. Line 7, written at 6. for Package read package Edition differs; line still fits. The text above is as printed. (exit 0) [TestOrphans] $ git checkout HEAD -- notes.md [TestOrphans] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt provides formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. a52d54173694 1 slip 1. No longer fits. Was line 6: "Package fmt implements formatted I/O with functions analogou...". The slip said: for Package read package The text above is as printed. (exit 0) [TestOrphans] $ git checkout -q 8b413fc2bf40b2ab0f08063af4351845c6240939 [TestOrphans] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt (stderr) No slips for notes.md. (exit 0) [TestBareCopy] $ tipin a/notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of a/notes.md. a/notes.md was not touched. Slips are kept in a/notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestBareCopy] $ tipin check . a/notes.md 1 slip: 1 fits BARE COPY b/notes.md same edition as a/notes.md, which has 1 slip. To carry the slip: cp 'a/notes.md.tipin' 'b/notes.md.tipin' Checked 4 files. 1 book with slips, 1 bare copy. (exit 1) [TestBareCopy] $ tipin check . a/notes.md 1 slip: 1 fits b/notes.md 1 slip: 1 fits Checked 5 files. Every slip has its book. (exit 0) [TestBareCopy] $ tipin check . a/notes.md 1 slip: 1 fits b/notes.md 1 slip: 1 fits Checked 4 files. Every slip has its book. (exit 0) [TestBareCopy] $ tipin check $GOROOT/src Checked 9502 files. No slips. (0.15 s, error ) [TestBookNeverTouched] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestBookNeverTouched] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 [1] // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 9ebf966b2645 1 slip 1. Line 3. for Friday read Thursday The text above is as printed. (exit 0) [TestBookNeverTouched] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." for Friday read Thursday This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestBookNeverTouched] $ tipin drop notes.md 1 Slip 1 withdrawn. 0 slips. (exit 0) [TestBookNeverTouched] $ tipin file 1 x (stderr) file.tipin cannot be written here. Nothing was changed. (exit 1) [TestBookNeverTouched] grep sidecar.go:112: f, err := os.OpenFile(tmp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) [TestBookNeverTouched] grep sidecar.go:127: os.Remove(tmp) [TestPrint] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." for Friday read Thursday This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin notes.md 17 "for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net th" Slip 1 tipped in at line 17 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 17: " when printing structs, the plus flag (%+v) adds field name..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net th This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.md. nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.md was not touched. Slips are kept in nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin print nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA nnnnnnnnnnnnnnnnnnnnnnnnnnn... ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." for Friday read Thursday This slip belongs to edition 9ebf966b2645 of nnnnnnnnnnnnnnnnnnnnnnnnnnn... and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 1 of 5 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 10: "# Printing" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 2. Line 20: " %% a literal percent sign; consumes no value" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 2 of 5 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 3. Line 30: " %d base 10" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 4. Line 40: " %b decimalless scientific notation with exponent a power of..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 3 of 5 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 5. Line 50: " %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 6. Line 60: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 4 of 5 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 7. Line 70: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 8. Line 80: "laid out like this:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 5 of 5 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 9. Line 90: "decimal number. If no period is present, a default precision..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. 2f5692d5fb84 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." for Friday read Thursday This slip belongs to edition 2f5692d5fb84 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin "no\ntes.md" 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of no tes.md. no tes.md was not touched. Slips are kept in no tes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin print "no\ntes.md" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA no tes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." for Friday read Thursday This slip belongs to edition 9ebf966b2645 of no tes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin notes.md 101 wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww Slip 101 tipped in at line 101 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 101 slips. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 1 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 1. Line 1: "// Copyright 2009 The Go Authors. All rights reserved." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 2. Line 2: "// Use of this source code is governed by a BSD-style" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 2 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 3. Line 3: "// license that can be found in the LICENSE file." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 4. Line 4: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 3 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 5. Line 5: "/*" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 6. Line 6: "Package fmt implements formatted I/O with functions analogou..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 4 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 7. Line 7: "to C's printf and scanf. The format 'verbs' are derived fro..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 8. Line 8: "are simpler." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 5 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 9. Line 9: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 10. Line 10: "# Printing" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 6 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 11. Line 11: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 12. Line 12: "The verbs:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 7 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 13. Line 13: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 14. Line 14: "General:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 8 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 15. Line 15: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 16. Line 16: " %v the value in a default format" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 9 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 17. Line 17: " when printing structs, the plus flag (%+v) adds field name..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 18. Line 18: " %#v a Go-syntax representation of the value" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 10 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 19. Line 19: " %T a Go-syntax representation of the type of the value" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 20. Line 20: " %% a literal percent sign; consumes no value" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 11 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 21. Line 21: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 22. Line 22: "Boolean:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 12 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 23. Line 23: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 24. Line 24: " %t the word true or false" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 13 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 25. Line 25: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 26. Line 26: "Integer:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 14 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 27. Line 27: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 28. Line 28: " %b base 2" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 15 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 29. Line 29: " %c the character represented by the corresponding Unicode c..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 30. Line 30: " %d base 10" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 16 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 31. Line 31: " %o base 8" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 32. Line 32: " %O base 8 with 0o prefix" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 17 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 33. Line 33: " %q a single-quoted character literal safely escaped with Go..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 34. Line 34: " %x base 16, with lower-case letters for a-f" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 18 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 35. Line 35: " %X base 16, with upper-case letters for A-F" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 36. Line 36: " %U Unicode format: U+1234; same as "U+%04X"" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 19 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 37. Line 37: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 38. Line 38: "Floating-point and complex constituents:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 20 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 39. Line 39: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 40. Line 40: " %b decimalless scientific notation with exponent a power of..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 21 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 41. Line 41: " in the manner of strconv.FormatFloat with the 'b' format," for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 42. Line 42: " e.g. -123456p-78" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 22 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 43. Line 43: " %e scientific notation, e.g. -1.234456e+78" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 44. Line 44: " %E scientific notation, e.g. -1.234456E+78" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 23 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 45. Line 45: " %f decimal point but no exponent, e.g. 123.456" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 46. Line 46: " %F synonym for %f" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 24 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 47. Line 47: " %g %e for large exponents, %f otherwise. Precision is discu..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 48. Line 48: " %G %E for large exponents, %F otherwise" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 25 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 49. Line 49: " %x hexadecimal notation (with decimal power of two exponent..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 50. Line 50: " %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 26 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 51. Line 51: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 52. Line 52: "String and slice of bytes (treated equivalently with these v..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 27 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 53. Line 53: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 54. Line 54: " %s the uninterpreted bytes of the string or slice" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 28 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 55. Line 55: " %q a double-quoted string safely escaped with Go syntax" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 56. Line 56: " %x base 16, lower-case, two characters per byte" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 29 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 57. Line 57: " %X base 16, upper-case, two characters per byte" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 58. Line 58: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 30 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 59. Line 59: "Slice:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 60. Line 60: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 31 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 61. Line 61: " %p address of 0th element in base 16 notation, with leading..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 62. Line 62: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 32 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 63. Line 63: "Pointer:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 64. Line 64: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 33 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 65. Line 65: " %p base 16 notation, with leading 0x" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 66. Line 66: " The %b, %d, %o, %x and %X verbs also work with pointers," for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 34 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 67. Line 67: " formatting the value exactly as if it were an integer." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 68. Line 68: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 35 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 69. Line 69: "The default format for %v is:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 70. Line 70: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 36 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 71. Line 71: " bool: %t" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 72. Line 72: " int, int8 etc.: %d" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 37 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 73. Line 73: " uint, uint8 etc.: %d, %#x if printed with %#v" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 74. Line 74: " float32, complex64, etc: %g" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 38 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 75. Line 75: " string: %s" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 76. Line 76: " chan: %p" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 39 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 77. Line 77: " pointer: %p" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 78. Line 78: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 40 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 79. Line 79: "For compound objects, the elements are printed using these r..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 80. Line 80: "laid out like this:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 41 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 81. Line 81: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 82. Line 82: " struct: {field0 field1 ...}" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 42 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 83. Line 83: " array, slice: [elem0 elem1 ...]" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 84. Line 84: " maps: map[key1:value1 key2:value2 ...]" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 43 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 85. Line 85: " pointer to above: &{}, &[], &map[]" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 86. Line 86: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 44 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 87. Line 87: "Width is specified by an optional decimal number immediately..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 88. Line 88: "If absent, the width is whatever is necessary to represent t..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 45 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 89. Line 89: "Precision is specified after the (optional) width by a perio..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 90. Line 90: "decimal number. If no period is present, a default precision..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 46 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 91. Line 91: "A period with no following number specifies a precision of z..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 92. Line 92: "Examples:" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 47 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 93. Line 93: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 94. Line 94: " %f default width, default precision" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 48 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 95. Line 95: " %9f width 9, default precision" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 96. Line 96: " %.2f default width, precision 2" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 49 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 97. Line 97: " %9.2f width 9, precision 2" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 98. Line 98: " %9.f width 9, precision 0" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 50 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 99. Line 99: "" for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx 100. Line 100: "Width and precision are measured in units of Unicode code po..." for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirty read net forty five for net thirtyx This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA, slip sheet 51 of 51 notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 101. Line 101: "that is, runes. (This differs from C's printf where the" wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestPrint] $ tipin notes.md 6 "for Package read package" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. a52d54173694 printed 2026-10-14 Please correct the following before use. 1. Line 3: "// license that can be found in the LICENSE file." Edition differs; line still fits. for Friday read Thursday This slip belongs to edition a52d54173694 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (stderr) 1 slip not printed: it no longer fits. (exit 0) [TestPrint] $ tipin print notes.md 2 (stderr) 1 slip not printed: it no longer fits. (exit 1) [TestPrint] $ tipin drop notes.md 1 Slip 1 withdrawn. 1 slip. (exit 0) [TestPrint] $ tipin print notes.md - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut ERRATA notes.md ed. 9ebf966b2645 printed 2026-10-14 Please correct the following before use. 2. Line 6: "Package fmt implements formatted I/O with functions analogou..." for Package read package This slip belongs to edition 9ebf966b2645 of notes.md and to no other. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cut (exit 0) [TestPrint] $ tipin print notes.md 1 (stderr) Slip 1 is withdrawn. (exit 1) [TestPrint] $ tipin print notes.md 7 (stderr) notes.md has no slip 7. (exit 1) [TestRefusals] $ tipin notes.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestRefusals] $ tipin notes.md 0 x (stderr) notes.md has 384 lines. There is no line 0. (exit 1) [TestRefusals] $ tipin notes.md 385 x (stderr) notes.md has 384 lines. There is no line 385. (exit 1) [TestRefusals] $ tipin notes.md 3 " " (stderr) A slip needs words. (exit 1) [TestRefusals] $ tipin notes.md 3 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (stderr) A slip holds at most 500 characters. (exit 1) [TestRefusals] $ tipin notes.md 3 "a\nb" (stderr) A slip is one line of plain words. (exit 1) [TestRefusals] $ tipin notes.md 3 "a\x1bb" (stderr) A slip is one line of plain words. (exit 1) [TestRefusals] $ tipin notes.md 3 "words\t" (stderr) A slip is one line of plain words. (exit 1) [TestRefusals] $ tipin missing.md 1 x (stderr) There is no file missing.md. (exit 1) [TestRefusals] $ tipin folder 1 x (stderr) folder is a directory, not a file. (exit 1) [TestRefusals] $ tipin notes.md.tipin 1 x (stderr) That is a slip file, not a book. (exit 1) [TestRefusals] $ tipin show notes.md.tipin (stderr) That is a slip file, not a book. (exit 1) [TestRefusals] $ tipin ls 1 x (stderr) That does not look like a text file. (exit 1) [TestRefusals] $ tipin big.md 1 x (stderr) That file is larger than 8 MiB. (exit 1) [TestRefusals] $ tipin bad.md 1 x (stderr) bad.md.tipin is not a slip file this version can read. Nothing was changed. (exit 1) [TestRefusals] $ tipin drop bad.md 1 (stderr) bad.md.tipin is not a slip file this version can read. Nothing was changed. (exit 1) [TestRefusals] $ tipin drop notes.md 5 (stderr) notes.md has no slip 5. (exit 1) [TestRefusals] $ tipin (stderr) tipin FILE LINE TEXT... tip in a slip at line LINE (TEXT is the correction) tipin show FILE print the file, numbered, with the slips at the foot tipin print FILE [N] print the slips as a cut-out slip (all, or slip N) tipin check [DIR] find every slip file under DIR (default .): orphans, bare copies, slips that no longer fit, files that are not slip files tipin drop FILE N withdraw slip N (it stays in the sidecar, marked) (exit 2) [TestRefusals] $ tipin notes.md (stderr) tipin FILE LINE TEXT... tip in a slip at line LINE (TEXT is the correction) tipin show FILE print the file, numbered, with the slips at the foot tipin print FILE [N] print the slips as a cut-out slip (all, or slip N) tipin check [DIR] find every slip file under DIR (default .): orphans, bare copies, slips that no longer fit, files that are not slip files tipin drop FILE N withdraw slip N (it stays in the sidecar, marked) (exit 2) [TestRefusals] $ tipin show (stderr) tipin FILE LINE TEXT... tip in a slip at line LINE (TEXT is the correction) tipin show FILE print the file, numbered, with the slips at the foot tipin print FILE [N] print the slips as a cut-out slip (all, or slip N) tipin check [DIR] find every slip file under DIR (default .): orphans, bare copies, slips that no longer fit, files that are not slip files tipin drop FILE N withdraw slip N (it stays in the sidecar, marked) (exit 2) [TestRefusals] $ tipin help tipin FILE LINE TEXT... tip in a slip at line LINE (TEXT is the correction) tipin show FILE print the file, numbered, with the slips at the foot tipin print FILE [N] print the slips as a cut-out slip (all, or slip N) tipin check [DIR] find every slip file under DIR (default .): orphans, bare copies, slips that no longer fit, files that are not slip files tipin drop FILE N withdraw slip N (it stays in the sidecar, marked) (exit 2) [TestRefusals] $ tipin crlf.md 3 "for Friday read Thursday" Slip 1 tipped in at line 3 of crlf.md. crlf.md was not touched. Slips are kept in crlf.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestRefusals] $ tipin show crlf.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 [1] // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA crlf.md ed. 82e2cb5e592d 1 slip 1. Line 3. for Friday read Thursday The text above is as printed. (exit 0) [TestRefusals] $ tipin noeol.md 384 "for package read Package" Slip 1 tipped in at line 384 of noeol.md. noeol.md was not touched. Slips are kept in noeol.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestRefusals] $ tipin show noeol.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 [1] package fmt ________________ ERRATA noeol.md ed. 92be30a365ee 1 slip 1. Line 384. for package read Package The text above is as printed. (exit 0) [TestRefusals] $ tipin drop notes.md 1 Slip 1 withdrawn. 0 slips. (exit 0) [TestRefusals] $ tipin drop notes.md 1 (stderr) Slip 1 is already withdrawn. (exit 1) [TestRefusals] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 to C's printf and scanf. The format 'verbs' are derived from C's but 8 are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 9ebf966b2645 0 slips, 1 withdrawn 1. Withdrawn 2026-10-14. The text above is as printed. (exit 0) [TestNumbersStable] $ tipin notes.md 3 "for this read that" Slip 1 tipped in at line 3 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 1 slip. (exit 0) [TestNumbersStable] $ tipin notes.md 6 "for this read that" Slip 2 tipped in at line 6 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 2 slips. (exit 0) [TestNumbersStable] $ tipin notes.md 7 "for this read that" Slip 3 tipped in at line 7 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 3 slips. (exit 0) [TestNumbersStable] $ tipin drop notes.md 2 Slip 2 withdrawn. 2 slips. (exit 0) [TestNumbersStable] $ tipin notes.md 8 "for are simpler read is simpler" Slip 4 tipped in at line 8 of notes.md. notes.md was not touched. Slips are kept in notes.md.tipin. Carry it with the file. 3 slips. (exit 0) [TestNumbersStable] $ tipin show notes.md 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 [1] // license that can be found in the LICENSE file. 4 5 /* 6 Package fmt implements formatted I/O with functions analogous 7 [3] to C's printf and scanf. The format 'verbs' are derived from C's but 8 [4] are simpler. 9 10 # Printing 11 12 The verbs: 13 14 General: 15 16 %v the value in a default format 17 when printing structs, the plus flag (%+v) adds field names 18 %#v a Go-syntax representation of the value 19 %T a Go-syntax representation of the type of the value 20 %% a literal percent sign; consumes no value 21 22 Boolean: 23 24 %t the word true or false 25 26 Integer: 27 28 %b base 2 29 %c the character represented by the corresponding Unicode code point 30 %d base 10 31 %o base 8 32 %O base 8 with 0o prefix 33 %q a single-quoted character literal safely escaped with Go syntax. 34 %x base 16, with lower-case letters for a-f 35 %X base 16, with upper-case letters for A-F 36 %U Unicode format: U+1234; same as "U+%04X" 37 38 Floating-point and complex constituents: 39 40 %b decimalless scientific notation with exponent a power of two, 41 in the manner of strconv.FormatFloat with the 'b' format, 42 e.g. -123456p-78 43 %e scientific notation, e.g. -1.234456e+78 44 %E scientific notation, e.g. -1.234456E+78 45 %f decimal point but no exponent, e.g. 123.456 46 %F synonym for %f 47 %g %e for large exponents, %f otherwise. Precision is discussed below. 48 %G %E for large exponents, %F otherwise 49 %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20 50 %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20 51 52 String and slice of bytes (treated equivalently with these verbs): 53 54 %s the uninterpreted bytes of the string or slice 55 %q a double-quoted string safely escaped with Go syntax 56 %x base 16, lower-case, two characters per byte 57 %X base 16, upper-case, two characters per byte 58 59 Slice: 60 61 %p address of 0th element in base 16 notation, with leading 0x 62 63 Pointer: 64 65 %p base 16 notation, with leading 0x 66 The %b, %d, %o, %x and %X verbs also work with pointers, 67 formatting the value exactly as if it were an integer. 68 69 The default format for %v is: 70 71 bool: %t 72 int, int8 etc.: %d 73 uint, uint8 etc.: %d, %#x if printed with %#v 74 float32, complex64, etc: %g 75 string: %s 76 chan: %p 77 pointer: %p 78 79 For compound objects, the elements are printed using these rules, recursively, 80 laid out like this: 81 82 struct: {field0 field1 ...} 83 array, slice: [elem0 elem1 ...] 84 maps: map[key1:value1 key2:value2 ...] 85 pointer to above: &{}, &[], &map[] 86 87 Width is specified by an optional decimal number immediately preceding the verb. 88 If absent, the width is whatever is necessary to represent the value. 89 Precision is specified after the (optional) width by a period followed by a 90 decimal number. If no period is present, a default precision is used. 91 A period with no following number specifies a precision of zero. 92 Examples: 93 94 %f default width, default precision 95 %9f width 9, default precision 96 %.2f default width, precision 2 97 %9.2f width 9, precision 2 98 %9.f width 9, precision 0 99 100 Width and precision are measured in units of Unicode code points, 101 that is, runes. (This differs from C's printf where the 102 units are always measured in bytes.) Either or both of the flags 103 may be replaced with the character '*', causing their values to be 104 obtained from the next operand (preceding the one to format), 105 which must be of type int. 106 107 For most values, width is the minimum number of runes to output, 108 padding the formatted form with spaces if necessary. 109 110 For strings, byte slices and byte arrays, however, precision 111 limits the length of the input to be formatted (not the size of 112 the output), truncating if necessary. Normally it is measured in 113 runes, but for these types when formatted with the %x or %X format 114 it is measured in bytes. 115 116 For floating-point values, width sets the minimum width of the field and 117 precision sets the number of places after the decimal, if appropriate, 118 except that for %g/%G precision sets the maximum number of significant 119 digits (trailing zeros are removed). For example, given 12.345 the format 120 %6.3f prints 12.345 while %.3g prints 12.3. The default precision for %e, %f 121 and %#g is 6; for %g it is the smallest number of digits necessary to identify 122 the value uniquely. 123 124 For complex numbers, the width and precision apply to the two 125 components independently and the result is parenthesized, so %f applied 126 to 1.2+3.4i produces (1.200000+3.400000i). 127 128 When formatting a single integer code point or a rune string (type []rune) 129 with %q, invalid Unicode code points are changed to the Unicode replacement 130 character, U+FFFD, as in strconv.QuoteRune. 131 132 Other flags: 133 134 '+' always print a sign for numeric values; 135 guarantee ASCII-only output for %q (%+q) 136 '-' pad with spaces on the right rather than the left (left-justify the field) 137 '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o), 138 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p); 139 for %q, print a raw (backquoted) string if strconv.CanBackquote 140 returns true; 141 always print a decimal point for %e, %E, %f, %F, %g and %G; 142 do not remove trailing zeros for %g and %G; 143 write e.g. U+0078 'x' if the character is printable for %U (%#U). 144 ' ' (space) leave a space for elided sign in numbers (% d); 145 put spaces between bytes printing strings or slices in hex (% x, % X) 146 '0' pad with leading zeros rather than spaces; 147 for numbers, this moves the padding after the sign; 148 ignored for strings, byte slices and byte arrays 149 150 Flags are ignored by verbs that do not expect them. 151 For example there is no alternate decimal format, so %#d and %d 152 behave identically. 153 154 For each Printf-like function, there is also a Print function 155 that takes no format and is equivalent to saying %v for every 156 operand. Another variant Println inserts blanks between 157 operands and appends a newline. 158 159 Regardless of the verb, if an operand is an interface value, 160 the internal concrete value is used, not the interface itself. 161 Thus: 162 163 var i interface{} = 23 164 fmt.Printf("%v\n", i) 165 166 will print 23. 167 168 Except when printed using the verbs %T and %p, special 169 formatting considerations apply for operands that implement 170 certain interfaces. In order of application: 171 172 1. If the operand is a reflect.Value, the operand is replaced by the 173 concrete value that it holds, and printing continues with the next rule. 174 175 2. If an operand implements the Formatter interface, it will 176 be invoked. In this case the interpretation of verbs and flags is 177 controlled by that implementation. 178 179 3. If the %v verb is used with the # flag (%#v) and the operand 180 implements the GoStringer interface, that will be invoked. 181 182 If the format (which is implicitly %v for Println etc.) is valid 183 for a string (%s %q %x %X), or is %v but not %#v, 184 the following two rules apply: 185 186 4. If an operand implements the error interface, the Error method 187 will be invoked to convert the object to a string, which will then 188 be formatted as required by the verb (if any). 189 190 5. If an operand implements method String() string, that method 191 will be invoked to convert the object to a string, which will then 192 be formatted as required by the verb (if any). 193 194 For compound operands such as slices and structs, the format 195 applies to the elements of each operand, recursively, not to the 196 operand as a whole. Thus %q will quote each element of a slice 197 of strings, and %6.2f will control formatting for each element 198 of a floating-point array. 199 200 However, when printing a byte slice with a string-like verb 201 (%s %q %x %X), it is treated identically to a string, as a single item. 202 203 To avoid recursion in cases such as 204 205 type X string 206 func (x X) String() string { return Sprintf("<%s>", x) } 207 208 convert the value before recurring: 209 210 func (x X) String() string { return Sprintf("<%s>", string(x)) } 211 212 Infinite recursion can also be triggered by self-referential data 213 structures, such as a slice that contains itself as an element, if 214 that type has a String method. Such pathologies are rare, however, 215 and the package does not protect against them. 216 217 When printing a struct, fmt cannot and therefore does not invoke 218 formatting methods such as Error or String on unexported fields. 219 220 # Explicit argument indexes 221 222 In Printf, Sprintf, and Fprintf, the default behavior is for each 223 formatting verb to format successive arguments passed in the call. 224 However, the notation [n] immediately before the verb indicates that the 225 nth one-indexed argument is to be formatted instead. The same notation 226 before a '*' for a width or precision selects the argument index holding 227 the value. After processing a bracketed expression [n], subsequent verbs 228 will use arguments n+1, n+2, etc. unless otherwise directed. 229 230 For example, 231 232 fmt.Sprintf("%[2]d %[1]d\n", 11, 22) 233 234 will yield "22 11", while 235 236 fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6) 237 238 equivalent to 239 240 fmt.Sprintf("%6.2f", 12.0) 241 242 will yield " 12.00". Because an explicit index affects subsequent verbs, 243 this notation can be used to print the same values multiple times 244 by resetting the index for the first argument to be repeated: 245 246 fmt.Sprintf("%d %d %#[1]x %#x", 16, 17) 247 248 will yield "16 17 0x10 0x11". 249 250 # Format errors 251 252 If an invalid argument is given for a verb, such as providing 253 a string to %d, the generated string will contain a 254 description of the problem, as in these examples: 255 256 Wrong type or unknown verb: %!verb(type=value) 257 Printf("%d", "hi"): %!d(string=hi) 258 Too many arguments: %!(EXTRA type=value) 259 Printf("hi", "guys"): hi%!(EXTRA string=guys) 260 Too few arguments: %!verb(MISSING) 261 Printf("hi%d"): hi%!d(MISSING) 262 Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC) 263 Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi 264 Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi 265 Invalid or invalid use of argument index: %!(BADINDEX) 266 Printf("%*[2]d", 7): %!d(BADINDEX) 267 Printf("%.[2]d", 7): %!d(BADINDEX) 268 269 All errors begin with the string "%!" followed sometimes 270 by a single character (the verb) and end with a parenthesized 271 description. 272 273 If an Error or String method triggers a panic when called by a 274 print routine, the fmt package reformats the error message 275 from the panic, decorating it with an indication that it came 276 through the fmt package. For example, if a String method 277 calls panic("bad"), the resulting formatted message will look 278 like 279 280 %!s(PANIC=bad) 281 282 The %!s just shows the print verb in use when the failure 283 occurred. If the panic is caused by a nil receiver to an Error 284 or String method, however, the output is the undecorated 285 string, "". 286 287 # Scanning 288 289 An analogous set of functions scans formatted text to yield 290 values. Scan, Scanf and Scanln read from os.Stdin; Fscan, 291 Fscanf and Fscanln read from a specified io.Reader; Sscan, 292 Sscanf and Sscanln read from an argument string. 293 294 Scan, Fscan, Sscan treat newlines in the input as spaces. 295 296 Scanln, Fscanln and Sscanln stop scanning at a newline and 297 require that the items be followed by a newline or EOF. 298 299 Scanf, Fscanf, and Sscanf parse the arguments according to a 300 format string, analogous to that of Printf. In the text that 301 follows, 'space' means any Unicode whitespace character 302 except newline. 303 304 In the format string, a verb introduced by the % character 305 consumes and parses input; these verbs are described in more 306 detail below. A character other than %, space, or newline in 307 the format consumes exactly that input character, which must 308 be present. A newline with zero or more spaces before it in 309 the format string consumes zero or more spaces in the input 310 followed by a single newline or the end of the input. A space 311 following a newline in the format string consumes zero or more 312 spaces in the input. Otherwise, any run of one or more spaces 313 in the format string consumes as many spaces as possible in 314 the input. Unless the run of spaces in the format string 315 appears adjacent to a newline, the run must consume at least 316 one space from the input or find the end of the input. 317 318 The handling of spaces and newlines differs from that of C's 319 scanf family: in C, newlines are treated as any other space, 320 and it is never an error when a run of spaces in the format 321 string finds no spaces to consume in the input. 322 323 The verbs behave analogously to those of Printf. 324 For example, %x will scan an integer as a hexadecimal number, 325 and %v will scan the default representation format for the value. 326 The Printf verbs %p and %T and the flags # and + are not implemented. 327 For floating-point and complex values, all valid formatting verbs 328 (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept 329 both decimal and hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") 330 and digit-separating underscores (for example: "3.14159_26535_89793"). 331 332 Input processed by verbs is implicitly space-delimited: the 333 implementation of every verb except %c starts by discarding 334 leading spaces from the remaining input, and the %s verb 335 (and %v reading into a string) stops consuming input at the first 336 space or newline character. 337 338 The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), 339 and 0x (hexadecimal) are accepted when scanning integers 340 without a format or with the %v verb, as are digit-separating 341 underscores. 342 343 Width is interpreted in the input text but there is no 344 syntax for scanning with a precision (no %5.2f, just %5f). 345 If width is provided, it applies after leading spaces are 346 trimmed and specifies the maximum number of runes to read 347 to satisfy the verb. For example, 348 349 Sscanf(" 1234567 ", "%5s%d", &s, &i) 350 351 will set s to "12345" and i to 67 while 352 353 Sscanf(" 12 34 567 ", "%5s%d", &s, &i) 354 355 will set s to "12" and i to 34. 356 357 In all the scanning functions, a carriage return followed 358 immediately by a newline is treated as a plain newline 359 (\r\n means the same as \n). 360 361 In all the scanning functions, if an operand implements method 362 Scan (that is, it implements the Scanner interface) that 363 method will be used to scan the text for that operand. Also, 364 if the number of arguments scanned is less than the number of 365 arguments provided, an error is returned. 366 367 All arguments to be scanned must be either pointers to basic 368 types or implementations of the Scanner interface. 369 370 Like Scanf and Fscanf, Sscanf need not consume its entire input. 371 There is no way to recover how much of the input string Sscanf used. 372 373 Note: Fscan etc. can read one character (rune) past the input 374 they return, which means that a loop calling a scan routine 375 may skip some of the input. This is usually a problem only 376 when there is no space between input values. If the reader 377 provided to Fscan implements ReadRune, that method will be used 378 to read characters. If the reader also implements UnreadRune, 379 that method will be used to save the character and successive 380 calls will not lose data. To attach ReadRune and UnreadRune 381 methods to a reader without that capability, use 382 bufio.NewReader. 383 */ 384 package fmt ________________ ERRATA notes.md ed. 9ebf966b2645 3 slips, 1 withdrawn 1. Line 3. for this read that 2. Withdrawn 2026-10-14. 3. Line 7. for this read that 4. Line 8. for are simpler read is simpler The text above is as printed. (exit 0)