]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: make QuoteRune etc. take a rune argument
authorRob Pike <r@golang.org>
Tue, 13 Dec 2011 19:13:23 +0000 (11:13 -0800)
committerRob Pike <r@golang.org>
Tue, 13 Dec 2011 19:13:23 +0000 (11:13 -0800)
Just an oversight it didn't already.
Fixes #2515.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5483064

src/pkg/fmt/format.go
src/pkg/strconv/quote.go
src/pkg/strconv/quote_test.go

index fbafa9d9ad99c15053cef2c80255bc50f163d4df..5f62c067f06a716bd075bf0f39464fb0ecd2c361 100644 (file)
@@ -331,9 +331,9 @@ func (f *fmt) fmt_q(s string) {
 func (f *fmt) fmt_qc(c int64) {
        var quoted string
        if f.plus {
-               quoted = strconv.QuoteRuneToASCII(int(c))
+               quoted = strconv.QuoteRuneToASCII(rune(c))
        } else {
-               quoted = strconv.QuoteRune(int(c))
+               quoted = strconv.QuoteRune(rune(c))
        }
        f.padString(quoted)
 }
index 30b384df8e3541a497cd6b10c93fd2a8b48478cb..edba62954be4e03bc6e2a41f3e69b89d07529608 100644 (file)
@@ -116,30 +116,30 @@ func AppendQuoteToASCII(dst []byte, s string) []byte {
 // rune.  The returned string uses Go escape sequences (\t, \n, \xFF, \u0100)
 // for control characters and non-printable characters as defined by
 // unicode.IsPrint.
-func QuoteRune(rune int) string {
+func QuoteRune(r rune) string {
        // TODO: avoid the allocation here.
-       return quoteWith(string(rune), '\'', false)
+       return quoteWith(string(r), '\'', false)
 }
 
 // AppendQuoteRune appends a single-quoted Go character literal representing the rune,
 // as generated by QuoteRune, to dst and returns the extended buffer.
-func AppendQuoteRune(dst []byte, rune int) []byte {
-       return append(dst, QuoteRune(rune)...)
+func AppendQuoteRune(dst []byte, r rune) []byte {
+       return append(dst, QuoteRune(r)...)
 }
 
 // QuoteRuneToASCII returns a single-quoted Go character literal representing
 // the rune.  The returned string uses Go escape sequences (\t, \n, \xFF,
 // \u0100) for non-ASCII characters and non-printable characters as defined
 // by unicode.IsPrint.
-func QuoteRuneToASCII(rune int) string {
+func QuoteRuneToASCII(r rune) string {
        // TODO: avoid the allocation here.
-       return quoteWith(string(rune), '\'', true)
+       return quoteWith(string(r), '\'', true)
 }
 
 // AppendQuoteRune appends a single-quoted Go character literal representing the rune,
 // as generated by QuoteRuneToASCII, to dst and returns the extended buffer.
-func AppendQuoteRuneToASCII(dst []byte, rune int) []byte {
-       return append(dst, QuoteRuneToASCII(rune)...)
+func AppendQuoteRuneToASCII(dst []byte, r rune) []byte {
+       return append(dst, QuoteRuneToASCII(r)...)
 }
 
 // CanBackquote returns whether the string s would be
index e440797162b32e5cfd14b1a1a2f522118dfbacac..419943d83c751133b9d577227398605530c7f5ee 100644 (file)
@@ -47,7 +47,7 @@ func TestQuoteToASCII(t *testing.T) {
 }
 
 type quoteRuneTest struct {
-       in    int
+       in    rune
        out   string
        ascii string
 }