FAQ
Reviewers: golang-dev1,

Message:
Hello [email protected],

I'd like you to review this change to
https://code.google.com/p/go/


Description:
fmt: fix documentation glitch in index expressions in Printf
Also clean up the code a bit.

Please review this at https://codereview.appspot.com/9761043/

Affected files:
    M src/pkg/fmt/doc.go
    M src/pkg/fmt/fmt_test.go
    M src/pkg/fmt/print.go


Index: src/pkg/fmt/doc.go
===================================================================
--- a/src/pkg/fmt/doc.go
+++ b/src/pkg/fmt/doc.go
@@ -124,9 +124,9 @@
    formatting verb to format successive arguments passed in the call.
    However, the notation [n] immediately before the verb indicates that the
    nth one-indexed argument is to be formatted instead. The same notation
- before a '*' for a width or precision selects the argument index holding
- the value. After processing a bracketed expression [n], arguments n+1,
- n+2, etc. will be processed unless otherwise directed.
+ before a '*' for a width or a '.*' for precision selects the argument
+ index holding the value. After processing a bracketed expression [n],
+ arguments n+1, n+2, etc. will be processed unless otherwise directed.

    For example,
     fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
Index: src/pkg/fmt/fmt_test.go
===================================================================
--- a/src/pkg/fmt/fmt_test.go
+++ b/src/pkg/fmt/fmt_test.go
@@ -553,6 +553,7 @@
    {"%6.2f", SE{12.0}, " 12.00"},
    {"%[3]*[2].*[1]f", SE{12.0, 2, 6}, " 12.00"},
    {"%[1]*[2].*[3]f", SE{6, 2, 12.0}, " 12.00"},
+ {"%[2].*[3]f", SE{6, 3, 12.0}, "12.000"},
    // An actual use! Print the same arguments twice.
    {"%d %d %d %#[1]o %#o %#o", SE{11, 12, 13}, "11 12 13 013 014 015"},

Index: src/pkg/fmt/print.go
===================================================================
--- a/src/pkg/fmt/print.go
+++ b/src/pkg/fmt/print.go
@@ -1021,11 +1021,11 @@
   }

   // intFromArg gets the argNumth element of a. On return, isInt reports
