LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package fmt | 5 package fmt |
6 | 6 |
7 import ( | 7 import ( |
8 "strconv" | 8 "strconv" |
9 "unicode/utf8" | 9 "unicode/utf8" |
10 ) | 10 ) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 func (f *fmt) formatFloat(v float64, verb byte, prec, n int) { | 362 func (f *fmt) formatFloat(v float64, verb byte, prec, n int) { |
363 // We leave one byte at the beginning of f.intbuf for a sign if needed, | 363 // We leave one byte at the beginning of f.intbuf for a sign if needed, |
364 // and make it a space, which we might be able to use. | 364 // and make it a space, which we might be able to use. |
365 f.intbuf[0] = ' ' | 365 f.intbuf[0] = ' ' |
366 slice := strconv.AppendFloat(f.intbuf[0:1], v, verb, prec, n) | 366 slice := strconv.AppendFloat(f.intbuf[0:1], v, verb, prec, n) |
367 // Add a plus sign or space to the floating-point string representation
if missing and required. | 367 // Add a plus sign or space to the floating-point string representation
if missing and required. |
368 // The formatted number starts at slice[1]. | 368 // The formatted number starts at slice[1]. |
369 switch slice[1] { | 369 switch slice[1] { |
370 case '-', '+': | 370 case '-', '+': |
371 // If we're zero padding, want the sign before the leading zeros
. | 371 // If we're zero padding, want the sign before the leading zeros
. |
372 » » // Achieve this by writing the sign out and padding the postive
number. | 372 » » // Achieve this by writing the sign out and padding the positive
number. |
373 if f.zero && f.widPresent && f.wid > len(slice) { | 373 if f.zero && f.widPresent && f.wid > len(slice) { |
374 f.buf.WriteByte(slice[1]) | 374 f.buf.WriteByte(slice[1]) |
375 f.wid-- | 375 f.wid-- |
376 f.pad(slice[2:]) | 376 f.pad(slice[2:]) |
377 return | 377 return |
378 } | 378 } |
379 // We're set; drop the leading space. | 379 // We're set; drop the leading space. |
380 slice = slice[1:] | 380 slice = slice[1:] |
381 default: | 381 default: |
382 // There's no sign, but we might need one. | 382 // There's no sign, but we might need one. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 } | 486 } |
487 if i != 0 { | 487 if i != 0 { |
488 break | 488 break |
489 } | 489 } |
490 f.plus = true | 490 f.plus = true |
491 r = imag(v) | 491 r = imag(v) |
492 } | 492 } |
493 f.plus = oldPlus | 493 f.plus = oldPlus |
494 f.buf.Write(irparenBytes) | 494 f.buf.Write(irparenBytes) |
495 } | 495 } |
LEFT | RIGHT |