message: fix off-by-one bug
will add example that tests the integration.
Change-Id: Iaeeb2a460db994ba07e1fa283daba14587d27171
Reviewed-on: https://go-review.googlesource.com/58913
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
diff --git a/internal/catmsg/catmsg.go b/internal/catmsg/catmsg.go
index 74c039f..f8abf37 100644
--- a/internal/catmsg/catmsg.go
+++ b/internal/catmsg/catmsg.go
@@ -294,7 +294,7 @@
// d.Arg(1)
// d.Render(resultOfInvites)
// d.Render(" %[2]v to ")
-// d.Arg(1)
+// d.Arg(2)
// d.Render(resultOfTheir)
// d.Render(" party.")
// where the messages for "invites" and "their" both use a plural.Select
diff --git a/message/message.go b/message/message.go
index 9279123..187b26f 100644
--- a/message/message.go
+++ b/message/message.go
@@ -150,6 +150,7 @@
// Arg implements catmsg.Renderer.
func (p *printer) Arg(i int) interface{} { // TODO, also return "ok" bool
+ i--
if uint(i) < uint(len(p.args)) {
return p.args[i]
}
diff --git a/message/print.go b/message/print.go
index c0bef3f..7e4642b 100644
--- a/message/print.go
+++ b/message/print.go
@@ -1040,7 +1040,7 @@
p.fmt.plusV = p.fmt.plus
p.fmt.plus = false
}
- p.printArg(p.Arg(p.argNum), rune(c))
+ p.printArg(p.Arg(p.argNum+1), rune(c))
p.argNum++
i++
continue formatLoop