internal/number: add AppendDigit

the other ones may go eventually.

Change-Id: I6c34f6972c1a827eb4dc193c5be26bb686681e7f
Reviewed-on: https://go-review.googlesource.com/45492
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/number/number.go b/internal/number/number.go
index 34f4477..ea341c7 100644
--- a/internal/number/number.go
+++ b/internal/number/number.go
@@ -121,6 +121,15 @@
 	return int(n.system.digitSize)
 }
 
+// AppendDigit appends the UTF-8 sequence for n corresponding to the given digit
+// to dst and reports the number of bytes written. dst must be large enough to
+// hold the rune (can be up to utf8.UTFMax bytes).
+func (n Info) AppendDigit(dst []byte, digit byte) []byte {
+	dst = append(dst, n.system.zero[:n.system.digitSize]...)
+	dst[len(dst)-1] += digit
+	return dst
+}
+
 // Digit returns the digit for the numbering system for the corresponding ASCII
 // value. For example, ni.Digit('3') could return 'δΈ‰'. Note that the argument
 // is the rune constant '3', which equals 51, not the integer constant 3.
diff --git a/internal/number/number_test.go b/internal/number/number_test.go
index fc04887..3eb5339 100644
--- a/internal/number/number_test.go
+++ b/internal/number/number_test.go
@@ -5,6 +5,7 @@
 package number
 
 import (
+	"fmt"
 	"testing"
 
 	"golang.org/x/text/internal/testtext"
@@ -51,13 +52,22 @@
 		{"en-u-nu-roman", SymPlusSign, "+", '9'},
 	}
 	for _, tc := range testCases {
-		info := InfoFromTag(language.MustParse(tc.lang))
-		if got := info.Symbol(tc.sym); got != tc.wantSym {
-			t.Errorf("%s:%v:sym: got %q; want %q", tc.lang, tc.sym, got, tc.wantSym)
-		}
-		if got := info.Digit('9'); got != tc.wantNine {
-			t.Errorf("%s:%v:nine: got %q; want %q", tc.lang, tc.sym, got, tc.wantNine)
-		}
+		t.Run(fmt.Sprintf("%s:%v", tc.lang, tc.sym), func(t *testing.T) {
+			info := InfoFromTag(language.MustParse(tc.lang))
+			if got := info.Symbol(tc.sym); got != tc.wantSym {
+				t.Errorf("sym: got %q; want %q", got, tc.wantSym)
+			}
+			if got := info.Digit('9'); got != tc.wantNine {
+				t.Errorf("Digit(9): got %+q; want %+q", got, tc.wantNine)
+			}
+			var buf [4]byte
+			if got := string(buf[:info.WriteDigit(buf[:], '9')]); got != string(tc.wantNine) {
+				t.Errorf("WriteDigit(9): got %+q; want %+q", got, tc.wantNine)
+			}
+			if got := string(info.AppendDigit([]byte{}, 9)); got != string(tc.wantNine) {
+				t.Errorf("AppendDigit(9): got %+q; want %+q", got, tc.wantNine)
+			}
+		})
 	}
 }