whether the argument has type int.
-func intFromArg(a []interface{}, end, i, argNum int) (num int, isInt bool,
newi, newArgNum int) {
- newi, newArgNum = end, argNum
- if i < end && argNum < len(a) {
+func intFromArg(a []interface{}, argNum int) (num int, isInt bool,
newArgNum int) {
+ newArgNum = argNum
+ if argNum < len(a) {
     num, isInt = a[argNum].(int)
- newi, newArgNum = i+1, argNum+1
+ newArgNum = argNum + 1
    }
    return
   }
@@ -1112,7 +1112,8 @@

     // Do we have width?
     if i < end && format[i] == '*' {
- p.fmt.wid, p.fmt.widPresent, i, argNum = intFromArg(a, end, i, argNum)
+ i++
+ p.fmt.wid, p.fmt.widPresent, argNum = intFromArg(a, argNum)
      if !p.fmt.widPresent {
       p.buf.Write(badWidthBytes)
      }
@@ -1123,14 +1124,16 @@

     // Do we have precision?
     if i+1 < end && format[i] == '.' {
- if format[i+1] == '*' {
- p.fmt.prec, p.fmt.precPresent, i, argNum = intFromArg(a, end, i+1,
argNum)
+ i++
+ if format[i] == '*' {
+ i++
+ p.fmt.prec, p.fmt.precPresent, argNum = intFromArg(a, argNum)
       if !p.fmt.precPresent {
        p.buf.Write(badPrecBytes)
       }
       argNum, i = p.argNumber(argNum, format, i, len(a)) // We consumed [];
another can follow here.
      } else {
- p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i+1, end)
+ p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i, end)
       if !p.fmt.precPresent {
        p.fmt.prec = 0
        p.fmt.precPresent = true


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rob Pike at May 25, 2013 at 1:28 am
    Ignore this for now please. I am still thinking.
    On Friday, May 24, 2013, wrote:

    Reviewers: golang-dev1,

    Message:
    Hello [email protected],

    I'd like you to review this change to
    https://code.google.com/p/go/


    Description:
    fmt: fix documentation glitch in index expressions in Printf
    Also clean up the code a bit.

    Please review this at https://codereview.appspot.**com/9761043/<https://codereview.appspot.com/9761043/>

    Affected files:
    M src/pkg/fmt/doc.go
    M src/pkg/fmt/fmt_test.go
    M src/pkg/fmt/print.go


    Index: src/pkg/fmt/doc.go
    ==============================**==============================**=======
    --- a/src/pkg/fmt/doc.go
    +++ b/src/pkg/fmt/doc.go
    @@ -124,9 +124,9 @@
    formatting verb to format successive arguments passed in the call.
    However, the notation [n] immediately before the verb indicates
    that the
    nth one-indexed argument is to be formatted instead. The same
    notation
    - before a '*' for a width or precision selects the argument index
    holding
    - the value. After processing a bracketed expression [n], arguments
    n+1,
    - n+2, etc. will be processed unless otherwise directed.
    + before a '*' for a width or a '.*' for precision selects the
    argument
    + index holding the value. After processing a bracketed expression
    [n],
    + arguments n+1, n+2, etc. will be processed unless otherwise
    directed.

    For example,
    fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
    Index: src/pkg/fmt/fmt_test.go
    ==============================**==============================**=======
    --- a/src/pkg/fmt/fmt_test.go
    +++ b/src/pkg/fmt/fmt_test.go
    @@ -553,6 +553,7 @@
    {"%6.2f", SE{12.0}, " 12.00"},
    {"%[3]*[2].*[1]f", SE{12.0, 2, 6}, " 12.00"},
    {"%[1]*[2].*[3]f", SE{6, 2, 12.0}, " 12.00"},
    + {"%[2].*[3]f", SE{6, 3, 12.0}, "12.000"},
    // An actual use! Print the same arguments twice.
    {"%d %d %d %#[1]o %#o %#o", SE{11, 12, 13}, "11 12 13 013 014
    015"},

    Index: src/pkg/fmt/print.go
    ==============================**==============================**=======
    --- a/src/pkg/fmt/print.go
    +++ b/src/pkg/fmt/print.go
    @@ -1021,11 +1021,11 @@
    }

    // intFromArg gets the argNumth element of a. On return, isInt reports
    whether the argument has type int.
    -func intFromArg(a []interface{}, end, i, argNum int) (num int, isInt
    bool, newi, newArgNum int) {
    - newi, newArgNum = end, argNum
    - if i < end && argNum < len(a) {
    +func intFromArg(a []interface{}, argNum int) (num int, isInt bool,
    newArgNum int) {
    + newArgNum = argNum
    + if argNum < len(a) {
    num, isInt = a[argNum].(int)
    - newi, newArgNum = i+1, argNum+1
    + newArgNum = argNum + 1
    }
    return
    }
    @@ -1112,7 +1112,8 @@

    // Do we have width?
    if i < end && format[i] == '*' {
    - p.fmt.wid, p.fmt.widPresent, i, argNum =
    intFromArg(a, end, i, argNum)
    + i++
    + p.fmt.wid, p.fmt.widPresent, argNum =
    intFromArg(a, argNum)
    if !p.fmt.widPresent {
    p.buf.Write(badWidthBytes)
    }
    @@ -1123,14 +1124,16 @@

    // Do we have precision?
    if i+1 < end && format[i] == '.' {
    - if format[i+1] == '*' {
    - p.fmt.prec, p.fmt.precPresent, i, argNum =
    intFromArg(a, end, i+1, argNum)
    + i++
    + if format[i] == '*' {
    + i++
    + p.fmt.prec, p.fmt.precPresent, argNum =
    intFromArg(a, argNum)
    if !p.fmt.precPresent {
    p.buf.Write(badPrecBytes)
    }
    argNum, i = p.argNumber(argNum, format, i,
    len(a)) // We consumed []; another can follow here.
    } else {
    - p.fmt.prec, p.fmt.precPresent, i =
    parsenum(format, i+1, end)
    + p.fmt.prec, p.fmt.precPresent, i =
    parsenum(format, i, end)
    if !p.fmt.precPresent {
    p.fmt.prec = 0
    p.fmt.precPresent = true

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • R at May 25, 2013 at 2:46 am
    *** Abandoned ***

    https://codereview.appspot.com/9761043/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedMay 24, '13 at 11:40p
activeMay 25, '13 at 2:46a
posts3
users1
websitegolang.org

1 user in discussion

R: 3 posts

People

Translate

site design / logo © 2023 Grokbase