Commit 9750adbb authored by Russ Cox's avatar Russ Cox

strings: delete Runes, Bytes

gofmt -w -r 'strings.Bytes(a) -> []byte(a)' src/cmd src/pkg test/bench
gofmt -w -r 'strings.Runes(a) -> []int(a)' src/cmd src/pkg test/bench
delete unused imports

R=r
CC=golang-dev
https://golang.org/cl/224062
parent dfaa6eaa
...@@ -724,7 +724,7 @@ func (c *typeConv) Opaque(n int64) ast.Expr { ...@@ -724,7 +724,7 @@ func (c *typeConv) Opaque(n int64) ast.Expr {
func (c *typeConv) intExpr(n int64) ast.Expr { func (c *typeConv) intExpr(n int64) ast.Expr {
return &ast.BasicLit{ return &ast.BasicLit{
Kind: token.INT, Kind: token.INT,
Value: strings.Bytes(strconv.Itoa64(n)), Value: []byte(strconv.Itoa64(n)),
} }
} }
...@@ -755,7 +755,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s ...@@ -755,7 +755,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s
used[f.Name] = true used[f.Name] = true
} }
for cid, goid := range ident { for cid, goid := range ident {
if token.Lookup(strings.Bytes(goid)).IsKeyword() { if token.Lookup([]byte(goid)).IsKeyword() {
// Avoid keyword // Avoid keyword
goid = "_" + goid goid = "_" + goid
......
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"strings"
) )
...@@ -29,8 +28,8 @@ func usage() { ...@@ -29,8 +28,8 @@ func usage() {
// Markers around EBNF sections in .html files // Markers around EBNF sections in .html files
var ( var (
open = strings.Bytes(`<pre class="ebnf">`) open = []byte(`<pre class="ebnf">`)
close = strings.Bytes(`</pre>`) close = []byte(`</pre>`)
) )
......
...@@ -152,7 +152,7 @@ func pkgName(filename string) string { ...@@ -152,7 +152,7 @@ func pkgName(filename string) string {
func htmlEscape(s string) string { func htmlEscape(s string) string {
var buf bytes.Buffer var buf bytes.Buffer
template.HTMLEscape(&buf, strings.Bytes(s)) template.HTMLEscape(&buf, []byte(s))
return buf.String() return buf.String()
} }
...@@ -476,7 +476,7 @@ func (s *Styler) BasicLit(x *ast.BasicLit) (text []byte, tag printer.HTMLTag) { ...@@ -476,7 +476,7 @@ func (s *Styler) BasicLit(x *ast.BasicLit) (text []byte, tag printer.HTMLTag) {
func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) { func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
text = strings.Bytes(id.Name()) text = []byte(id.Name())
if s.highlight == id.Name() { if s.highlight == id.Name() {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"} tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
} }
...@@ -485,7 +485,7 @@ func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) { ...@@ -485,7 +485,7 @@ func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) { func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) {
text = strings.Bytes(tok.String()) text = []byte(tok.String())
return return
} }
...@@ -493,7 +493,7 @@ func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) { ...@@ -493,7 +493,7 @@ func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Tab conversion // Tab conversion
var spaces = strings.Bytes(" ") // 16 spaces seems like a good number var spaces = []byte(" ") // 16 spaces seems like a good number
const ( const (
indenting = iota indenting = iota
...@@ -595,7 +595,7 @@ func writeAny(w io.Writer, x interface{}, html bool) { ...@@ -595,7 +595,7 @@ func writeAny(w io.Writer, x interface{}, html bool) {
case []byte: case []byte:
writeText(w, v, html) writeText(w, v, html)
case string: case string:
writeText(w, strings.Bytes(v), html) writeText(w, []byte(v), html)
case ast.Decl, ast.Expr, ast.Stmt, *ast.File: case ast.Decl, ast.Expr, ast.Stmt, *ast.File:
writeNode(w, x, html, &defaultStyler) writeNode(w, x, html, &defaultStyler)
default: default:
...@@ -674,13 +674,13 @@ func urlFmt(w io.Writer, x interface{}, format string) { ...@@ -674,13 +674,13 @@ func urlFmt(w io.Writer, x interface{}, format string) {
if strings.HasPrefix(relpath, "src/pkg/") { if strings.HasPrefix(relpath, "src/pkg/") {
relpath = relpath[len("src/pkg/"):] relpath = relpath[len("src/pkg/"):]
} }
template.HTMLEscape(w, strings.Bytes(pkgHandler.pattern+relpath)) template.HTMLEscape(w, []byte(pkgHandler.pattern+relpath))
case "url-src": case "url-src":
template.HTMLEscape(w, strings.Bytes("/"+relpath)) template.HTMLEscape(w, []byte("/"+relpath))
case "url-pos": case "url-pos":
// line id's in html-printed source are of the // line id's in html-printed source are of the
// form "L%d" where %d stands for the line number // form "L%d" where %d stands for the line number
template.HTMLEscape(w, strings.Bytes("/"+relpath)) template.HTMLEscape(w, []byte("/"+relpath))
fmt.Fprintf(w, "#L%d", line) fmt.Fprintf(w, "#L%d", line)
} }
} }
...@@ -742,7 +742,7 @@ func paddingFmt(w io.Writer, x interface{}, format string) { ...@@ -742,7 +742,7 @@ func paddingFmt(w io.Writer, x interface{}, format string) {
// Template formatter for "time" format. // Template formatter for "time" format.
func timeFmt(w io.Writer, x interface{}, format string) { func timeFmt(w io.Writer, x interface{}, format string) {
// note: os.Dir.Mtime_ns is in uint64 in ns! // note: os.Dir.Mtime_ns is in uint64 in ns!
template.HTMLEscape(w, strings.Bytes(time.SecondsToLocalTime(int64(x.(uint64)/1e9)).String())) template.HTMLEscape(w, []byte(time.SecondsToLocalTime(int64(x.(uint64)/1e9)).String()))
} }
...@@ -757,7 +757,7 @@ func dirslashFmt(w io.Writer, x interface{}, format string) { ...@@ -757,7 +757,7 @@ func dirslashFmt(w io.Writer, x interface{}, format string) {
// Template formatter for "localname" format. // Template formatter for "localname" format.
func localnameFmt(w io.Writer, x interface{}, format string) { func localnameFmt(w io.Writer, x interface{}, format string) {
_, localname := pathutil.Split(x.(string)) _, localname := pathutil.Split(x.(string))
template.HTMLEscape(w, strings.Bytes(localname)) template.HTMLEscape(w, []byte(localname))
} }
...@@ -852,8 +852,8 @@ func serveText(c *http.Conn, text []byte) { ...@@ -852,8 +852,8 @@ func serveText(c *http.Conn, text []byte) {
// Files // Files
var ( var (
tagBegin = strings.Bytes("<!--") tagBegin = []byte("<!--")
tagEnd = strings.Bytes("-->") tagEnd = []byte("-->")
) )
// commentText returns the text of the first HTML comment in src. // commentText returns the text of the first HTML comment in src.
...@@ -878,7 +878,7 @@ func serveHTMLDoc(c *http.Conn, r *http.Request, abspath, relpath string) { ...@@ -878,7 +878,7 @@ func serveHTMLDoc(c *http.Conn, r *http.Request, abspath, relpath string) {
// if it begins with "<!DOCTYPE " assume it is standalone // if it begins with "<!DOCTYPE " assume it is standalone
// html that doesn't need the template wrapping. // html that doesn't need the template wrapping.
if bytes.HasPrefix(src, strings.Bytes("<!DOCTYPE ")) { if bytes.HasPrefix(src, []byte("<!DOCTYPE ")) {
c.Write(src) c.Write(src)
return return
} }
......
...@@ -696,7 +696,7 @@ func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) { ...@@ -696,7 +696,7 @@ func (x *Index) LookupWord(w string) (match *LookupResult, alt *AltWords) {
func isIdentifier(s string) bool { func isIdentifier(s string) bool {
var S scanner.Scanner var S scanner.Scanner
S.Init("", strings.Bytes(s), nil, 0) S.Init("", []byte(s), nil, 0)
if _, tok, _ := S.Scan(); tok == token.IDENT { if _, tok, _ := S.Scan(); tok == token.IDENT {
_, tok, _ := S.Scan() _, tok, _ := S.Scan()
return tok == token.EOF return tok == token.EOF
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"go/ast" "go/ast"
"go/printer" "go/printer"
"fmt" "fmt"
"strings"
) )
...@@ -36,7 +35,7 @@ func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HTMLTag) { ...@@ -36,7 +35,7 @@ func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HTMLTag) {
func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) { func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
text = strings.Bytes(id.Name()) text = []byte(id.Name())
if s.highlight == id { if s.highlight == id {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"} tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
} }
......
...@@ -16,7 +16,6 @@ import ( ...@@ -16,7 +16,6 @@ import (
"go/scanner" "go/scanner"
"go/token" "go/token"
"io" "io"
"strings"
) )
...@@ -166,8 +165,8 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) { ...@@ -166,8 +165,8 @@ func (p *ebnfParser) parse(out io.Writer, src []byte) {
// Markers around EBNF sections // Markers around EBNF sections
var ( var (
openTag = strings.Bytes(`<pre class="ebnf">`) openTag = []byte(`<pre class="ebnf">`)
closeTag = strings.Bytes(`</pre>`) closeTag = []byte(`</pre>`)
) )
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"io" "io"
"os" "os"
"reflect" "reflect"
"strings"
"testing" "testing"
) )
...@@ -161,7 +160,7 @@ func TestPartialRead(t *testing.T) { ...@@ -161,7 +160,7 @@ func TestPartialRead(t *testing.T) {
if _, err := io.ReadFull(tr, buf); err != nil { if _, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
if expected := strings.Bytes("Kilt"); !bytes.Equal(buf, expected) { if expected := []byte("Kilt"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected) t.Errorf("Contents = %v, want %v", buf, expected)
} }
...@@ -174,7 +173,7 @@ func TestPartialRead(t *testing.T) { ...@@ -174,7 +173,7 @@ func TestPartialRead(t *testing.T) {
if _, err := io.ReadFull(tr, buf); err != nil { if _, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
if expected := strings.Bytes("Google"); !bytes.Equal(buf, expected) { if expected := []byte("Google"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected) t.Errorf("Contents = %v, want %v", buf, expected)
} }
} }
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"io" "io"
"os" "os"
"strconv" "strconv"
"strings"
) )
var ( var (
...@@ -72,7 +71,7 @@ func (tw *Writer) cString(b []byte, s string) { ...@@ -72,7 +71,7 @@ func (tw *Writer) cString(b []byte, s string) {
} }
return return
} }
for i, ch := range strings.Bytes(s) { for i, ch := range []byte(s) {
b[i] = ch b[i] = ch
} }
if len(s) < len(b) { if len(s) < len(b) {
...@@ -128,25 +127,25 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error { ...@@ -128,25 +127,25 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
s := slicer(header) s := slicer(header)
// TODO(dsymonds): handle names longer than 100 chars // TODO(dsymonds): handle names longer than 100 chars
copy(s.next(100), strings.Bytes(hdr.Name)) copy(s.next(100), []byte(hdr.Name))
tw.octal(s.next(8), hdr.Mode) // 100:108 tw.octal(s.next(8), hdr.Mode) // 100:108
tw.numeric(s.next(8), hdr.Uid) // 108:116 tw.numeric(s.next(8), hdr.Uid) // 108:116
tw.numeric(s.next(8), hdr.Gid) // 116:124 tw.numeric(s.next(8), hdr.Gid) // 116:124
tw.numeric(s.next(12), hdr.Size) // 124:136 tw.numeric(s.next(12), hdr.Size) // 124:136
tw.numeric(s.next(12), hdr.Mtime) // 136:148 tw.numeric(s.next(12), hdr.Mtime) // 136:148
s.next(8) // chksum (148:156) s.next(8) // chksum (148:156)
s.next(1)[0] = hdr.Typeflag // 156:157 s.next(1)[0] = hdr.Typeflag // 156:157
s.next(100) // linkname (157:257) s.next(100) // linkname (157:257)
copy(s.next(8), strings.Bytes("ustar\x0000")) // 257:265 copy(s.next(8), []byte("ustar\x0000")) // 257:265
tw.cString(s.next(32), hdr.Uname) // 265:297 tw.cString(s.next(32), hdr.Uname) // 265:297
tw.cString(s.next(32), hdr.Gname) // 297:329 tw.cString(s.next(32), hdr.Gname) // 297:329
tw.numeric(s.next(8), hdr.Devmajor) // 329:337 tw.numeric(s.next(8), hdr.Devmajor) // 329:337
tw.numeric(s.next(8), hdr.Devminor) // 337:345 tw.numeric(s.next(8), hdr.Devminor) // 337:345
// Use the GNU magic instead of POSIX magic if we used any GNU extensions. // Use the GNU magic instead of POSIX magic if we used any GNU extensions.
if tw.usedBinary { if tw.usedBinary {
copy(header[257:265], strings.Bytes("ustar \x00")) copy(header[257:265], []byte("ustar \x00"))
} }
// The chksum field is terminated by a NUL and a space. // The chksum field is terminated by a NUL and a space.
......
...@@ -7,7 +7,6 @@ package asn1 ...@@ -7,7 +7,6 @@ package asn1
import ( import (
"bytes" "bytes"
"reflect" "reflect"
"strings"
"testing" "testing"
"time" "time"
) )
...@@ -165,7 +164,7 @@ var timeTestData = []timeTest{ ...@@ -165,7 +164,7 @@ var timeTestData = []timeTest{
func TestTime(t *testing.T) { func TestTime(t *testing.T) {
for i, test := range timeTestData { for i, test := range timeTestData {
ret, err := parseUTCTime(strings.Bytes(test.in)) ret, err := parseUTCTime([]byte(test.in))
if (err == nil) != test.ok { if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok) t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
} }
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"io" "io"
"os" "os"
"reflect" "reflect"
"strings"
"time" "time"
) )
...@@ -209,7 +208,7 @@ func marshalObjectIdentifier(out *forkableWriter, oid []int) (err os.Error) { ...@@ -209,7 +208,7 @@ func marshalObjectIdentifier(out *forkableWriter, oid []int) (err os.Error) {
} }
func marshalPrintableString(out *forkableWriter, s string) (err os.Error) { func marshalPrintableString(out *forkableWriter, s string) (err os.Error) {
b := strings.Bytes(s) b := []byte(s)
for _, c := range b { for _, c := range b {
if !isPrintable(c) { if !isPrintable(c) {
return StructuralError{"PrintableString contains invalid character"} return StructuralError{"PrintableString contains invalid character"}
...@@ -221,7 +220,7 @@ func marshalPrintableString(out *forkableWriter, s string) (err os.Error) { ...@@ -221,7 +220,7 @@ func marshalPrintableString(out *forkableWriter, s string) (err os.Error) {
} }
func marshalIA5String(out *forkableWriter, s string) (err os.Error) { func marshalIA5String(out *forkableWriter, s string) (err os.Error) {
b := strings.Bytes(s) b := []byte(s)
for _, c := range b { for _, c := range b {
if c > 127 { if c > 127 {
return StructuralError{"IA5String contains invalid character"} return StructuralError{"IA5String contains invalid character"}
......
...@@ -296,7 +296,7 @@ var errorWriterTests = []errorWriterTest{ ...@@ -296,7 +296,7 @@ var errorWriterTests = []errorWriterTest{
func TestWriteErrors(t *testing.T) { func TestWriteErrors(t *testing.T) {
for _, w := range errorWriterTests { for _, w := range errorWriterTests {
buf := NewWriter(w) buf := NewWriter(w)
_, e := buf.Write(strings.Bytes("hello world")) _, e := buf.Write([]byte("hello world"))
if e != nil { if e != nil {
t.Errorf("Write hello to %v: %v", w, e) t.Errorf("Write hello to %v: %v", w, e)
continue continue
......
...@@ -6,7 +6,6 @@ package bytes_test ...@@ -6,7 +6,6 @@ package bytes_test
import ( import (
. "bytes" . "bytes"
"strings"
"testing" "testing"
"unicode" "unicode"
) )
...@@ -60,8 +59,8 @@ var comparetests = []BinOpTest{ ...@@ -60,8 +59,8 @@ var comparetests = []BinOpTest{
func TestCompare(t *testing.T) { func TestCompare(t *testing.T) {
for _, tt := range comparetests { for _, tt := range comparetests {
a := strings.Bytes(tt.a) a := []byte(tt.a)
b := strings.Bytes(tt.b) b := []byte(tt.b)
cmp := Compare(a, b) cmp := Compare(a, b)
eql := Equal(a, b) eql := Equal(a, b)
if cmp != tt.i { if cmp != tt.i {
...@@ -94,8 +93,8 @@ var indextests = []BinOpTest{ ...@@ -94,8 +93,8 @@ var indextests = []BinOpTest{
func TestIndex(t *testing.T) { func TestIndex(t *testing.T) {
for _, tt := range indextests { for _, tt := range indextests {
a := strings.Bytes(tt.a) a := []byte(tt.a)
b := strings.Bytes(tt.b) b := []byte(tt.b)
pos := Index(a, b) pos := Index(a, b)
if pos != tt.i { if pos != tt.i {
t.Errorf(`Index(%q, %q) = %v`, tt.a, tt.b, pos) t.Errorf(`Index(%q, %q) = %v`, tt.a, tt.b, pos)
...@@ -108,7 +107,7 @@ func TestIndexByte(t *testing.T) { ...@@ -108,7 +107,7 @@ func TestIndexByte(t *testing.T) {
if len(tt.b) != 1 { if len(tt.b) != 1 {
continue continue
} }
a := strings.Bytes(tt.a) a := []byte(tt.a)
b := tt.b[0] b := tt.b[0]
pos := IndexByte(a, b) pos := IndexByte(a, b)
if pos != tt.i { if pos != tt.i {
...@@ -171,7 +170,7 @@ var explodetests = []ExplodeTest{ ...@@ -171,7 +170,7 @@ var explodetests = []ExplodeTest{
func TestExplode(t *testing.T) { func TestExplode(t *testing.T) {
for _, tt := range explodetests { for _, tt := range explodetests {
a := Split(strings.Bytes(tt.s), nil, tt.n) a := Split([]byte(tt.s), nil, tt.n)
result := arrayOfString(a) result := arrayOfString(a)
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a) t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a)
...@@ -210,13 +209,13 @@ var splittests = []SplitTest{ ...@@ -210,13 +209,13 @@ var splittests = []SplitTest{
func TestSplit(t *testing.T) { func TestSplit(t *testing.T) {
for _, tt := range splittests { for _, tt := range splittests {
a := Split(strings.Bytes(tt.s), strings.Bytes(tt.sep), tt.n) a := Split([]byte(tt.s), []byte(tt.sep), tt.n)
result := arrayOfString(a) result := arrayOfString(a)
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a) t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
continue continue
} }
s := Join(a, strings.Bytes(tt.sep)) s := Join(a, []byte(tt.sep))
if string(s) != tt.s { if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s) t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
} }
...@@ -241,7 +240,7 @@ var splitaftertests = []SplitTest{ ...@@ -241,7 +240,7 @@ var splitaftertests = []SplitTest{
func TestSplitAfter(t *testing.T) { func TestSplitAfter(t *testing.T) {
for _, tt := range splitaftertests { for _, tt := range splitaftertests {
a := SplitAfter(strings.Bytes(tt.s), strings.Bytes(tt.sep), tt.n) a := SplitAfter([]byte(tt.s), []byte(tt.sep), tt.n)
result := arrayOfString(a) result := arrayOfString(a)
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a) t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
...@@ -275,7 +274,7 @@ var fieldstests = []FieldsTest{ ...@@ -275,7 +274,7 @@ var fieldstests = []FieldsTest{
func TestFields(t *testing.T) { func TestFields(t *testing.T) {
for _, tt := range fieldstests { for _, tt := range fieldstests {
a := Fields(strings.Bytes(tt.s)) a := Fields([]byte(tt.s))
result := arrayOfString(a) result := arrayOfString(a)
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a) t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
...@@ -434,7 +433,7 @@ func TestAdd(t *testing.T) { ...@@ -434,7 +433,7 @@ func TestAdd(t *testing.T) {
for i := 0; i < len(test.s); i++ { for i := 0; i < len(test.s); i++ {
b[i] = test.s[i] b[i] = test.s[i]
} }
b = Add(b, strings.Bytes(test.t)) b = Add(b, []byte(test.t))
if string(b) != test.s+test.t { if string(b) != test.s+test.t {
t.Errorf("Add(%q,%q) = %q", test.s, test.t, string(b)) t.Errorf("Add(%q,%q) = %q", test.s, test.t, string(b))
} }
...@@ -474,8 +473,8 @@ var RepeatTests = []RepeatTest{ ...@@ -474,8 +473,8 @@ var RepeatTests = []RepeatTest{
func TestRepeat(t *testing.T) { func TestRepeat(t *testing.T) {
for _, tt := range RepeatTests { for _, tt := range RepeatTests {
tin := strings.Bytes(tt.in) tin := []byte(tt.in)
tout := strings.Bytes(tt.out) tout := []byte(tt.out)
a := Repeat(tin, tt.count) a := Repeat(tin, tt.count)
if !Equal(a, tout) { if !Equal(a, tout) {
t.Errorf("Repeat(%q, %d) = %q; want %q", tin, tt.count, a, tout) t.Errorf("Repeat(%q, %d) = %q; want %q", tin, tt.count, a, tout)
...@@ -514,7 +513,7 @@ var RunesTests = []RunesTest{ ...@@ -514,7 +513,7 @@ var RunesTests = []RunesTest{
func TestRunes(t *testing.T) { func TestRunes(t *testing.T) {
for _, tt := range RunesTests { for _, tt := range RunesTests {
tin := strings.Bytes(tt.in) tin := []byte(tt.in)
a := Runes(tin) a := Runes(tin)
if !runesEqual(a, tt.out) { if !runesEqual(a, tt.out) {
t.Errorf("Runes(%q) = %v; want %v", tin, a, tt.out) t.Errorf("Runes(%q) = %v; want %v", tin, a, tt.out)
......
...@@ -7,7 +7,6 @@ package gzip ...@@ -7,7 +7,6 @@ package gzip
import ( import (
"io" "io"
"io/ioutil" "io/ioutil"
"strings"
"testing" "testing"
) )
...@@ -53,10 +52,10 @@ func TestWriter(t *testing.T) { ...@@ -53,10 +52,10 @@ func TestWriter(t *testing.T) {
pipe(t, pipe(t,
func(deflater *Deflater) { func(deflater *Deflater) {
deflater.Comment = "comment" deflater.Comment = "comment"
deflater.Extra = strings.Bytes("extra") deflater.Extra = []byte("extra")
deflater.Mtime = 1e8 deflater.Mtime = 1e8
deflater.Name = "name" deflater.Name = "name"
_, err := deflater.Write(strings.Bytes("payload")) _, err := deflater.Write([]byte("payload"))
if err != nil { if err != nil {
t.Fatalf("%v", err) t.Fatalf("%v", err)
} }
......
...@@ -7,7 +7,6 @@ package hmac ...@@ -7,7 +7,6 @@ package hmac
import ( import (
"hash" "hash"
"fmt" "fmt"
"strings"
"testing" "testing"
) )
...@@ -33,7 +32,7 @@ var hmacTests = []hmacTest{ ...@@ -33,7 +32,7 @@ var hmacTests = []hmacTest{
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
}, },
strings.Bytes("Sample #1"), []byte("Sample #1"),
"4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a", "4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a",
}, },
hmacTest{ hmacTest{
...@@ -43,7 +42,7 @@ var hmacTests = []hmacTest{ ...@@ -43,7 +42,7 @@ var hmacTests = []hmacTest{
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x40, 0x41, 0x42, 0x43,
}, },
strings.Bytes("Sample #2"), []byte("Sample #2"),
"0922d3405faa3d194f82a45830737d5cc6c75d24", "0922d3405faa3d194f82a45830737d5cc6c75d24",
}, },
hmacTest{ hmacTest{
...@@ -63,15 +62,15 @@ var hmacTests = []hmacTest{ ...@@ -63,15 +62,15 @@ var hmacTests = []hmacTest{
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb0, 0xb1, 0xb2, 0xb3,
}, },
strings.Bytes("Sample #3"), []byte("Sample #3"),
"bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa", "bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa",
}, },
// Test from Plan 9. // Test from Plan 9.
hmacTest{ hmacTest{
NewMD5, NewMD5,
strings.Bytes("Jefe"), []byte("Jefe"),
strings.Bytes("what do ya want for nothing?"), []byte("what do ya want for nothing?"),
"750c783e6ab0b503eaa86e310a5db738", "750c783e6ab0b503eaa86e310a5db738",
}, },
} }
......
...@@ -12,14 +12,13 @@ import ( ...@@ -12,14 +12,13 @@ import (
"encoding/hex" "encoding/hex"
"os" "os"
"io" "io"
"strings"
"testing" "testing"
"testing/quick" "testing/quick"
) )
func decodeBase64(in string) []byte { func decodeBase64(in string) []byte {
out := make([]byte, base64.StdEncoding.DecodedLen(len(in))) out := make([]byte, base64.StdEncoding.DecodedLen(len(in)))
n, err := base64.StdEncoding.Decode(out, strings.Bytes(in)) n, err := base64.StdEncoding.Decode(out, []byte(in))
if err != nil { if err != nil {
return nil return nil
} }
...@@ -56,7 +55,7 @@ func TestDecryptPKCS1v15(t *testing.T) { ...@@ -56,7 +55,7 @@ func TestDecryptPKCS1v15(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("#%d error decrypting", i) t.Errorf("#%d error decrypting", i)
} }
want := strings.Bytes(test.out) want := []byte(test.out)
if bytes.Compare(out, want) != 0 { if bytes.Compare(out, want) != 0 {
t.Errorf("#%d got:%#v want:%#v", i, out, want) t.Errorf("#%d got:%#v want:%#v", i, out, want)
} }
...@@ -125,12 +124,12 @@ var decryptPKCS1v15SessionKeyTests = []DecryptPKCS1v15Test{ ...@@ -125,12 +124,12 @@ var decryptPKCS1v15SessionKeyTests = []DecryptPKCS1v15Test{
func TestEncryptPKCS1v15SessionKey(t *testing.T) { func TestEncryptPKCS1v15SessionKey(t *testing.T) {
for i, test := range decryptPKCS1v15SessionKeyTests { for i, test := range decryptPKCS1v15SessionKeyTests {
key := strings.Bytes("FAIL") key := []byte("FAIL")
err := DecryptPKCS1v15SessionKey(nil, rsaPrivateKey, decodeBase64(test.in), key) err := DecryptPKCS1v15SessionKey(nil, rsaPrivateKey, decodeBase64(test.in), key)
if err != nil { if err != nil {
t.Errorf("#%d error decrypting", i) t.Errorf("#%d error decrypting", i)
} }
want := strings.Bytes(test.out) want := []byte(test.out)
if bytes.Compare(key, want) != 0 { if bytes.Compare(key, want) != 0 {
t.Errorf("#%d got:%#v want:%#v", i, key, want) t.Errorf("#%d got:%#v want:%#v", i, key, want)
} }
...@@ -169,7 +168,7 @@ var signPKCS1v15Tests = []signPKCS1v15Test{ ...@@ -169,7 +168,7 @@ var signPKCS1v15Tests = []signPKCS1v15Test{
func TestSignPKCS1v15(t *testing.T) { func TestSignPKCS1v15(t *testing.T) {
for i, test := range signPKCS1v15Tests { for i, test := range signPKCS1v15Tests {
h := sha1.New() h := sha1.New()
h.Write(strings.Bytes(test.in)) h.Write([]byte(test.in))
digest := h.Sum() digest := h.Sum()
s, err := SignPKCS1v15(nil, rsaPrivateKey, HashSHA1, digest) s, err := SignPKCS1v15(nil, rsaPrivateKey, HashSHA1, digest)
...@@ -187,7 +186,7 @@ func TestSignPKCS1v15(t *testing.T) { ...@@ -187,7 +186,7 @@ func TestSignPKCS1v15(t *testing.T) {
func TestVerifyPKCS1v15(t *testing.T) { func TestVerifyPKCS1v15(t *testing.T) {
for i, test := range signPKCS1v15Tests { for i, test := range signPKCS1v15Tests {
h := sha1.New() h := sha1.New()
h.Write(strings.Bytes(test.in)) h.Write([]byte(test.in))
digest := h.Sum() digest := h.Sum()
sig, _ := hex.DecodeString(test.out) sig, _ := hex.DecodeString(test.out)
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package tls package tls
import "strings"
type clientHelloMsg struct { type clientHelloMsg struct {
raw []byte raw []byte
major, minor uint8 major, minor uint8
...@@ -100,7 +98,7 @@ func (m *clientHelloMsg) marshal() []byte { ...@@ -100,7 +98,7 @@ func (m *clientHelloMsg) marshal() []byte {
z[1] = 1 z[1] = 1
z[3] = byte(len(m.serverName) >> 8) z[3] = byte(len(m.serverName) >> 8)
z[4] = byte(len(m.serverName)) z[4] = byte(len(m.serverName))
copy(z[5:], strings.Bytes(m.serverName)) copy(z[5:], []byte(m.serverName))
z = z[l:] z = z[l:]
} }
...@@ -280,7 +278,7 @@ func (m *serverHelloMsg) marshal() []byte { ...@@ -280,7 +278,7 @@ func (m *serverHelloMsg) marshal() []byte {
l = 255 l = 255
} }
z[0] = byte(l) z[0] = byte(l)
copy(z[1:], strings.Bytes(v[0:l])) copy(z[1:], []byte(v[0:l]))
z = z[1+l:] z = z[1+l:]
} }
} }
...@@ -548,7 +546,7 @@ func (m *nextProtoMsg) marshal() []byte { ...@@ -548,7 +546,7 @@ func (m *nextProtoMsg) marshal() []byte {
y := x[4:] y := x[4:]
y[0] = byte(l) y[0] = byte(l)
copy(y[1:], strings.Bytes(m.proto[0:l])) copy(y[1:], []byte(m.proto[0:l]))
y = y[1+l:] y = y[1+l:]
y[0] = byte(padding) y[0] = byte(padding)
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"crypto/sha1" "crypto/sha1"
"hash" "hash"
"os" "os"
"strings"
) )
// Split a premaster secret in two as specified in RFC 4346, section 5. // Split a premaster secret in two as specified in RFC 4346, section 5.
...@@ -70,10 +69,10 @@ const ( ...@@ -70,10 +69,10 @@ const (
finishedVerifyLength = 12 // Length of verify_data in a Finished message. finishedVerifyLength = 12 // Length of verify_data in a Finished message.
) )
var masterSecretLabel = strings.Bytes("master secret") var masterSecretLabel = []byte("master secret")
var keyExpansionLabel = strings.Bytes("key expansion") var keyExpansionLabel = []byte("key expansion")
var clientFinishedLabel = strings.Bytes("client finished") var clientFinishedLabel = []byte("client finished")
var serverFinishedLabel = strings.Bytes("server finished") var serverFinishedLabel = []byte("server finished")
// keysFromPreMasterSecret generates the connection keys from the pre master // keysFromPreMasterSecret generates the connection keys from the pre master
// secret, given the lengths of the MAC and cipher keys, as defined in RFC // secret, given the lengths of the MAC and cipher keys, as defined in RFC
......
...@@ -735,7 +735,7 @@ func buildExtensions(template *Certificate) (ret []extension, err os.Error) { ...@@ -735,7 +735,7 @@ func buildExtensions(template *Certificate) (ret []extension, err os.Error) {
ret[n].Id = oidExtensionSubjectAltName ret[n].Id = oidExtensionSubjectAltName
rawValues := make([]asn1.RawValue, len(template.DNSNames)) rawValues := make([]asn1.RawValue, len(template.DNSNames))
for i, name := range template.DNSNames { for i, name := range template.DNSNames {
rawValues[i] = asn1.RawValue{Tag: 2, Class: 2, Bytes: strings.Bytes(name)} rawValues[i] = asn1.RawValue{Tag: 2, Class: 2, Bytes: []byte(name)}
} }
ret[n].Value, err = asn1.MarshalToMemory(rawValues) ret[n].Value, err = asn1.MarshalToMemory(rawValues)
if err != nil { if err != nil {
......
...@@ -11,13 +11,12 @@ import ( ...@@ -11,13 +11,12 @@ import (
"encoding/pem" "encoding/pem"
"os" "os"
"reflect" "reflect"
"strings"
"testing" "testing"
"time" "time"
) )
func TestParsePKCS1PrivateKey(t *testing.T) { func TestParsePKCS1PrivateKey(t *testing.T) {
block, _ := pem.Decode(strings.Bytes(pemPrivateKey)) block, _ := pem.Decode([]byte(pemPrivateKey))
priv, err := ParsePKCS1PrivateKey(block.Bytes) priv, err := ParsePKCS1PrivateKey(block.Bytes)
if err != nil { if err != nil {
t.Errorf("Failed to parse private key: %s", err) t.Errorf("Failed to parse private key: %s", err)
...@@ -151,7 +150,7 @@ func TestCreateSelfSignedCertificate(t *testing.T) { ...@@ -151,7 +150,7 @@ func TestCreateSelfSignedCertificate(t *testing.T) {
t.Errorf("failed to open /dev/urandom") t.Errorf("failed to open /dev/urandom")
} }
block, _ := pem.Decode(strings.Bytes(pemPrivateKey)) block, _ := pem.Decode([]byte(pemPrivateKey))
priv, err := ParsePKCS1PrivateKey(block.Bytes) priv, err := ParsePKCS1PrivateKey(block.Bytes)
if err != nil { if err != nil {
t.Errorf("Failed to parse private key: %s", err) t.Errorf("Failed to parse private key: %s", err)
......
...@@ -6,7 +6,6 @@ package ebnf ...@@ -6,7 +6,6 @@ package ebnf
import ( import (
"io/ioutil" "io/ioutil"
"strings"
"testing" "testing"
) )
...@@ -53,7 +52,7 @@ func check(t *testing.T, filename string, src []byte) { ...@@ -53,7 +52,7 @@ func check(t *testing.T, filename string, src []byte) {
func TestGrammars(t *testing.T) { func TestGrammars(t *testing.T) {
for _, src := range grammars { for _, src := range grammars {
check(t, "", strings.Bytes(src)) check(t, "", []byte(src))
} }
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"testing" "testing"
) )
...@@ -57,7 +56,7 @@ func strip85(s string) string { ...@@ -57,7 +56,7 @@ func strip85(s string) string {
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
buf := make([]byte, MaxEncodedLen(len(p.decoded))) buf := make([]byte, MaxEncodedLen(len(p.decoded)))
n := Encode(buf, strings.Bytes(p.decoded)) n := Encode(buf, []byte(p.decoded))
buf = buf[0:n] buf = buf[0:n]
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(string(buf)), strip85(p.encoded)) testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(string(buf)), strip85(p.encoded))
} }
...@@ -67,14 +66,14 @@ func TestEncoder(t *testing.T) { ...@@ -67,14 +66,14 @@ func TestEncoder(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(bb) encoder := NewEncoder(bb)
encoder.Write(strings.Bytes(p.decoded)) encoder.Write([]byte(p.decoded))
encoder.Close() encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(bb.String()), strip85(p.encoded)) testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(bb.String()), strip85(p.encoded))
} }
} }
func TestEncoderBuffering(t *testing.T) { func TestEncoderBuffering(t *testing.T) {
input := strings.Bytes(bigtest.decoded) input := []byte(bigtest.decoded)
for bs := 1; bs <= 12; bs++ { for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(bb) encoder := NewEncoder(bb)
...@@ -96,7 +95,7 @@ func TestEncoderBuffering(t *testing.T) { ...@@ -96,7 +95,7 @@ func TestEncoderBuffering(t *testing.T) {
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
dbuf := make([]byte, 4*len(p.encoded)) dbuf := make([]byte, 4*len(p.encoded))
ndst, nsrc, err := Decode(dbuf, strings.Bytes(p.encoded), true) ndst, nsrc, err := Decode(dbuf, []byte(p.encoded), true)
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil)) testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil))
testEqual(t, "Decode(%q) = nsrc %v, want %v", p.encoded, nsrc, len(p.encoded)) testEqual(t, "Decode(%q) = nsrc %v, want %v", p.encoded, nsrc, len(p.encoded))
testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded)) testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded))
...@@ -145,7 +144,7 @@ func TestDecodeCorrupt(t *testing.T) { ...@@ -145,7 +144,7 @@ func TestDecodeCorrupt(t *testing.T) {
for _, e := range examples { for _, e := range examples {
dbuf := make([]byte, 4*len(e.e)) dbuf := make([]byte, 4*len(e.e))
_, _, err := Decode(dbuf, strings.Bytes(e.e), true) _, _, err := Decode(dbuf, []byte(e.e), true)
switch err := err.(type) { switch err := err.(type) {
case CorruptInputError: case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p) testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"testing" "testing"
) )
...@@ -58,7 +57,7 @@ func testEqual(t *testing.T, msg string, args ...interface{}) bool { ...@@ -58,7 +57,7 @@ func testEqual(t *testing.T, msg string, args ...interface{}) bool {
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
buf := make([]byte, StdEncoding.EncodedLen(len(p.decoded))) buf := make([]byte, StdEncoding.EncodedLen(len(p.decoded)))
StdEncoding.Encode(buf, strings.Bytes(p.decoded)) StdEncoding.Encode(buf, []byte(p.decoded))
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(buf), p.encoded) testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(buf), p.encoded)
} }
} }
...@@ -67,14 +66,14 @@ func TestEncoder(t *testing.T) { ...@@ -67,14 +66,14 @@ func TestEncoder(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(StdEncoding, bb) encoder := NewEncoder(StdEncoding, bb)
encoder.Write(strings.Bytes(p.decoded)) encoder.Write([]byte(p.decoded))
encoder.Close() encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded) testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded)
} }
} }
func TestEncoderBuffering(t *testing.T) { func TestEncoderBuffering(t *testing.T) {
input := strings.Bytes(bigtest.decoded) input := []byte(bigtest.decoded)
for bs := 1; bs <= 12; bs++ { for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(StdEncoding, bb) encoder := NewEncoder(StdEncoding, bb)
...@@ -96,7 +95,7 @@ func TestEncoderBuffering(t *testing.T) { ...@@ -96,7 +95,7 @@ func TestEncoderBuffering(t *testing.T) {
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))) dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded)))
count, end, err := StdEncoding.decode(dbuf, strings.Bytes(p.encoded)) count, end, err := StdEncoding.decode(dbuf, []byte(p.encoded))
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil)) testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil))
testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded)) testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded))
if len(p.encoded) > 0 { if len(p.encoded) > 0 {
...@@ -153,7 +152,7 @@ func TestDecodeCorrupt(t *testing.T) { ...@@ -153,7 +152,7 @@ func TestDecodeCorrupt(t *testing.T) {
for _, e := range examples { for _, e := range examples {
dbuf := make([]byte, StdEncoding.DecodedLen(len(e.e))) dbuf := make([]byte, StdEncoding.DecodedLen(len(e.e)))
_, err := StdEncoding.Decode(dbuf, strings.Bytes(e.e)) _, err := StdEncoding.Decode(dbuf, []byte(e.e))
switch err := err.(type) { switch err := err.(type) {
case CorruptInputError: case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p) testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"strings"
"testing" "testing"
) )
...@@ -61,7 +60,7 @@ var gitBigtest = gitPairs[len(gitPairs)-1] ...@@ -61,7 +60,7 @@ var gitBigtest = gitPairs[len(gitPairs)-1]
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
for _, p := range gitPairs { for _, p := range gitPairs {
buf := make([]byte, EncodedLen(len(p.decoded))) buf := make([]byte, EncodedLen(len(p.decoded)))
n := Encode(buf, strings.Bytes(p.decoded)) n := Encode(buf, []byte(p.decoded))
if n != len(buf) { if n != len(buf) {
t.Errorf("EncodedLen does not agree with Encode") t.Errorf("EncodedLen does not agree with Encode")
} }
...@@ -74,14 +73,14 @@ func TestEncoder(t *testing.T) { ...@@ -74,14 +73,14 @@ func TestEncoder(t *testing.T) {
for _, p := range gitPairs { for _, p := range gitPairs {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(bb) encoder := NewEncoder(bb)
encoder.Write(strings.Bytes(p.decoded)) encoder.Write([]byte(p.decoded))
encoder.Close() encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded) testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded)
} }
} }
func TestEncoderBuffering(t *testing.T) { func TestEncoderBuffering(t *testing.T) {
input := strings.Bytes(gitBigtest.decoded) input := []byte(gitBigtest.decoded)
for bs := 1; bs <= 12; bs++ { for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{} bb := &bytes.Buffer{}
encoder := NewEncoder(bb) encoder := NewEncoder(bb)
...@@ -103,7 +102,7 @@ func TestEncoderBuffering(t *testing.T) { ...@@ -103,7 +102,7 @@ func TestEncoderBuffering(t *testing.T) {
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
for _, p := range gitPairs { for _, p := range gitPairs {
dbuf := make([]byte, 4*len(p.encoded)) dbuf := make([]byte, 4*len(p.encoded))
ndst, err := Decode(dbuf, strings.Bytes(p.encoded)) ndst, err := Decode(dbuf, []byte(p.encoded))
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil)) testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil))
testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded)) testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded))
testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:ndst]), p.decoded) testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:ndst]), p.decoded)
...@@ -151,7 +150,7 @@ func TestDecodeCorrupt(t *testing.T) { ...@@ -151,7 +150,7 @@ func TestDecodeCorrupt(t *testing.T) {
for _, e := range examples { for _, e := range examples {
dbuf := make([]byte, 2*len(e.e)) dbuf := make([]byte, 2*len(e.e))
_, err := Decode(dbuf, strings.Bytes(e.e)) _, err := Decode(dbuf, []byte(e.e))
switch err := err.(type) { switch err := err.(type) {
case CorruptInputError: case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p) testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
......
...@@ -8,7 +8,6 @@ package hex ...@@ -8,7 +8,6 @@ package hex
import ( import (
"os" "os"
"strconv" "strconv"
"strings"
) )
const hextable = "0123456789abcdef" const hextable = "0123456789abcdef"
...@@ -92,7 +91,7 @@ func EncodeToString(src []byte) string { ...@@ -92,7 +91,7 @@ func EncodeToString(src []byte) string {
// DecodeString returns the bytes represented by the hexadecimal string s. // DecodeString returns the bytes represented by the hexadecimal string s.
func DecodeString(s string) ([]byte, os.Error) { func DecodeString(s string) ([]byte, os.Error) {
src := strings.Bytes(s) src := []byte(s)
dst := make([]byte, DecodedLen(len(src))) dst := make([]byte, DecodedLen(len(src)))
_, err := Decode(dst, src) _, err := Decode(dst, src)
if err != nil { if err != nil {
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"encoding/base64" "encoding/base64"
"io" "io"
"os" "os"
"strings"
) )
// A Block represents a PEM encoded structure. // A Block represents a PEM encoded structure.
...@@ -65,9 +64,9 @@ func removeWhitespace(data []byte) []byte { ...@@ -65,9 +64,9 @@ func removeWhitespace(data []byte) []byte {
return result[0:n] return result[0:n]
} }
var pemStart = strings.Bytes("\n-----BEGIN ") var pemStart = []byte("\n-----BEGIN ")
var pemEnd = strings.Bytes("\n-----END ") var pemEnd = []byte("\n-----END ")
var pemEndOfLine = strings.Bytes("-----") var pemEndOfLine = []byte("-----")
// Decode will find the next PEM formatted block (certificate, private key // Decode will find the next PEM formatted block (certificate, private key
// etc) in the input. It returns that block and the remainder of the input. If // etc) in the input. It returns that block and the remainder of the input. If
...@@ -214,13 +213,13 @@ func Encode(out io.Writer, b *Block) (err os.Error) { ...@@ -214,13 +213,13 @@ func Encode(out io.Writer, b *Block) (err os.Error) {
if err != nil { if err != nil {
return return
} }
_, err = out.Write(strings.Bytes(b.Type + "-----\n")) _, err = out.Write([]byte(b.Type + "-----\n"))
if err != nil { if err != nil {
return return
} }
for k, v := range b.Headers { for k, v := range b.Headers {
_, err = out.Write(strings.Bytes(k + ": " + v + "\n")) _, err = out.Write([]byte(k + ": " + v + "\n"))
if err != nil { if err != nil {
return return
} }
...@@ -248,7 +247,7 @@ func Encode(out io.Writer, b *Block) (err os.Error) { ...@@ -248,7 +247,7 @@ func Encode(out io.Writer, b *Block) (err os.Error) {
if err != nil { if err != nil {
return return
} }
_, err = out.Write(strings.Bytes(b.Type + "-----\n")) _, err = out.Write([]byte(b.Type + "-----\n"))
return return
} }
......
...@@ -7,7 +7,6 @@ package pem ...@@ -7,7 +7,6 @@ package pem
import ( import (
"bytes" "bytes"
"reflect" "reflect"
"strings"
"testing" "testing"
) )
...@@ -28,7 +27,7 @@ var getLineTests = []GetLineTest{ ...@@ -28,7 +27,7 @@ var getLineTests = []GetLineTest{
func TestGetLine(t *testing.T) { func TestGetLine(t *testing.T) {
for i, test := range getLineTests { for i, test := range getLineTests {
x, y := getLine(strings.Bytes(test.in)) x, y := getLine([]byte(test.in))
if string(x) != test.out1 || string(y) != test.out2 { if string(x) != test.out1 || string(y) != test.out2 {
t.Errorf("#%d got:%+v,%+v want:%s,%s", i, x, y, test.out1, test.out2) t.Errorf("#%d got:%+v,%+v want:%s,%s", i, x, y, test.out1, test.out2)
} }
...@@ -36,7 +35,7 @@ func TestGetLine(t *testing.T) { ...@@ -36,7 +35,7 @@ func TestGetLine(t *testing.T) {
} }
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
result, remainder := Decode(strings.Bytes(pemData)) result, remainder := Decode([]byte(pemData))
if !reflect.DeepEqual(result, certificate) { if !reflect.DeepEqual(result, certificate) {
t.Errorf("#0 got:%#v want:%#v", result, certificate) t.Errorf("#0 got:%#v want:%#v", result, certificate)
} }
...@@ -44,7 +43,7 @@ func TestDecode(t *testing.T) { ...@@ -44,7 +43,7 @@ func TestDecode(t *testing.T) {
if !reflect.DeepEqual(result, privateKey) { if !reflect.DeepEqual(result, privateKey) {
t.Errorf("#1 got:%#v want:%#v", result, privateKey) t.Errorf("#1 got:%#v want:%#v", result, privateKey)
} }
result, _ = Decode(strings.Bytes(pemPrivateKey)) result, _ = Decode([]byte(pemPrivateKey))
if !reflect.DeepEqual(result, privateKey2) { if !reflect.DeepEqual(result, privateKey2) {
t.Errorf("#2 got:%#v want:%#v", result, privateKey2) t.Errorf("#2 got:%#v want:%#v", result, privateKey2)
} }
...@@ -77,7 +76,7 @@ func TestLineBreaker(t *testing.T) { ...@@ -77,7 +76,7 @@ func TestLineBreaker(t *testing.T) {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
var breaker lineBreaker var breaker lineBreaker
breaker.out = buf breaker.out = buf
_, err := breaker.Write(strings.Bytes(test.in)) _, err := breaker.Write([]byte(test.in))
if err != nil { if err != nil {
t.Errorf("#%d: error from Write: %s", i, err) t.Errorf("#%d: error from Write: %s", i, err)
continue continue
...@@ -99,7 +98,7 @@ func TestLineBreaker(t *testing.T) { ...@@ -99,7 +98,7 @@ func TestLineBreaker(t *testing.T) {
breaker.out = buf breaker.out = buf
for i := 0; i < len(test.in); i++ { for i := 0; i < len(test.in); i++ {
_, err := breaker.Write(strings.Bytes(test.in[i : i+1])) _, err := breaker.Write([]byte(test.in[i : i+1]))
if err != nil { if err != nil {
t.Errorf("#%d: error from Write (byte by byte): %s", i, err) t.Errorf("#%d: error from Write (byte by byte): %s", i, err)
continue continue
......
...@@ -6,13 +6,12 @@ package datafmt ...@@ -6,13 +6,12 @@ package datafmt
import ( import (
"fmt" "fmt"
"strings"
"testing" "testing"
) )
func parse(t *testing.T, form string, fmap FormatterMap) Format { func parse(t *testing.T, form string, fmap FormatterMap) Format {
f, err := Parse("", strings.Bytes(form), fmap) f, err := Parse("", []byte(form), fmap)
if err != nil { if err != nil {
t.Errorf("Parse(%s): %v", form, err) t.Errorf("Parse(%s): %v", form, err)
return nil return nil
...@@ -52,7 +51,7 @@ func formatter(s *State, value interface{}, rule_name string) bool { ...@@ -52,7 +51,7 @@ func formatter(s *State, value interface{}, rule_name string) bool {
case "nil": case "nil":
return false return false
case "testing.T": case "testing.T":
s.Write(strings.Bytes("testing.T")) s.Write([]byte("testing.T"))
return true return true
} }
panic("unreachable") panic("unreachable")
......
...@@ -137,7 +137,7 @@ func (p *parser) parseString() string { ...@@ -137,7 +137,7 @@ func (p *parser) parseString() string {
func (p *parser) parseLiteral() literal { func (p *parser) parseLiteral() literal {
s := strings.Bytes(p.parseString()) s := []byte(p.parseString())
// A string literal may contain %-format specifiers. To simplify // A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments // and speed up printing of the literal, split it into segments
......
...@@ -32,7 +32,6 @@ import ( ...@@ -32,7 +32,6 @@ import (
"log" "log"
"os" "os"
"runtime" "runtime"
"strings"
"time" "time"
"./pdp1" "./pdp1"
) )
...@@ -53,7 +52,7 @@ func main() { ...@@ -53,7 +52,7 @@ func main() {
var m SpacewarPDP1 var m SpacewarPDP1
m.Init(w) m.Init(w)
m.PC = 4 m.PC = 4
f := bytes.NewBuffer(strings.Bytes(spacewarCode)) f := bytes.NewBuffer([]byte(spacewarCode))
if err = m.Load(f); err != nil { if err = m.Load(f); err != nil {
log.Exitf("loading %s: %s", "spacewar.lst", err) log.Exitf("loading %s: %s", "spacewar.lst", err)
} }
......
...@@ -66,12 +66,12 @@ var fmttests = []fmtTest{ ...@@ -66,12 +66,12 @@ var fmttests = []fmtTest{
fmtTest{"%q", "abc", `"abc"`}, fmtTest{"%q", "abc", `"abc"`},
// basic bytes // basic bytes
fmtTest{"%s", strings.Bytes("abc"), "abc"}, fmtTest{"%s", []byte("abc"), "abc"},
fmtTest{"%x", strings.Bytes("abc"), "616263"}, fmtTest{"%x", []byte("abc"), "616263"},
fmtTest{"% x", strings.Bytes("abc"), "61 62 63"}, fmtTest{"% x", []byte("abc"), "61 62 63"},
fmtTest{"%x", strings.Bytes("xyz"), "78797a"}, fmtTest{"%x", []byte("xyz"), "78797a"},
fmtTest{"%X", strings.Bytes("xyz"), "78797A"}, fmtTest{"%X", []byte("xyz"), "78797A"},
fmtTest{"%q", strings.Bytes("abc"), `"abc"`}, fmtTest{"%q", []byte("abc"), `"abc"`},
// escaped strings // escaped strings
fmtTest{"%#q", `abc`, "`abc`"}, fmtTest{"%#q", `abc`, "`abc`"},
......
...@@ -123,8 +123,8 @@ func split(text []byte) [][]byte { ...@@ -123,8 +123,8 @@ func split(text []byte) [][]byte {
var ( var (
ldquo = strings.Bytes("&ldquo;") ldquo = []byte("&ldquo;")
rdquo = strings.Bytes("&rdquo;") rdquo = []byte("&rdquo;")
) )
// Escape comment text for HTML. // Escape comment text for HTML.
...@@ -149,10 +149,10 @@ func commentEscape(w io.Writer, s []byte) { ...@@ -149,10 +149,10 @@ func commentEscape(w io.Writer, s []byte) {
var ( var (
html_p = strings.Bytes("<p>\n") html_p = []byte("<p>\n")
html_endp = strings.Bytes("</p>\n") html_endp = []byte("</p>\n")
html_pre = strings.Bytes("<pre>") html_pre = []byte("<pre>")
html_endpre = strings.Bytes("</pre>\n") html_endpre = []byte("</pre>\n")
) )
......
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
pathutil "path" pathutil "path"
"strings"
) )
...@@ -27,7 +26,7 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) { ...@@ -27,7 +26,7 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) {
if src != nil { if src != nil {
switch s := src.(type) { switch s := src.(type) {
case string: case string:
return strings.Bytes(s), nil return []byte(s), nil
case []byte: case []byte:
return s, nil return s, nil
case *bytes.Buffer: case *bytes.Buffer:
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"bytes" "bytes"
"go/ast" "go/ast"
"go/token" "go/token"
"strings"
) )
...@@ -286,7 +285,7 @@ func (p *printer) isOneLineFieldList(list []*ast.Field) bool { ...@@ -286,7 +285,7 @@ func (p *printer) isOneLineFieldList(list []*ast.Field) bool {
func (p *printer) setLineComment(text string) { func (p *printer) setLineComment(text string) {
p.setComment(&ast.CommentGroup{[]*ast.Comment{&ast.Comment{noPos, strings.Bytes(text)}}}) p.setComment(&ast.CommentGroup{[]*ast.Comment{&ast.Comment{noPos, []byte(text)}}})
} }
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"os" "os"
"reflect" "reflect"
"runtime" "runtime"
"strings"
"tabwriter" "tabwriter"
) )
...@@ -45,11 +44,11 @@ var ( ...@@ -45,11 +44,11 @@ var (
newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'} // more than maxNewlines newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'} // more than maxNewlines
formfeeds = [...]byte{'\f', '\f', '\f', '\f', '\f', '\f', '\f', '\f'} // more than maxNewlines formfeeds = [...]byte{'\f', '\f', '\f', '\f', '\f', '\f', '\f', '\f'} // more than maxNewlines
esc_quot = strings.Bytes("&#34;") // shorter than "&quot;" esc_quot = []byte("&#34;") // shorter than "&quot;"
esc_apos = strings.Bytes("&#39;") // shorter than "&apos;" esc_apos = []byte("&#39;") // shorter than "&apos;"
esc_amp = strings.Bytes("&amp;") esc_amp = []byte("&amp;")
esc_lt = strings.Bytes("&lt;") esc_lt = []byte("&lt;")
esc_gt = strings.Bytes("&gt;") esc_gt = []byte("&gt;")
) )
...@@ -223,12 +222,12 @@ func (p *printer) writeTaggedItem(data []byte, tag HTMLTag) { ...@@ -223,12 +222,12 @@ func (p *printer) writeTaggedItem(data []byte, tag HTMLTag) {
// write start tag, if any // write start tag, if any
// (no html-escaping and no p.pos update for tags - use write0) // (no html-escaping and no p.pos update for tags - use write0)
if tag.Start != "" { if tag.Start != "" {
p.write0(strings.Bytes(tag.Start)) p.write0([]byte(tag.Start))
} }
p.write(data) p.write(data)
// write end tag, if any // write end tag, if any
if tag.End != "" { if tag.End != "" {
p.write0(strings.Bytes(tag.End)) p.write0([]byte(tag.End))
} }
} }
...@@ -247,7 +246,7 @@ func (p *printer) writeItem(pos token.Position, data []byte, tag HTMLTag) { ...@@ -247,7 +246,7 @@ func (p *printer) writeItem(pos token.Position, data []byte, tag HTMLTag) {
} }
if debug { if debug {
// do not update p.pos - use write0 // do not update p.pos - use write0
p.write0(strings.Bytes(fmt.Sprintf("[%d:%d]", pos.Line, pos.Column))) p.write0([]byte(fmt.Sprintf("[%d:%d]", pos.Line, pos.Column)))
} }
if p.Mode&GenHTML != 0 { if p.Mode&GenHTML != 0 {
// write line tag if on a new line // write line tag if on a new line
...@@ -744,7 +743,7 @@ func (p *printer) print(args ...) { ...@@ -744,7 +743,7 @@ func (p *printer) print(args ...) {
if p.Styler != nil { if p.Styler != nil {
data, tag = p.Styler.Ident(x) data, tag = p.Styler.Ident(x)
} else { } else {
data = strings.Bytes(x.Name()) data = []byte(x.Name())
} }
case *ast.BasicLit: case *ast.BasicLit:
if p.Styler != nil { if p.Styler != nil {
...@@ -756,12 +755,12 @@ func (p *printer) print(args ...) { ...@@ -756,12 +755,12 @@ func (p *printer) print(args ...) {
// (note that valid Go programs cannot contain esc ('\xff') // (note that valid Go programs cannot contain esc ('\xff')
// bytes since they do not appear in legal UTF-8 sequences) // bytes since they do not appear in legal UTF-8 sequences)
// TODO(gri): do this more efficiently. // TODO(gri): do this more efficiently.
data = strings.Bytes("\xff" + string(data) + "\xff") data = []byte("\xff" + string(data) + "\xff")
case token.Token: case token.Token:
if p.Styler != nil { if p.Styler != nil {
data, tag = p.Styler.Token(x) data, tag = p.Styler.Token(x)
} else { } else {
data = strings.Bytes(x.String()) data = []byte(x.String())
} }
isKeyword = x.IsKeyword() isKeyword = x.IsKeyword()
case token.Position: case token.Position:
......
...@@ -7,7 +7,6 @@ package scanner ...@@ -7,7 +7,6 @@ package scanner
import ( import (
"go/token" "go/token"
"os" "os"
"strings"
"testing" "testing"
) )
...@@ -225,7 +224,7 @@ func TestScan(t *testing.T) { ...@@ -225,7 +224,7 @@ func TestScan(t *testing.T) {
// verify scan // verify scan
index := 0 index := 0
epos := token.Position{"", 0, 1, 1} epos := token.Position{"", 0, 1, 1}
nerrors := Tokenize("", strings.Bytes(src), &testErrorHandler{t}, ScanComments, nerrors := Tokenize("", []byte(src), &testErrorHandler{t}, ScanComments,
func(pos token.Position, tok token.Token, litb []byte) bool { func(pos token.Position, tok token.Token, litb []byte) bool {
e := elt{token.EOF, "", special} e := elt{token.EOF, "", special}
if index < len(tokens) { if index < len(tokens) {
...@@ -264,7 +263,7 @@ func TestScan(t *testing.T) { ...@@ -264,7 +263,7 @@ func TestScan(t *testing.T) {
func checkSemi(t *testing.T, line string, mode uint) { func checkSemi(t *testing.T, line string, mode uint) {
var S Scanner var S Scanner
S.Init("TestSemis", strings.Bytes(line), nil, mode) S.Init("TestSemis", []byte(line), nil, mode)
pos, tok, lit := S.Scan() pos, tok, lit := S.Scan()
for tok != token.EOF { for tok != token.EOF {
if tok == token.ILLEGAL { if tok == token.ILLEGAL {
...@@ -451,7 +450,7 @@ func TestLineComments(t *testing.T) { ...@@ -451,7 +450,7 @@ func TestLineComments(t *testing.T) {
// verify scan // verify scan
var S Scanner var S Scanner
S.Init("TestLineComments", strings.Bytes(src), nil, 0) S.Init("TestLineComments", []byte(src), nil, 0)
for _, s := range segments { for _, s := range segments {
pos, _, lit := S.Scan() pos, _, lit := S.Scan()
checkPos(t, string(lit), pos, token.Position{s.filename, pos.Offset, s.line, pos.Column}) checkPos(t, string(lit), pos, token.Position{s.filename, pos.Offset, s.line, pos.Column})
...@@ -468,7 +467,7 @@ func TestInit(t *testing.T) { ...@@ -468,7 +467,7 @@ func TestInit(t *testing.T) {
var s Scanner var s Scanner
// 1st init // 1st init
s.Init("", strings.Bytes("if true { }"), nil, 0) s.Init("", []byte("if true { }"), nil, 0)
s.Scan() // if s.Scan() // if
s.Scan() // true s.Scan() // true
_, tok, _ := s.Scan() // { _, tok, _ := s.Scan() // {
...@@ -477,7 +476,7 @@ func TestInit(t *testing.T) { ...@@ -477,7 +476,7 @@ func TestInit(t *testing.T) {
} }
// 2nd init // 2nd init
s.Init("", strings.Bytes("go true { ]"), nil, 0) s.Init("", []byte("go true { ]"), nil, 0)
_, tok, _ = s.Scan() // go _, tok, _ = s.Scan() // go
if tok != token.GO { if tok != token.GO {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO) t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO)
...@@ -493,7 +492,7 @@ func TestIllegalChars(t *testing.T) { ...@@ -493,7 +492,7 @@ func TestIllegalChars(t *testing.T) {
var s Scanner var s Scanner
const src = "*?*$*@*" const src = "*?*$*@*"
s.Init("", strings.Bytes(src), &testErrorHandler{t}, AllowIllegalChars) s.Init("", []byte(src), &testErrorHandler{t}, AllowIllegalChars)
for offs, ch := range src { for offs, ch := range src {
pos, tok, lit := s.Scan() pos, tok, lit := s.Scan()
if pos.Offset != offs { if pos.Offset != offs {
...@@ -521,7 +520,7 @@ func TestStdErrorHander(t *testing.T) { ...@@ -521,7 +520,7 @@ func TestStdErrorHander(t *testing.T) {
"@ @ @" // original file, line 1 again "@ @ @" // original file, line 1 again
v := new(ErrorVector) v := new(ErrorVector)
nerrors := Tokenize("File1", strings.Bytes(src), v, 0, nerrors := Tokenize("File1", []byte(src), v, 0,
func(pos token.Position, tok token.Token, litb []byte) bool { func(pos token.Position, tok token.Token, litb []byte) bool {
return tok != token.EOF return tok != token.EOF
}) })
...@@ -567,7 +566,7 @@ func (h *errorCollector) Error(pos token.Position, msg string) { ...@@ -567,7 +566,7 @@ func (h *errorCollector) Error(pos token.Position, msg string) {
func checkError(t *testing.T, src string, tok token.Token, pos int, err string) { func checkError(t *testing.T, src string, tok token.Token, pos int, err string) {
var s Scanner var s Scanner
var h errorCollector var h errorCollector
s.Init("", strings.Bytes(src), &h, ScanComments) s.Init("", []byte(src), &h, ScanComments)
_, tok0, _ := s.Scan() _, tok0, _ := s.Scan()
_, tok1, _ := s.Scan() _, tok1, _ := s.Scan()
if tok0 != tok { if tok0 != tok {
......
...@@ -298,7 +298,7 @@ func TestScalarEncInstructions(t *testing.T) { ...@@ -298,7 +298,7 @@ func TestScalarEncInstructions(t *testing.T) {
// bytes == []uint8 // bytes == []uint8
{ {
b.Reset() b.Reset()
data := struct{ a []byte }{strings.Bytes("hello")} data := struct{ a []byte }{[]byte("hello")}
instr := &encInstr{encUint8Array, 6, 0, 0} instr := &encInstr{encUint8Array, 6, 0, 0}
state := newencoderState(b) state := newencoderState(b)
instr.op(instr, state, unsafe.Pointer(&data)) instr.op(instr, state, unsafe.Pointer(&data))
...@@ -587,7 +587,7 @@ func TestEndToEnd(t *testing.T) { ...@@ -587,7 +587,7 @@ func TestEndToEnd(t *testing.T) {
strs: &[2]string{s1, s2}, strs: &[2]string{s1, s2},
int64s: &[]int64{77, 89, 123412342134}, int64s: &[]int64{77, 89, 123412342134},
s: "Now is the time", s: "Now is the time",
y: strings.Bytes("hello, sailor"), y: []byte("hello, sailor"),
t: &T2{"this is T2"}, t: &T2{"this is T2"},
} }
b := new(bytes.Buffer) b := new(bytes.Buffer)
...@@ -935,7 +935,7 @@ func TestIgnoredFields(t *testing.T) { ...@@ -935,7 +935,7 @@ func TestIgnoredFields(t *testing.T) {
it0.ignore_e[2] = 3.0 it0.ignore_e[2] = 3.0
it0.ignore_f = true it0.ignore_f = true
it0.ignore_g = "pay no attention" it0.ignore_g = "pay no attention"
it0.ignore_h = strings.Bytes("to the curtain") it0.ignore_h = []byte("to the curtain")
it0.ignore_i = &RT1{3.1, "hi", 7, "hello"} it0.ignore_i = &RT1{3.1, "hi", 7, "hello"}
b := new(bytes.Buffer) b := new(bytes.Buffer)
......
...@@ -46,7 +46,7 @@ func send(req *Request) (resp *Response, err os.Error) { ...@@ -46,7 +46,7 @@ func send(req *Request) (resp *Response, err os.Error) {
if len(info) > 0 { if len(info) > 0 {
enc := base64.URLEncoding enc := base64.URLEncoding
encoded := make([]byte, enc.EncodedLen(len(info))) encoded := make([]byte, enc.EncodedLen(len(info)))
enc.Encode(encoded, strings.Bytes(info)) enc.Encode(encoded, []byte(info))
if req.Header == nil { if req.Header == nil {
req.Header = make(map[string]string) req.Header = make(map[string]string)
} }
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
package http package http
import (
"strings"
)
// This file deals with lexical matters of HTTP // This file deals with lexical matters of HTTP
func isSeparator(c byte) bool { func isSeparator(c byte) bool {
...@@ -112,7 +108,7 @@ func httpUnquote(raw []byte) (eaten int, result string) { ...@@ -112,7 +108,7 @@ func httpUnquote(raw []byte) (eaten int, result string) {
// the input string might be parsed. result is always non-nil. // the input string might be parsed. result is always non-nil.
func httpSplitFieldValue(fv string) (eaten int, result []string) { func httpSplitFieldValue(fv string) (eaten int, result []string) {
result = make([]string, 0, len(fv)) result = make([]string, 0, len(fv))
raw := strings.Bytes(fv) raw := []byte(fv)
i := 0 i := 0
chunk := "" chunk := ""
for i < len(raw) { for i < len(raw) {
......
...@@ -376,7 +376,7 @@ func CanonicalHeaderKey(s string) string { ...@@ -376,7 +376,7 @@ func CanonicalHeaderKey(s string) string {
// and upper case after each dash. // and upper case after each dash.
// (Host, User-Agent, If-Modified-Since). // (Host, User-Agent, If-Modified-Since).
// HTTP headers are ASCII only, so no Unicode issues. // HTTP headers are ASCII only, so no Unicode issues.
a := strings.Bytes(s) a := []byte(s)
upper := true upper := true
for i, v := range a { for i, v := range a {
if upper && 'a' <= v && v <= 'z' { if upper && 'a' <= v && v <= 'z' {
......
...@@ -70,7 +70,7 @@ func shouldEscape(c byte) bool { ...@@ -70,7 +70,7 @@ func shouldEscape(c byte) bool {
// CanonicalPath applies the algorithm specified in RFC 2396 to // CanonicalPath applies the algorithm specified in RFC 2396 to
// simplify the path, removing unnecessary . and .. elements. // simplify the path, removing unnecessary . and .. elements.
func CanonicalPath(path string) string { func CanonicalPath(path string) string {
buf := strings.Bytes(path) buf := []byte(path)
a := buf[0:0] a := buf[0:0]
// state helps to find /.. ^.. ^. and /. patterns. // state helps to find /.. ^.. ^. and /. patterns.
// state == 1 - prev char is '/' or beginning of the string. // state == 1 - prev char is '/' or beginning of the string.
......
...@@ -8,10 +8,7 @@ ...@@ -8,10 +8,7 @@
// abstract the functionality, plus some other related primitives. // abstract the functionality, plus some other related primitives.
package io package io
import ( import "os"
"os"
"strings"
)
// Error represents an unexpected I/O behavior. // Error represents an unexpected I/O behavior.
type Error struct { type Error struct {
...@@ -160,7 +157,7 @@ type ReadByter interface { ...@@ -160,7 +157,7 @@ type ReadByter interface {
// WriteString writes the contents of the string s to w, which accepts an array of bytes. // WriteString writes the contents of the string s to w, which accepts an array of bytes.
func WriteString(w Writer, s string) (n int, err os.Error) { func WriteString(w Writer, s string) (n int, err os.Error) {
return w.Write(strings.Bytes(s)) return w.Write([]byte(s))
} }
// ReadAtLeast reads from r into buf until it has read at least min bytes. // ReadAtLeast reads from r into buf until it has read at least min bytes.
......
...@@ -7,7 +7,6 @@ package ioutil_test ...@@ -7,7 +7,6 @@ package ioutil_test
import ( import (
. "io/ioutil" . "io/ioutil"
"os" "os"
"strings"
"testing" "testing"
) )
...@@ -43,7 +42,7 @@ func TestWriteFile(t *testing.T) { ...@@ -43,7 +42,7 @@ func TestWriteFile(t *testing.T) {
"build bigger and better idiot-proof programs, and the Universe trying " + "build bigger and better idiot-proof programs, and the Universe trying " +
"to produce bigger and better idiots. So far, the Universe is winning." "to produce bigger and better idiots. So far, the Universe is winning."
if err := WriteFile(filename, strings.Bytes(data), 0644); err != nil { if err := WriteFile(filename, []byte(data), 0644); err != nil {
t.Fatalf("WriteFile %s: %v", filename, err) t.Fatalf("WriteFile %s: %v", filename, err)
} }
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"fmt" "fmt"
. "io" . "io"
"os" "os"
"strings"
"testing" "testing"
"time" "time"
) )
...@@ -29,7 +28,7 @@ func TestPipe1(t *testing.T) { ...@@ -29,7 +28,7 @@ func TestPipe1(t *testing.T) {
c := make(chan int) c := make(chan int)
r, w := Pipe() r, w := Pipe()
var buf = make([]byte, 64) var buf = make([]byte, 64)
go checkWrite(t, w, strings.Bytes("hello, world"), c) go checkWrite(t, w, []byte("hello, world"), c)
n, err := r.Read(buf) n, err := r.Read(buf)
if err != nil { if err != nil {
t.Errorf("read: %v", err) t.Errorf("read: %v", err)
......
...@@ -7,7 +7,6 @@ package net ...@@ -7,7 +7,6 @@ package net
import ( import (
"flag" "flag"
"io" "io"
"strings"
"syscall" "syscall"
"testing" "testing"
) )
...@@ -18,7 +17,7 @@ var ipv6 = flag.Bool("ipv6", false, "assume ipv6 tunnel is present") ...@@ -18,7 +17,7 @@ var ipv6 = flag.Bool("ipv6", false, "assume ipv6 tunnel is present")
// fd is already connected to the destination, port 80. // fd is already connected to the destination, port 80.
// Run an HTTP request to fetch the appropriate page. // Run an HTTP request to fetch the appropriate page.
func fetchGoogle(t *testing.T, fd Conn, network, addr string) { func fetchGoogle(t *testing.T, fd Conn, network, addr string) {
req := strings.Bytes("GET /intl/en/privacy.html HTTP/1.0\r\nHost: www.google.com\r\n\r\n") req := []byte("GET /intl/en/privacy.html HTTP/1.0\r\nHost: www.google.com\r\n\r\n")
n, err := fd.Write(req) n, err := fd.Write(req)
buf := make([]byte, 1000) buf := make([]byte, 1000)
......
...@@ -65,7 +65,7 @@ func connect(t *testing.T, network, addr string, isEmpty bool) { ...@@ -65,7 +65,7 @@ func connect(t *testing.T, network, addr string, isEmpty bool) {
var b []byte var b []byte
if !isEmpty { if !isEmpty {
b = strings.Bytes("hello, world\n") b = []byte("hello, world\n")
} }
var b1 [100]byte var b1 [100]byte
......
...@@ -468,7 +468,7 @@ func TestTruncate(t *testing.T) { ...@@ -468,7 +468,7 @@ func TestTruncate(t *testing.T) {
} }
checkSize(t, Path, 0) checkSize(t, Path, 0)
fd.Write(strings.Bytes("hello, world\n")) fd.Write([]byte("hello, world\n"))
checkSize(t, Path, 13) checkSize(t, Path, 13)
fd.Truncate(10) fd.Truncate(10)
checkSize(t, Path, 10) checkSize(t, Path, 10)
...@@ -476,7 +476,7 @@ func TestTruncate(t *testing.T) { ...@@ -476,7 +476,7 @@ func TestTruncate(t *testing.T) {
checkSize(t, Path, 1024) checkSize(t, Path, 1024)
fd.Truncate(0) fd.Truncate(0)
checkSize(t, Path, 0) checkSize(t, Path, 0)
fd.Write(strings.Bytes("surprise!")) fd.Write([]byte("surprise!"))
checkSize(t, Path, 13+9) // wrote at offset past where hello, world was. checkSize(t, Path, 13+9) // wrote at offset past where hello, world was.
fd.Close() fd.Close()
Remove(Path) Remove(Path)
...@@ -688,7 +688,7 @@ func TestWriteAt(t *testing.T) { ...@@ -688,7 +688,7 @@ func TestWriteAt(t *testing.T) {
const data = "hello, world\n" const data = "hello, world\n"
io.WriteString(f, data) io.WriteString(f, data)
n, err := f.WriteAt(strings.Bytes("WORLD"), 7) n, err := f.WriteAt([]byte("WORLD"), 7)
if err != nil || n != 5 { if err != nil || n != 5 {
t.Fatalf("WriteAt 7: %d, %v", n, err) t.Fatalf("WriteAt 7: %d, %v", n, err)
} }
......
...@@ -6,10 +6,7 @@ package patch ...@@ -6,10 +6,7 @@ package patch
// TODO(rsc): test Apply // TODO(rsc): test Apply
import ( import "testing"
"strings"
"testing"
)
type Test struct { type Test struct {
in string in string
...@@ -19,7 +16,7 @@ type Test struct { ...@@ -19,7 +16,7 @@ type Test struct {
func TestFileApply(t *testing.T) { func TestFileApply(t *testing.T) {
for i, test := range tests { for i, test := range tests {
set, err := Parse(strings.Bytes(test.diff)) set, err := Parse([]byte(test.diff))
if err != nil { if err != nil {
t.Errorf("#%d: Parse: %s", i, err) t.Errorf("#%d: Parse: %s", i, err)
continue continue
...@@ -28,7 +25,7 @@ func TestFileApply(t *testing.T) { ...@@ -28,7 +25,7 @@ func TestFileApply(t *testing.T) {
t.Errorf("#%d: Parse returned %d patches, want 1", i, len(set.File)) t.Errorf("#%d: Parse returned %d patches, want 1", i, len(set.File))
continue continue
} }
new, err := set.File[0].Apply(strings.Bytes(test.in)) new, err := set.File[0].Apply([]byte(test.in))
if err != nil { if err != nil {
t.Errorf("#%d: Apply: %s", i, err) t.Errorf("#%d: Apply: %s", i, err)
continue continue
......
...@@ -42,7 +42,7 @@ func Clean(path string) string { ...@@ -42,7 +42,7 @@ func Clean(path string) string {
// writing to buf; w is index of next byte to write. // writing to buf; w is index of next byte to write.
// dotdot is index in buf where .. must stop, either because // dotdot is index in buf where .. must stop, either because
// it is the leading slash or it is a leading ../../.. prefix. // it is the leading slash or it is a leading ../../.. prefix.
buf := strings.Bytes(path) buf := []byte(path)
r, w, dotdot := 0, 0, 0 r, w, dotdot := 0, 0, 0
if rooted { if rooted {
r, w, dotdot = 1, 1, 1 r, w, dotdot = 1, 1, 1
......
...@@ -161,7 +161,7 @@ func executeTest(t *testing.T, expr string, str string, match []int) { ...@@ -161,7 +161,7 @@ func executeTest(t *testing.T, expr string, str string, match []int) {
printVec(t, match) printVec(t, match)
} }
// now try bytes // now try bytes
m = re.Execute(strings.Bytes(str)) m = re.Execute([]byte(str))
if !equal(m, match) { if !equal(m, match) {
t.Errorf("Execute failure on %#q matching %q:", expr, str) t.Errorf("Execute failure on %#q matching %q:", expr, str)
printVec(t, m) printVec(t, m)
...@@ -199,7 +199,7 @@ func matchTest(t *testing.T, expr string, str string, match []int) { ...@@ -199,7 +199,7 @@ func matchTest(t *testing.T, expr string, str string, match []int) {
t.Errorf("MatchString failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0) t.Errorf("MatchString failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0)
} }
// now try bytes // now try bytes
m = re.Match(strings.Bytes(str)) m = re.Match([]byte(str))
if m != (len(match) > 0) { if m != (len(match) > 0) {
t.Errorf("Match failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0) t.Errorf("Match failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0)
} }
...@@ -315,7 +315,7 @@ func TestReplaceAll(t *testing.T) { ...@@ -315,7 +315,7 @@ func TestReplaceAll(t *testing.T) {
tc.pattern, tc.input, tc.replacement, actual, tc.output) tc.pattern, tc.input, tc.replacement, actual, tc.output)
} }
// now try bytes // now try bytes
actual = string(re.ReplaceAll(strings.Bytes(tc.input), strings.Bytes(tc.replacement))) actual = string(re.ReplaceAll([]byte(tc.input), []byte(tc.replacement)))
if actual != tc.output { if actual != tc.output {
t.Errorf("%q.Replace(%q,%q) = %q; want %q", t.Errorf("%q.Replace(%q,%q) = %q; want %q",
tc.pattern, tc.input, tc.replacement, actual, tc.output) tc.pattern, tc.input, tc.replacement, actual, tc.output)
...@@ -419,7 +419,7 @@ func TestAllMatches(t *testing.T) { ...@@ -419,7 +419,7 @@ func TestAllMatches(t *testing.T) {
case "matchit": case "matchit":
result = make([]string, len(c.input)+1) result = make([]string, len(c.input)+1)
i := 0 i := 0
b := strings.Bytes(c.input) b := []byte(c.input)
for match := range re.AllMatchesIter(b, c.n) { for match := range re.AllMatchesIter(b, c.n) {
result[i] = string(match) result[i] = string(match)
i++ i++
...@@ -435,7 +435,7 @@ func TestAllMatches(t *testing.T) { ...@@ -435,7 +435,7 @@ func TestAllMatches(t *testing.T) {
result = result[0:i] result = result[0:i]
case "match": case "match":
result = make([]string, len(c.input)+1) result = make([]string, len(c.input)+1)
b := strings.Bytes(c.input) b := []byte(c.input)
i := 0 i := 0
for _, match := range re.AllMatches(b, c.n) { for _, match := range re.AllMatches(b, c.n) {
result[i] = string(match) result[i] = string(match)
......
...@@ -302,23 +302,3 @@ func TrimSpace(s string) string { ...@@ -302,23 +302,3 @@ func TrimSpace(s string) string {
} }
return s[start:end] return s[start:end]
} }
// Bytes returns a new slice containing the bytes in s.
func Bytes(s string) []byte {
b := make([]byte, len(s))
for i := 0; i < len(s); i++ {
b[i] = s[i]
}
return b
}
// Runes returns a slice of runes (Unicode code points) equivalent to the string s.
func Runes(s string) []int {
t := make([]int, utf8.RuneCountInString(s))
i := 0
for _, r := range s {
t[i] = r
i++
}
return t
}
...@@ -444,16 +444,16 @@ var RunesTests = []RunesTest{ ...@@ -444,16 +444,16 @@ var RunesTests = []RunesTest{
func TestRunes(t *testing.T) { func TestRunes(t *testing.T) {
for _, tt := range RunesTests { for _, tt := range RunesTests {
a := Runes(tt.in) a := []int(tt.in)
if !runesEqual(a, tt.out) { if !runesEqual(a, tt.out) {
t.Errorf("Runes(%q) = %v; want %v", tt.in, a, tt.out) t.Errorf("[]int(%q) = %v; want %v", tt.in, a, tt.out)
continue continue
} }
if !tt.lossy { if !tt.lossy {
// can only test reassembly if we didn't lose information // can only test reassembly if we didn't lose information
s := string(a) s := string(a)
if s != tt.in { if s != tt.in {
t.Errorf("string(Runes(%q)) = %x; want %x", tt.in, s, tt.in) t.Errorf("string([]int(%q)) = %x; want %x", tt.in, s, tt.in)
} }
} }
} }
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"strings"
) )
// StringFormatter formats into the default string representation. // StringFormatter formats into the default string representation.
...@@ -26,11 +25,11 @@ func StringFormatter(w io.Writer, value interface{}, format string) { ...@@ -26,11 +25,11 @@ func StringFormatter(w io.Writer, value interface{}, format string) {
} }
var ( var (
esc_quot = strings.Bytes("&#34;") // shorter than "&quot;" esc_quot = []byte("&#34;") // shorter than "&quot;"
esc_apos = strings.Bytes("&#39;") // shorter than "&apos;" esc_apos = []byte("&#39;") // shorter than "&apos;"
esc_amp = strings.Bytes("&amp;") esc_amp = []byte("&amp;")
esc_lt = strings.Bytes("&lt;") esc_lt = []byte("&lt;")
esc_gt = strings.Bytes("&gt;") esc_gt = []byte("&gt;")
) )
// HTMLEscape writes to w the properly escaped HTML equivalent // HTMLEscape writes to w the properly escaped HTML equivalent
......
...@@ -915,7 +915,7 @@ func (t *Template) Parse(s string) os.Error { ...@@ -915,7 +915,7 @@ func (t *Template) Parse(s string) os.Error {
if !validDelim(t.ldelim) || !validDelim(t.rdelim) { if !validDelim(t.ldelim) || !validDelim(t.rdelim) {
return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)} return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)}
} }
t.buf = strings.Bytes(s) t.buf = []byte(s)
t.p = 0 t.p = 0
t.linenum = 1 t.linenum = 1
t.parse() t.parse()
...@@ -942,8 +942,8 @@ func (t *Template) Execute(data interface{}, wr io.Writer) os.Error { ...@@ -942,8 +942,8 @@ func (t *Template) Execute(data interface{}, wr io.Writer) os.Error {
// delimiters are very rarely invalid and Parse has the necessary // delimiters are very rarely invalid and Parse has the necessary
// error-handling interface already. // error-handling interface already.
func (t *Template) SetDelims(left, right string) { func (t *Template) SetDelims(left, right string) {
t.ldelim = strings.Bytes(left) t.ldelim = []byte(left)
t.rdelim = strings.Bytes(right) t.rdelim = []byte(right)
} }
// Parse creates a Template with default parameters (such as {} for // Parse creates a Template with default parameters (such as {} for
......
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"container/vector" "container/vector"
"fmt" "fmt"
"io" "io"
"strings"
"testing" "testing"
) )
...@@ -397,7 +396,7 @@ func TestAll(t *testing.T) { ...@@ -397,7 +396,7 @@ func TestAll(t *testing.T) {
s.stringmap = make(map[string]string) s.stringmap = make(map[string]string)
s.stringmap["stringkey1"] = "stringresult" // the same value so repeated section is order-independent s.stringmap["stringkey1"] = "stringresult" // the same value so repeated section is order-independent
s.stringmap["stringkey2"] = "stringresult" s.stringmap["stringkey2"] = "stringresult"
s.bytes = strings.Bytes("hello") s.bytes = []byte("hello")
s.iface = []int{1, 2, 3} s.iface = []int{1, 2, 3}
var buf bytes.Buffer var buf bytes.Buffer
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
package testing package testing
import (
"strings"
)
var good_re = []string{ var good_re = []string{
``, ``,
`.`, `.`,
...@@ -179,7 +175,7 @@ func executeTest(t *T, expr string, str string, match []int) { ...@@ -179,7 +175,7 @@ func executeTest(t *T, expr string, str string, match []int) {
printVec(t, match) printVec(t, match)
} }
// now try bytes // now try bytes
m = re.Execute(strings.Bytes(str)) m = re.Execute([]byte(str))
if !equal(m, match) { if !equal(m, match) {
t.Error("Execute failure on `", expr, "` matching `", str, "`:") t.Error("Execute failure on `", expr, "` matching `", str, "`:")
printVec(t, m) printVec(t, m)
...@@ -217,7 +213,7 @@ func matchTest(t *T, expr string, str string, match []int) { ...@@ -217,7 +213,7 @@ func matchTest(t *T, expr string, str string, match []int) {
t.Error("MatchString failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0) t.Error("MatchString failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0)
} }
// now try bytes // now try bytes
m = re.Match(strings.Bytes(str)) m = re.Match([]byte(str))
if m != (len(match) > 0) { if m != (len(match) > 0) {
t.Error("Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0) t.Error("Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0)
} }
...@@ -247,7 +243,7 @@ func matchStringsTest(t *T, expr string, str string, match []int) { ...@@ -247,7 +243,7 @@ func matchStringsTest(t *T, expr string, str string, match []int) {
printStrings(t, strs) printStrings(t, strs)
} }
// now try bytes // now try bytes
s := re.MatchSlices(strings.Bytes(str)) s := re.MatchSlices([]byte(str))
if !equalBytes(s, strs) { if !equalBytes(s, strs) {
t.Error("MatchSlices failure on `", expr, "` matching `", str, "`:") t.Error("MatchSlices failure on `", expr, "` matching `", str, "`:")
printBytes(t, s) printBytes(t, s)
......
...@@ -6,7 +6,6 @@ package utf8_test ...@@ -6,7 +6,6 @@ package utf8_test
import ( import (
"bytes" "bytes"
"strings"
"testing" "testing"
. "utf8" . "utf8"
) )
...@@ -48,7 +47,7 @@ var utf8map = []Utf8Map{ ...@@ -48,7 +47,7 @@ var utf8map = []Utf8Map{
// strings.Bytes with one extra byte at end // strings.Bytes with one extra byte at end
func makeBytes(s string) []byte { func makeBytes(s string) []byte {
s += "\x00" s += "\x00"
b := strings.Bytes(s) b := []byte(s)
return b[0 : len(s)-1] return b[0 : len(s)-1]
} }
...@@ -214,7 +213,7 @@ func BenchmarkDecodeASCIIRune(b *testing.B) { ...@@ -214,7 +213,7 @@ func BenchmarkDecodeASCIIRune(b *testing.B) {
} }
func BenchmarkDecodeJapaneseRune(b *testing.B) { func BenchmarkDecodeJapaneseRune(b *testing.B) {
nihon := strings.Bytes("本") nihon := []byte("本")
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
DecodeRune(nihon) DecodeRune(nihon)
} }
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"log" "log"
"net" "net"
"once" "once"
"strings"
"testing" "testing"
) )
...@@ -45,7 +44,7 @@ func TestEcho(t *testing.T) { ...@@ -45,7 +44,7 @@ func TestEcho(t *testing.T) {
t.Errorf("WebSocket handshake error", err) t.Errorf("WebSocket handshake error", err)
return return
} }
msg := strings.Bytes("hello, world\n") msg := []byte("hello, world\n")
if _, err := ws.Write(msg); err != nil { if _, err := ws.Write(msg); err != nil {
t.Errorf("Write: error %v", err) t.Errorf("Write: error %v", err)
} }
......
...@@ -173,7 +173,7 @@ func (c *Conn) sendBytes(buf []byte) { ...@@ -173,7 +173,7 @@ func (c *Conn) sendBytes(buf []byte) {
c.sendPadding(len(buf)) c.sendPadding(len(buf))
} }
func (c *Conn) sendString(str string) { c.sendBytes(strings.Bytes(str)) } func (c *Conn) sendString(str string) { c.sendBytes([]byte(str)) }
// sendUInt32s sends a list of 32-bit integers as variable length data. // sendUInt32s sends a list of 32-bit integers as variable length data.
func (c *Conn) sendUInt32List(list []uint32) { func (c *Conn) sendUInt32List(list []uint32) {
...@@ -318,7 +318,7 @@ func Dial(display string) (*Conn, os.Error) { ...@@ -318,7 +318,7 @@ func Dial(display string) (*Conn, os.Error) {
put16(buf[6:], uint16(len(authName))) put16(buf[6:], uint16(len(authName)))
put16(buf[8:], uint16(len(authData))) put16(buf[8:], uint16(len(authData)))
put16(buf[10:], 0) put16(buf[10:], 0)
copy(buf[12:], strings.Bytes(authName)) copy(buf[12:], []byte(authName))
copy(buf[12+pad(len(authName)):], authData) copy(buf[12+pad(len(authName)):], authData)
if _, err = c.conn.Write(buf); err != nil { if _, err = c.conn.Write(buf); err != nil {
return nil, err return nil, err
......
...@@ -815,7 +815,7 @@ Input: ...@@ -815,7 +815,7 @@ Input:
p.err = SyntaxError("invalid character entity &" + s + ";") p.err = SyntaxError("invalid character entity &" + s + ";")
return nil return nil
} }
p.buf.Write(strings.Bytes(text)) p.buf.Write([]byte(text))
b0, b1 = 0, 0 b0, b1 = 0, 0
continue Input continue Input
} }
...@@ -1508,11 +1508,11 @@ var htmlAutoClose = []string{ ...@@ -1508,11 +1508,11 @@ var htmlAutoClose = []string{
} }
var ( var (
esc_quot = strings.Bytes("&#34;") // shorter than "&quot;" esc_quot = []byte("&#34;") // shorter than "&quot;"
esc_apos = strings.Bytes("&#39;") // shorter than "&apos;" esc_apos = []byte("&#39;") // shorter than "&apos;"
esc_amp = strings.Bytes("&amp;") esc_amp = []byte("&amp;")
esc_lt = strings.Bytes("&lt;") esc_lt = []byte("&lt;")
esc_gt = strings.Bytes("&gt;") esc_gt = []byte("&gt;")
) )
// Escape writes to w the properly escaped XML equivalent // Escape writes to w the properly escaped XML equivalent
......
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"io" "io"
"os" "os"
"reflect" "reflect"
"strings"
"testing" "testing"
) )
...@@ -30,69 +29,71 @@ const testInput = ` ...@@ -30,69 +29,71 @@ const testInput = `
</body><!-- missing final newline -->` </body><!-- missing final newline -->`
var rawTokens = []Token{ var rawTokens = []Token{
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
ProcInst{"xml", strings.Bytes(`version="1.0" encoding="UTF-8"`)}, ProcInst{"xml", []byte(`version="1.0" encoding="UTF-8"`)},
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
Directive(strings.Bytes(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Directive([]byte(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`)), "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`),
CharData(strings.Bytes("\n")), ),
CharData([]byte("\n")),
StartElement{Name{"", "body"}, []Attr{Attr{Name{"xmlns", "foo"}, "ns1"}, Attr{Name{"", "xmlns"}, "ns2"}, Attr{Name{"xmlns", "tag"}, "ns3"}}}, StartElement{Name{"", "body"}, []Attr{Attr{Name{"xmlns", "foo"}, "ns1"}, Attr{Name{"", "xmlns"}, "ns2"}, Attr{Name{"xmlns", "tag"}, "ns3"}}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"", "hello"}, []Attr{Attr{Name{"", "lang"}, "en"}}}, StartElement{Name{"", "hello"}, []Attr{Attr{Name{"", "lang"}, "en"}}},
CharData(strings.Bytes("World <>'\" 白鵬翔")), CharData([]byte("World <>'\" 白鵬翔")),
EndElement{Name{"", "hello"}}, EndElement{Name{"", "hello"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"", "goodbye"}, nil}, StartElement{Name{"", "goodbye"}, nil},
EndElement{Name{"", "goodbye"}}, EndElement{Name{"", "goodbye"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"", "outer"}, []Attr{Attr{Name{"foo", "attr"}, "value"}, Attr{Name{"xmlns", "tag"}, "ns4"}}}, StartElement{Name{"", "outer"}, []Attr{Attr{Name{"foo", "attr"}, "value"}, Attr{Name{"xmlns", "tag"}, "ns4"}}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"", "inner"}, nil}, StartElement{Name{"", "inner"}, nil},
EndElement{Name{"", "inner"}}, EndElement{Name{"", "inner"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
EndElement{Name{"", "outer"}}, EndElement{Name{"", "outer"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"tag", "name"}, nil}, StartElement{Name{"tag", "name"}, nil},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
CharData(strings.Bytes("Some text here.")), CharData([]byte("Some text here.")),
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
EndElement{Name{"tag", "name"}}, EndElement{Name{"tag", "name"}},
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
EndElement{Name{"", "body"}}, EndElement{Name{"", "body"}},
Comment(strings.Bytes(" missing final newline ")), Comment([]byte(" missing final newline ")),
} }
var cookedTokens = []Token{ var cookedTokens = []Token{
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
ProcInst{"xml", strings.Bytes(`version="1.0" encoding="UTF-8"`)}, ProcInst{"xml", []byte(`version="1.0" encoding="UTF-8"`)},
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
Directive(strings.Bytes(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Directive([]byte(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`)), "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`),
CharData(strings.Bytes("\n")), ),
CharData([]byte("\n")),
StartElement{Name{"ns2", "body"}, []Attr{Attr{Name{"xmlns", "foo"}, "ns1"}, Attr{Name{"", "xmlns"}, "ns2"}, Attr{Name{"xmlns", "tag"}, "ns3"}}}, StartElement{Name{"ns2", "body"}, []Attr{Attr{Name{"xmlns", "foo"}, "ns1"}, Attr{Name{"", "xmlns"}, "ns2"}, Attr{Name{"xmlns", "tag"}, "ns3"}}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"ns2", "hello"}, []Attr{Attr{Name{"", "lang"}, "en"}}}, StartElement{Name{"ns2", "hello"}, []Attr{Attr{Name{"", "lang"}, "en"}}},
CharData(strings.Bytes("World <>'\" 白鵬翔")), CharData([]byte("World <>'\" 白鵬翔")),
EndElement{Name{"ns2", "hello"}}, EndElement{Name{"ns2", "hello"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"ns2", "goodbye"}, nil}, StartElement{Name{"ns2", "goodbye"}, nil},
EndElement{Name{"ns2", "goodbye"}}, EndElement{Name{"ns2", "goodbye"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"ns2", "outer"}, []Attr{Attr{Name{"ns1", "attr"}, "value"}, Attr{Name{"xmlns", "tag"}, "ns4"}}}, StartElement{Name{"ns2", "outer"}, []Attr{Attr{Name{"ns1", "attr"}, "value"}, Attr{Name{"xmlns", "tag"}, "ns4"}}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"ns2", "inner"}, nil}, StartElement{Name{"ns2", "inner"}, nil},
EndElement{Name{"ns2", "inner"}}, EndElement{Name{"ns2", "inner"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
EndElement{Name{"ns2", "outer"}}, EndElement{Name{"ns2", "outer"}},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
StartElement{Name{"ns3", "name"}, nil}, StartElement{Name{"ns3", "name"}, nil},
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
CharData(strings.Bytes("Some text here.")), CharData([]byte("Some text here.")),
CharData(strings.Bytes("\n ")), CharData([]byte("\n ")),
EndElement{Name{"ns3", "name"}}, EndElement{Name{"ns3", "name"}},
CharData(strings.Bytes("\n")), CharData([]byte("\n")),
EndElement{Name{"ns2", "body"}}, EndElement{Name{"ns2", "body"}},
Comment(strings.Bytes(" missing final newline ")), Comment([]byte(" missing final newline ")),
} }
var xmlInput = []string{ var xmlInput = []string{
......
...@@ -123,7 +123,7 @@ func pallmall(cols []int) { ...@@ -123,7 +123,7 @@ func pallmall(cols []int) {
fmt.Println(msg) fmt.Println(msg)
tot := 0 tot := 0
// wait for all results // wait for all results
for _ = range (cols) { for _ = range cols {
result := <-ended result := <-ended
tot += result.met tot += result.met
fmt.Printf("%v%v\n", result.met, spell(result.same, true)) fmt.Printf("%v%v\n", result.met, spell(result.same, true))
......
...@@ -41,7 +41,6 @@ import ( ...@@ -41,7 +41,6 @@ import (
"bufio" "bufio"
"flag" "flag"
"os" "os"
"strings"
) )
var out *bufio.Writer var out *bufio.Writer
...@@ -161,7 +160,7 @@ func main() { ...@@ -161,7 +160,7 @@ func main() {
AccumulateProbabilities(iub) AccumulateProbabilities(iub)
AccumulateProbabilities(homosapiens) AccumulateProbabilities(homosapiens)
alu := strings.Bytes( alu := []byte(
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
......
...@@ -42,7 +42,6 @@ import ( ...@@ -42,7 +42,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"sort" "sort"
"strings"
) )
var in *bufio.Reader var in *bufio.Reader
...@@ -111,7 +110,7 @@ func print(m map[string]int) { ...@@ -111,7 +110,7 @@ func print(m map[string]int) {
func main() { func main() {
in = bufio.NewReader(os.Stdin) in = bufio.NewReader(os.Stdin)
three := strings.Bytes(">THREE ") three := []byte(">THREE ")
for { for {
line, err := in.ReadSlice('\n') line, err := in.ReadSlice('\n')
if err != nil { if err != nil {
......
...@@ -532,7 +532,7 @@ func calc_rows() { ...@@ -532,7 +532,7 @@ func calc_rows() {
/* Calculate islands while solving the board. /* Calculate islands while solving the board.
*/ */
func boardHasIslands(cell int8) int8 { func boardHasIslands(cell int8) int8 {
/* Too low on board, don't bother checking */ /* Too low on board, don't bother checking */
if cell >= 40 { if cell >= 40 {
......
...@@ -40,7 +40,6 @@ import ( ...@@ -40,7 +40,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"regexp" "regexp"
"strings"
) )
var variants = []string{ var variants = []string{
...@@ -101,7 +100,7 @@ func main() { ...@@ -101,7 +100,7 @@ func main() {
fmt.Printf("%s %d\n", s, countMatches(s, bytes)) fmt.Printf("%s %d\n", s, countMatches(s, bytes))
} }
for _, sub := range substs { for _, sub := range substs {
bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl)) bytes = regexp.MustCompile(sub.pat).ReplaceAll(bytes, []byte(sub.repl))
} }
fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes)) fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment