func (c *typeConv) intExpr(n int64) ast.Expr {
return &ast.BasicLit{
Kind: token.INT,
- Value: strings.Bytes(strconv.Itoa64(n)),
+ Value: []byte(strconv.Itoa64(n)),
}
}
used[f.Name] = true
}
for cid, goid := range ident {
- if token.Lookup(strings.Bytes(goid)).IsKeyword() {
+ if token.Lookup([]byte(goid)).IsKeyword() {
// Avoid keyword
goid = "_" + goid
"io/ioutil"
"os"
"path"
- "strings"
)
// Markers around EBNF sections in .html files
var (
- open = strings.Bytes(`<pre class="ebnf">`)
- close = strings.Bytes(`</pre>`)
+ open = []byte(`<pre class="ebnf">`)
+ close = []byte(`</pre>`)
)
func htmlEscape(s string) string {
var buf bytes.Buffer
- template.HTMLEscape(&buf, strings.Bytes(s))
+ template.HTMLEscape(&buf, []byte(s))
return buf.String()
}
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() {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
}
func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) {
- text = strings.Bytes(tok.String())
+ text = []byte(tok.String())
return
}
// ----------------------------------------------------------------------------
// Tab conversion
-var spaces = strings.Bytes(" ") // 16 spaces seems like a good number
+var spaces = []byte(" ") // 16 spaces seems like a good number
const (
indenting = iota
case []byte:
writeText(w, v, html)
case string:
- writeText(w, strings.Bytes(v), html)
+ writeText(w, []byte(v), html)
case ast.Decl, ast.Expr, ast.Stmt, *ast.File:
writeNode(w, x, html, &defaultStyler)
default:
if strings.HasPrefix(relpath, "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":
- template.HTMLEscape(w, strings.Bytes("/"+relpath))
+ template.HTMLEscape(w, []byte("/"+relpath))
case "url-pos":
// line id's in html-printed source are of the
// 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)
}
}
// Template formatter for "time" format.
func timeFmt(w io.Writer, x interface{}, format string) {
// 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()))
}
// Template formatter for "localname" format.
func localnameFmt(w io.Writer, x interface{}, format string) {
_, localname := pathutil.Split(x.(string))
- template.HTMLEscape(w, strings.Bytes(localname))
+ template.HTMLEscape(w, []byte(localname))
}
// Files
var (
- tagBegin = strings.Bytes("<!--")
- tagEnd = strings.Bytes("-->")
+ tagBegin = []byte("<!--")
+ tagEnd = []byte("-->")
)
// commentText returns the text of the first HTML comment in src.
// if it begins with "<!DOCTYPE " assume it is standalone
// html that doesn't need the template wrapping.
- if bytes.HasPrefix(src, strings.Bytes("<!DOCTYPE ")) {
+ if bytes.HasPrefix(src, []byte("<!DOCTYPE ")) {
c.Write(src)
return
}
func isIdentifier(s string) bool {
var S scanner.Scanner
- S.Init("", strings.Bytes(s), nil, 0)
+ S.Init("", []byte(s), nil, 0)
if _, tok, _ := S.Scan(); tok == token.IDENT {
_, tok, _ := S.Scan()
return tok == token.EOF
"go/ast"
"go/printer"
"fmt"
- "strings"
)
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 {
tag = printer.HTMLTag{"<span class=highlight>", "</span>"}
}
"go/scanner"
"go/token"
"io"
- "strings"
)
// Markers around EBNF sections
var (
- openTag = strings.Bytes(`<pre class="ebnf">`)
- closeTag = strings.Bytes(`</pre>`)
+ openTag = []byte(`<pre class="ebnf">`)
+ closeTag = []byte(`</pre>`)
)
"io"
"os"
"reflect"
- "strings"
"testing"
)
if _, err := io.ReadFull(tr, buf); err != nil {
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)
}
if _, err := io.ReadFull(tr, buf); err != nil {
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)
}
}
"io"
"os"
"strconv"
- "strings"
)
var (
}
return
}
- for i, ch := range strings.Bytes(s) {
+ for i, ch := range []byte(s) {
b[i] = ch
}
if len(s) < len(b) {
s := slicer(header)
// TODO(dsymonds): handle names longer than 100 chars
- copy(s.next(100), strings.Bytes(hdr.Name))
-
- tw.octal(s.next(8), hdr.Mode) // 100:108
- tw.numeric(s.next(8), hdr.Uid) // 108:116
- tw.numeric(s.next(8), hdr.Gid) // 116:124
- tw.numeric(s.next(12), hdr.Size) // 124:136
- tw.numeric(s.next(12), hdr.Mtime) // 136:148
- s.next(8) // chksum (148:156)
- s.next(1)[0] = hdr.Typeflag // 156:157
- s.next(100) // linkname (157:257)
- copy(s.next(8), strings.Bytes("ustar\x0000")) // 257:265
- tw.cString(s.next(32), hdr.Uname) // 265:297
- tw.cString(s.next(32), hdr.Gname) // 297:329
- tw.numeric(s.next(8), hdr.Devmajor) // 329:337
- tw.numeric(s.next(8), hdr.Devminor) // 337:345
+ copy(s.next(100), []byte(hdr.Name))
+
+ tw.octal(s.next(8), hdr.Mode) // 100:108
+ tw.numeric(s.next(8), hdr.Uid) // 108:116
+ tw.numeric(s.next(8), hdr.Gid) // 116:124
+ tw.numeric(s.next(12), hdr.Size) // 124:136
+ tw.numeric(s.next(12), hdr.Mtime) // 136:148
+ s.next(8) // chksum (148:156)
+ s.next(1)[0] = hdr.Typeflag // 156:157
+ s.next(100) // linkname (157:257)
+ copy(s.next(8), []byte("ustar\x0000")) // 257:265
+ tw.cString(s.next(32), hdr.Uname) // 265:297
+ tw.cString(s.next(32), hdr.Gname) // 297:329
+ tw.numeric(s.next(8), hdr.Devmajor) // 329:337
+ tw.numeric(s.next(8), hdr.Devminor) // 337:345
// Use the GNU magic instead of POSIX magic if we used any GNU extensions.
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.
import (
"bytes"
"reflect"
- "strings"
"testing"
"time"
)
func TestTime(t *testing.T) {
for i, test := range timeTestData {
- ret, err := parseUTCTime(strings.Bytes(test.in))
+ ret, err := parseUTCTime([]byte(test.in))
if (err == nil) != test.ok {
t.Errorf("#%d: Incorrect error result (did fail? %v, expected: %v)", i, err == nil, test.ok)
}
"io"
"os"
"reflect"
- "strings"
"time"
)
}
func marshalPrintableString(out *forkableWriter, s string) (err os.Error) {
- b := strings.Bytes(s)
+ b := []byte(s)
for _, c := range b {
if !isPrintable(c) {
return StructuralError{"PrintableString contains invalid character"}
}
func marshalIA5String(out *forkableWriter, s string) (err os.Error) {
- b := strings.Bytes(s)
+ b := []byte(s)
for _, c := range b {
if c > 127 {
return StructuralError{"IA5String contains invalid character"}
func TestWriteErrors(t *testing.T) {
for _, w := range errorWriterTests {
buf := NewWriter(w)
- _, e := buf.Write(strings.Bytes("hello world"))
+ _, e := buf.Write([]byte("hello world"))
if e != nil {
t.Errorf("Write hello to %v: %v", w, e)
continue
import (
. "bytes"
- "strings"
"testing"
"unicode"
)
func TestCompare(t *testing.T) {
for _, tt := range comparetests {
- a := strings.Bytes(tt.a)
- b := strings.Bytes(tt.b)
+ a := []byte(tt.a)
+ b := []byte(tt.b)
cmp := Compare(a, b)
eql := Equal(a, b)
if cmp != tt.i {
func TestIndex(t *testing.T) {
for _, tt := range indextests {
- a := strings.Bytes(tt.a)
- b := strings.Bytes(tt.b)
+ a := []byte(tt.a)
+ b := []byte(tt.b)
pos := Index(a, b)
if pos != tt.i {
t.Errorf(`Index(%q, %q) = %v`, tt.a, tt.b, pos)
if len(tt.b) != 1 {
continue
}
- a := strings.Bytes(tt.a)
+ a := []byte(tt.a)
b := tt.b[0]
pos := IndexByte(a, b)
if pos != tt.i {
func TestExplode(t *testing.T) {
for _, tt := range explodetests {
- a := Split(strings.Bytes(tt.s), nil, tt.n)
+ a := Split([]byte(tt.s), nil, tt.n)
result := arrayOfString(a)
if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a)
func TestSplit(t *testing.T) {
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)
if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
continue
}
- s := Join(a, strings.Bytes(tt.sep))
+ s := Join(a, []byte(tt.sep))
if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
}
func TestSplitAfter(t *testing.T) {
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)
if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
func TestFields(t *testing.T) {
for _, tt := range fieldstests {
- a := Fields(strings.Bytes(tt.s))
+ a := Fields([]byte(tt.s))
result := arrayOfString(a)
if !eq(result, tt.a) {
t.Errorf("Fields(%q) = %v; want %v", tt.s, a, tt.a)
for i := 0; i < len(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 {
t.Errorf("Add(%q,%q) = %q", test.s, test.t, string(b))
}
func TestRepeat(t *testing.T) {
for _, tt := range RepeatTests {
- tin := strings.Bytes(tt.in)
- tout := strings.Bytes(tt.out)
+ tin := []byte(tt.in)
+ tout := []byte(tt.out)
a := Repeat(tin, tt.count)
if !Equal(a, tout) {
t.Errorf("Repeat(%q, %d) = %q; want %q", tin, tt.count, a, tout)
func TestRunes(t *testing.T) {
for _, tt := range RunesTests {
- tin := strings.Bytes(tt.in)
+ tin := []byte(tt.in)
a := Runes(tin)
if !runesEqual(a, tt.out) {
t.Errorf("Runes(%q) = %v; want %v", tin, a, tt.out)
import (
"io"
"io/ioutil"
- "strings"
"testing"
)
pipe(t,
func(deflater *Deflater) {
deflater.Comment = "comment"
- deflater.Extra = strings.Bytes("extra")
+ deflater.Extra = []byte("extra")
deflater.Mtime = 1e8
deflater.Name = "name"
- _, err := deflater.Write(strings.Bytes("payload"))
+ _, err := deflater.Write([]byte("payload"))
if err != nil {
t.Fatalf("%v", err)
}
import (
"hash"
"fmt"
- "strings"
"testing"
)
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
},
- strings.Bytes("Sample #1"),
+ []byte("Sample #1"),
"4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a",
},
hmacTest{
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43,
},
- strings.Bytes("Sample #2"),
+ []byte("Sample #2"),
"0922d3405faa3d194f82a45830737d5cc6c75d24",
},
hmacTest{
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3,
},
- strings.Bytes("Sample #3"),
+ []byte("Sample #3"),
"bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa",
},
// Test from Plan 9.
hmacTest{
NewMD5,
- strings.Bytes("Jefe"),
- strings.Bytes("what do ya want for nothing?"),
+ []byte("Jefe"),
+ []byte("what do ya want for nothing?"),
"750c783e6ab0b503eaa86e310a5db738",
},
}
"encoding/hex"
"os"
"io"
- "strings"
"testing"
"testing/quick"
)
func decodeBase64(in string) []byte {
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 {
return nil
}
if err != nil {
t.Errorf("#%d error decrypting", i)
}
- want := strings.Bytes(test.out)
+ want := []byte(test.out)
if bytes.Compare(out, want) != 0 {
t.Errorf("#%d got:%#v want:%#v", i, out, want)
}
func TestEncryptPKCS1v15SessionKey(t *testing.T) {
for i, test := range decryptPKCS1v15SessionKeyTests {
- key := strings.Bytes("FAIL")
+ key := []byte("FAIL")
err := DecryptPKCS1v15SessionKey(nil, rsaPrivateKey, decodeBase64(test.in), key)
if err != nil {
t.Errorf("#%d error decrypting", i)
}
- want := strings.Bytes(test.out)
+ want := []byte(test.out)
if bytes.Compare(key, want) != 0 {
t.Errorf("#%d got:%#v want:%#v", i, key, want)
}
func TestSignPKCS1v15(t *testing.T) {
for i, test := range signPKCS1v15Tests {
h := sha1.New()
- h.Write(strings.Bytes(test.in))
+ h.Write([]byte(test.in))
digest := h.Sum()
s, err := SignPKCS1v15(nil, rsaPrivateKey, HashSHA1, digest)
func TestVerifyPKCS1v15(t *testing.T) {
for i, test := range signPKCS1v15Tests {
h := sha1.New()
- h.Write(strings.Bytes(test.in))
+ h.Write([]byte(test.in))
digest := h.Sum()
sig, _ := hex.DecodeString(test.out)
package tls
-import "strings"
-
type clientHelloMsg struct {
raw []byte
major, minor uint8
z[1] = 1
z[3] = byte(len(m.serverName) >> 8)
z[4] = byte(len(m.serverName))
- copy(z[5:], strings.Bytes(m.serverName))
+ copy(z[5:], []byte(m.serverName))
z = z[l:]
}
l = 255
}
z[0] = byte(l)
- copy(z[1:], strings.Bytes(v[0:l]))
+ copy(z[1:], []byte(v[0:l]))
z = z[1+l:]
}
}
y := x[4:]
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[0] = byte(padding)
"crypto/sha1"
"hash"
"os"
- "strings"
)
// Split a premaster secret in two as specified in RFC 4346, section 5.
finishedVerifyLength = 12 // Length of verify_data in a Finished message.
)
-var masterSecretLabel = strings.Bytes("master secret")
-var keyExpansionLabel = strings.Bytes("key expansion")
-var clientFinishedLabel = strings.Bytes("client finished")
-var serverFinishedLabel = strings.Bytes("server finished")
+var masterSecretLabel = []byte("master secret")
+var keyExpansionLabel = []byte("key expansion")
+var clientFinishedLabel = []byte("client finished")
+var serverFinishedLabel = []byte("server finished")
// keysFromPreMasterSecret generates the connection keys from the pre master
// secret, given the lengths of the MAC and cipher keys, as defined in RFC
ret[n].Id = oidExtensionSubjectAltName
rawValues := make([]asn1.RawValue, len(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)
if err != nil {
"encoding/pem"
"os"
"reflect"
- "strings"
"testing"
"time"
)
func TestParsePKCS1PrivateKey(t *testing.T) {
- block, _ := pem.Decode(strings.Bytes(pemPrivateKey))
+ block, _ := pem.Decode([]byte(pemPrivateKey))
priv, err := ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
t.Errorf("Failed to parse private key: %s", err)
t.Errorf("failed to open /dev/urandom")
}
- block, _ := pem.Decode(strings.Bytes(pemPrivateKey))
+ block, _ := pem.Decode([]byte(pemPrivateKey))
priv, err := ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
t.Errorf("Failed to parse private key: %s", err)
import (
"io/ioutil"
- "strings"
"testing"
)
func TestGrammars(t *testing.T) {
for _, src := range grammars {
- check(t, "", strings.Bytes(src))
+ check(t, "", []byte(src))
}
}
"bytes"
"io/ioutil"
"os"
- "strings"
"testing"
)
func TestEncode(t *testing.T) {
for _, p := range pairs {
buf := make([]byte, MaxEncodedLen(len(p.decoded)))
- n := Encode(buf, strings.Bytes(p.decoded))
+ n := Encode(buf, []byte(p.decoded))
buf = buf[0:n]
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(string(buf)), strip85(p.encoded))
}
for _, p := range pairs {
bb := &bytes.Buffer{}
encoder := NewEncoder(bb)
- encoder.Write(strings.Bytes(p.decoded))
+ encoder.Write([]byte(p.decoded))
encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, strip85(bb.String()), strip85(p.encoded))
}
}
func TestEncoderBuffering(t *testing.T) {
- input := strings.Bytes(bigtest.decoded)
+ input := []byte(bigtest.decoded)
for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{}
encoder := NewEncoder(bb)
func TestDecode(t *testing.T) {
for _, p := range pairs {
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) = nsrc %v, want %v", p.encoded, nsrc, len(p.encoded))
testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded))
for _, e := range examples {
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) {
case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
"bytes"
"io/ioutil"
"os"
- "strings"
"testing"
)
func TestEncode(t *testing.T) {
for _, p := range pairs {
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)
}
}
for _, p := range pairs {
bb := &bytes.Buffer{}
encoder := NewEncoder(StdEncoding, bb)
- encoder.Write(strings.Bytes(p.decoded))
+ encoder.Write([]byte(p.decoded))
encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded)
}
}
func TestEncoderBuffering(t *testing.T) {
- input := strings.Bytes(bigtest.decoded)
+ input := []byte(bigtest.decoded)
for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{}
encoder := NewEncoder(StdEncoding, bb)
func TestDecode(t *testing.T) {
for _, p := range pairs {
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) = length %v, want %v", p.encoded, count, len(p.decoded))
if len(p.encoded) > 0 {
for _, e := range examples {
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) {
case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
"bytes"
"io/ioutil"
"os"
- "strings"
"testing"
)
func TestEncode(t *testing.T) {
for _, p := range gitPairs {
buf := make([]byte, EncodedLen(len(p.decoded)))
- n := Encode(buf, strings.Bytes(p.decoded))
+ n := Encode(buf, []byte(p.decoded))
if n != len(buf) {
t.Errorf("EncodedLen does not agree with Encode")
}
for _, p := range gitPairs {
bb := &bytes.Buffer{}
encoder := NewEncoder(bb)
- encoder.Write(strings.Bytes(p.decoded))
+ encoder.Write([]byte(p.decoded))
encoder.Close()
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, bb.String(), p.encoded)
}
}
func TestEncoderBuffering(t *testing.T) {
- input := strings.Bytes(gitBigtest.decoded)
+ input := []byte(gitBigtest.decoded)
for bs := 1; bs <= 12; bs++ {
bb := &bytes.Buffer{}
encoder := NewEncoder(bb)
func TestDecode(t *testing.T) {
for _, p := range gitPairs {
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) = 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)
for _, e := range examples {
dbuf := make([]byte, 2*len(e.e))
- _, err := Decode(dbuf, strings.Bytes(e.e))
+ _, err := Decode(dbuf, []byte(e.e))
switch err := err.(type) {
case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
import (
"os"
"strconv"
- "strings"
)
const hextable = "0123456789abcdef"
// DecodeString returns the bytes represented by the hexadecimal string s.
func DecodeString(s string) ([]byte, os.Error) {
- src := strings.Bytes(s)
+ src := []byte(s)
dst := make([]byte, DecodedLen(len(src)))
_, err := Decode(dst, src)
if err != nil {
"encoding/base64"
"io"
"os"
- "strings"
)
// A Block represents a PEM encoded structure.
return result[0:n]
}
-var pemStart = strings.Bytes("\n-----BEGIN ")
-var pemEnd = strings.Bytes("\n-----END ")
-var pemEndOfLine = strings.Bytes("-----")
+var pemStart = []byte("\n-----BEGIN ")
+var pemEnd = []byte("\n-----END ")
+var pemEndOfLine = []byte("-----")
// 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
if err != nil {
return
}
- _, err = out.Write(strings.Bytes(b.Type + "-----\n"))
+ _, err = out.Write([]byte(b.Type + "-----\n"))
if err != nil {
return
}
for k, v := range b.Headers {
- _, err = out.Write(strings.Bytes(k + ": " + v + "\n"))
+ _, err = out.Write([]byte(k + ": " + v + "\n"))
if err != nil {
return
}
if err != nil {
return
}
- _, err = out.Write(strings.Bytes(b.Type + "-----\n"))
+ _, err = out.Write([]byte(b.Type + "-----\n"))
return
}
import (
"bytes"
"reflect"
- "strings"
"testing"
)
func TestGetLine(t *testing.T) {
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 {
t.Errorf("#%d got:%+v,%+v want:%s,%s", i, x, y, test.out1, test.out2)
}
}
func TestDecode(t *testing.T) {
- result, remainder := Decode(strings.Bytes(pemData))
+ result, remainder := Decode([]byte(pemData))
if !reflect.DeepEqual(result, certificate) {
t.Errorf("#0 got:%#v want:%#v", result, certificate)
}
if !reflect.DeepEqual(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) {
t.Errorf("#2 got:%#v want:%#v", result, privateKey2)
}
buf := bytes.NewBuffer(nil)
var breaker lineBreaker
breaker.out = buf
- _, err := breaker.Write(strings.Bytes(test.in))
+ _, err := breaker.Write([]byte(test.in))
if err != nil {
t.Errorf("#%d: error from Write: %s", i, err)
continue
breaker.out = buf
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 {
t.Errorf("#%d: error from Write (byte by byte): %s", i, err)
continue
import (
"fmt"
- "strings"
"testing"
)
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 {
t.Errorf("Parse(%s): %v", form, err)
return nil
case "nil":
return false
case "testing.T":
- s.Write(strings.Bytes("testing.T"))
+ s.Write([]byte("testing.T"))
return true
}
panic("unreachable")
func (p *parser) parseLiteral() literal {
- s := strings.Bytes(p.parseString())
+ s := []byte(p.parseString())
// A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments
"log"
"os"
"runtime"
- "strings"
"time"
"./pdp1"
)
var m SpacewarPDP1
m.Init(w)
m.PC = 4
- f := bytes.NewBuffer(strings.Bytes(spacewarCode))
+ f := bytes.NewBuffer([]byte(spacewarCode))
if err = m.Load(f); err != nil {
log.Exitf("loading %s: %s", "spacewar.lst", err)
}
fmtTest{"%q", "abc", `"abc"`},
// basic bytes
- fmtTest{"%s", strings.Bytes("abc"), "abc"},
- fmtTest{"%x", strings.Bytes("abc"), "616263"},
- fmtTest{"% x", strings.Bytes("abc"), "61 62 63"},
- fmtTest{"%x", strings.Bytes("xyz"), "78797a"},
- fmtTest{"%X", strings.Bytes("xyz"), "78797A"},
- fmtTest{"%q", strings.Bytes("abc"), `"abc"`},
+ fmtTest{"%s", []byte("abc"), "abc"},
+ fmtTest{"%x", []byte("abc"), "616263"},
+ fmtTest{"% x", []byte("abc"), "61 62 63"},
+ fmtTest{"%x", []byte("xyz"), "78797a"},
+ fmtTest{"%X", []byte("xyz"), "78797A"},
+ fmtTest{"%q", []byte("abc"), `"abc"`},
// escaped strings
fmtTest{"%#q", `abc`, "`abc`"},
var (
- ldquo = strings.Bytes("“")
- rdquo = strings.Bytes("”")
+ ldquo = []byte("“")
+ rdquo = []byte("”")
)
// Escape comment text for HTML.
var (
- html_p = strings.Bytes("<p>\n")
- html_endp = strings.Bytes("</p>\n")
- html_pre = strings.Bytes("<pre>")
- html_endpre = strings.Bytes("</pre>\n")
+ html_p = []byte("<p>\n")
+ html_endp = []byte("</p>\n")
+ html_pre = []byte("<pre>")
+ html_endpre = []byte("</pre>\n")
)
"io/ioutil"
"os"
pathutil "path"
- "strings"
)
if src != nil {
switch s := src.(type) {
case string:
- return strings.Bytes(s), nil
+ return []byte(s), nil
case []byte:
return s, nil
case *bytes.Buffer:
"bytes"
"go/ast"
"go/token"
- "strings"
)
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)}}})
}
"os"
"reflect"
"runtime"
- "strings"
"tabwriter"
)
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
- esc_quot = strings.Bytes(""") // shorter than """
- esc_apos = strings.Bytes("'") // shorter than "'"
- esc_amp = strings.Bytes("&")
- esc_lt = strings.Bytes("<")
- esc_gt = strings.Bytes(">")
+ esc_quot = []byte(""") // shorter than """
+ esc_apos = []byte("'") // shorter than "'"
+ esc_amp = []byte("&")
+ esc_lt = []byte("<")
+ esc_gt = []byte(">")
)
// write start tag, if any
// (no html-escaping and no p.pos update for tags - use write0)
if tag.Start != "" {
- p.write0(strings.Bytes(tag.Start))
+ p.write0([]byte(tag.Start))
}
p.write(data)
// write end tag, if any
if tag.End != "" {
- p.write0(strings.Bytes(tag.End))
+ p.write0([]byte(tag.End))
}
}
}
if debug {
// 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 {
// write line tag if on a new line
if p.Styler != nil {
data, tag = p.Styler.Ident(x)
} else {
- data = strings.Bytes(x.Name())
+ data = []byte(x.Name())
}
case *ast.BasicLit:
if p.Styler != nil {
// (note that valid Go programs cannot contain esc ('\xff')
// bytes since they do not appear in legal UTF-8 sequences)
// TODO(gri): do this more efficiently.
- data = strings.Bytes("\xff" + string(data) + "\xff")
+ data = []byte("\xff" + string(data) + "\xff")
case token.Token:
if p.Styler != nil {
data, tag = p.Styler.Token(x)
} else {
- data = strings.Bytes(x.String())
+ data = []byte(x.String())
}
isKeyword = x.IsKeyword()
case token.Position:
import (
"go/token"
"os"
- "strings"
"testing"
)
// verify scan
index := 0
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 {
e := elt{token.EOF, "", special}
if index < len(tokens) {
func checkSemi(t *testing.T, line string, mode uint) {
var S Scanner
- S.Init("TestSemis", strings.Bytes(line), nil, mode)
+ S.Init("TestSemis", []byte(line), nil, mode)
pos, tok, lit := S.Scan()
for tok != token.EOF {
if tok == token.ILLEGAL {
// verify scan
var S Scanner
- S.Init("TestLineComments", strings.Bytes(src), nil, 0)
+ S.Init("TestLineComments", []byte(src), nil, 0)
for _, s := range segments {
pos, _, lit := S.Scan()
checkPos(t, string(lit), pos, token.Position{s.filename, pos.Offset, s.line, pos.Column})
var s Scanner
// 1st init
- s.Init("", strings.Bytes("if true { }"), nil, 0)
+ s.Init("", []byte("if true { }"), nil, 0)
s.Scan() // if
s.Scan() // true
_, tok, _ := s.Scan() // {
}
// 2nd init
- s.Init("", strings.Bytes("go true { ]"), nil, 0)
+ s.Init("", []byte("go true { ]"), nil, 0)
_, tok, _ = s.Scan() // go
if tok != token.GO {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO)
var s Scanner
const src = "*?*$*@*"
- s.Init("", strings.Bytes(src), &testErrorHandler{t}, AllowIllegalChars)
+ s.Init("", []byte(src), &testErrorHandler{t}, AllowIllegalChars)
for offs, ch := range src {
pos, tok, lit := s.Scan()
if pos.Offset != offs {
"@ @ @" // original file, line 1 again
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 {
return tok != token.EOF
})
func checkError(t *testing.T, src string, tok token.Token, pos int, err string) {
var s Scanner
var h errorCollector
- s.Init("", strings.Bytes(src), &h, ScanComments)
+ s.Init("", []byte(src), &h, ScanComments)
_, tok0, _ := s.Scan()
_, tok1, _ := s.Scan()
if tok0 != tok {
// bytes == []uint8
{
b.Reset()
- data := struct{ a []byte }{strings.Bytes("hello")}
+ data := struct{ a []byte }{[]byte("hello")}
instr := &encInstr{encUint8Array, 6, 0, 0}
state := newencoderState(b)
instr.op(instr, state, unsafe.Pointer(&data))
strs: &[2]string{s1, s2},
int64s: &[]int64{77, 89, 123412342134},
s: "Now is the time",
- y: strings.Bytes("hello, sailor"),
+ y: []byte("hello, sailor"),
t: &T2{"this is T2"},
}
b := new(bytes.Buffer)
it0.ignore_e[2] = 3.0
it0.ignore_f = true
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"}
b := new(bytes.Buffer)
if len(info) > 0 {
enc := base64.URLEncoding
encoded := make([]byte, enc.EncodedLen(len(info)))
- enc.Encode(encoded, strings.Bytes(info))
+ enc.Encode(encoded, []byte(info))
if req.Header == nil {
req.Header = make(map[string]string)
}
package http
-import (
- "strings"
-)
-
// This file deals with lexical matters of HTTP
func isSeparator(c byte) bool {
// the input string might be parsed. result is always non-nil.
func httpSplitFieldValue(fv string) (eaten int, result []string) {
result = make([]string, 0, len(fv))
- raw := strings.Bytes(fv)
+ raw := []byte(fv)
i := 0
chunk := ""
for i < len(raw) {
// and upper case after each dash.
// (Host, User-Agent, If-Modified-Since).
// HTTP headers are ASCII only, so no Unicode issues.
- a := strings.Bytes(s)
+ a := []byte(s)
upper := true
for i, v := range a {
if upper && 'a' <= v && v <= 'z' {
// CanonicalPath applies the algorithm specified in RFC 2396 to
// simplify the path, removing unnecessary . and .. elements.
func CanonicalPath(path string) string {
- buf := strings.Bytes(path)
+ buf := []byte(path)
a := buf[0:0]
// state helps to find /.. ^.. ^. and /. patterns.
// state == 1 - prev char is '/' or beginning of the string.
// abstract the functionality, plus some other related primitives.
package io
-import (
- "os"
- "strings"
-)
+import "os"
// Error represents an unexpected I/O behavior.
type Error struct {
// 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) {
- 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.
import (
. "io/ioutil"
"os"
- "strings"
"testing"
)
"build bigger and better idiot-proof programs, and the Universe trying " +
"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)
}
"fmt"
. "io"
"os"
- "strings"
"testing"
"time"
)
c := make(chan int)
r, w := Pipe()
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)
if err != nil {
t.Errorf("read: %v", err)
import (
"flag"
"io"
- "strings"
"syscall"
"testing"
)
// fd is already connected to the destination, port 80.
// Run an HTTP request to fetch the appropriate page.
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)
buf := make([]byte, 1000)
var b []byte
if !isEmpty {
- b = strings.Bytes("hello, world\n")
+ b = []byte("hello, world\n")
}
var b1 [100]byte
}
checkSize(t, Path, 0)
- fd.Write(strings.Bytes("hello, world\n"))
+ fd.Write([]byte("hello, world\n"))
checkSize(t, Path, 13)
fd.Truncate(10)
checkSize(t, Path, 10)
checkSize(t, Path, 1024)
fd.Truncate(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.
fd.Close()
Remove(Path)
const data = "hello, world\n"
io.WriteString(f, data)
- n, err := f.WriteAt(strings.Bytes("WORLD"), 7)
+ n, err := f.WriteAt([]byte("WORLD"), 7)
if err != nil || n != 5 {
t.Fatalf("WriteAt 7: %d, %v", n, err)
}
// TODO(rsc): test Apply
-import (
- "strings"
- "testing"
-)
+import "testing"
type Test struct {
in string
func TestFileApply(t *testing.T) {
for i, test := range tests {
- set, err := Parse(strings.Bytes(test.diff))
+ set, err := Parse([]byte(test.diff))
if err != nil {
t.Errorf("#%d: Parse: %s", i, err)
continue
t.Errorf("#%d: Parse returned %d patches, want 1", i, len(set.File))
continue
}
- new, err := set.File[0].Apply(strings.Bytes(test.in))
+ new, err := set.File[0].Apply([]byte(test.in))
if err != nil {
t.Errorf("#%d: Apply: %s", i, err)
continue
// writing to buf; w is index of next byte to write.
// dotdot is index in buf where .. must stop, either because
// it is the leading slash or it is a leading ../../.. prefix.
- buf := strings.Bytes(path)
+ buf := []byte(path)
r, w, dotdot := 0, 0, 0
if rooted {
r, w, dotdot = 1, 1, 1
printVec(t, match)
}
// now try bytes
- m = re.Execute(strings.Bytes(str))
+ m = re.Execute([]byte(str))
if !equal(m, match) {
t.Errorf("Execute failure on %#q matching %q:", expr, str)
printVec(t, m)
t.Errorf("MatchString failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0)
}
// now try bytes
- m = re.Match(strings.Bytes(str))
+ m = re.Match([]byte(str))
if m != (len(match) > 0) {
t.Errorf("Match failure on %#q matching %q: %t should be %t", expr, str, m, len(match) > 0)
}
tc.pattern, tc.input, tc.replacement, actual, tc.output)
}
// 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 {
t.Errorf("%q.Replace(%q,%q) = %q; want %q",
tc.pattern, tc.input, tc.replacement, actual, tc.output)
case "matchit":
result = make([]string, len(c.input)+1)
i := 0
- b := strings.Bytes(c.input)
+ b := []byte(c.input)
for match := range re.AllMatchesIter(b, c.n) {
result[i] = string(match)
i++
result = result[0:i]
case "match":
result = make([]string, len(c.input)+1)
- b := strings.Bytes(c.input)
+ b := []byte(c.input)
i := 0
for _, match := range re.AllMatches(b, c.n) {
result[i] = string(match)
}
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
-}
func TestRunes(t *testing.T) {
for _, tt := range RunesTests {
- a := Runes(tt.in)
+ a := []int(tt.in)
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
}
if !tt.lossy {
// can only test reassembly if we didn't lose information
s := string(a)
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)
}
}
}
"bytes"
"fmt"
"io"
- "strings"
)
// StringFormatter formats into the default string representation.
}
var (
- esc_quot = strings.Bytes(""") // shorter than """
- esc_apos = strings.Bytes("'") // shorter than "'"
- esc_amp = strings.Bytes("&")
- esc_lt = strings.Bytes("<")
- esc_gt = strings.Bytes(">")
+ esc_quot = []byte(""") // shorter than """
+ esc_apos = []byte("'") // shorter than "'"
+ esc_amp = []byte("&")
+ esc_lt = []byte("<")
+ esc_gt = []byte(">")
)
// HTMLEscape writes to w the properly escaped HTML equivalent
if !validDelim(t.ldelim) || !validDelim(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.linenum = 1
t.parse()
// delimiters are very rarely invalid and Parse has the necessary
// error-handling interface already.
func (t *Template) SetDelims(left, right string) {
- t.ldelim = strings.Bytes(left)
- t.rdelim = strings.Bytes(right)
+ t.ldelim = []byte(left)
+ t.rdelim = []byte(right)
}
// Parse creates a Template with default parameters (such as {} for
"container/vector"
"fmt"
"io"
- "strings"
"testing"
)
s.stringmap = make(map[string]string)
s.stringmap["stringkey1"] = "stringresult" // the same value so repeated section is order-independent
s.stringmap["stringkey2"] = "stringresult"
- s.bytes = strings.Bytes("hello")
+ s.bytes = []byte("hello")
s.iface = []int{1, 2, 3}
var buf bytes.Buffer
package testing
-import (
- "strings"
-)
-
var good_re = []string{
``,
`.`,
printVec(t, match)
}
// now try bytes
- m = re.Execute(strings.Bytes(str))
+ m = re.Execute([]byte(str))
if !equal(m, match) {
t.Error("Execute failure on `", expr, "` matching `", str, "`:")
printVec(t, m)
t.Error("MatchString failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0)
}
// now try bytes
- m = re.Match(strings.Bytes(str))
+ m = re.Match([]byte(str))
if m != (len(match) > 0) {
t.Error("Match failure on `", expr, "` matching `", str, "`:", m, "should be", len(match) > 0)
}
printStrings(t, strs)
}
// now try bytes
- s := re.MatchSlices(strings.Bytes(str))
+ s := re.MatchSlices([]byte(str))
if !equalBytes(s, strs) {
t.Error("MatchSlices failure on `", expr, "` matching `", str, "`:")
printBytes(t, s)
import (
"bytes"
- "strings"
"testing"
. "utf8"
)
// strings.Bytes with one extra byte at end
func makeBytes(s string) []byte {
s += "\x00"
- b := strings.Bytes(s)
+ b := []byte(s)
return b[0 : len(s)-1]
}
}
func BenchmarkDecodeJapaneseRune(b *testing.B) {
- nihon := strings.Bytes("本")
+ nihon := []byte("本")
for i := 0; i < b.N; i++ {
DecodeRune(nihon)
}
"log"
"net"
"once"
- "strings"
"testing"
)
t.Errorf("WebSocket handshake error", err)
return
}
- msg := strings.Bytes("hello, world\n")
+ msg := []byte("hello, world\n")
if _, err := ws.Write(msg); err != nil {
t.Errorf("Write: error %v", err)
}
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.
func (c *Conn) sendUInt32List(list []uint32) {
put16(buf[6:], uint16(len(authName)))
put16(buf[8:], uint16(len(authData)))
put16(buf[10:], 0)
- copy(buf[12:], strings.Bytes(authName))
+ copy(buf[12:], []byte(authName))
copy(buf[12+pad(len(authName)):], authData)
if _, err = c.conn.Write(buf); err != nil {
return nil, err
p.err = SyntaxError("invalid character entity &" + s + ";")
return nil
}
- p.buf.Write(strings.Bytes(text))
+ p.buf.Write([]byte(text))
b0, b1 = 0, 0
continue Input
}
}
var (
- esc_quot = strings.Bytes(""") // shorter than """
- esc_apos = strings.Bytes("'") // shorter than "'"
- esc_amp = strings.Bytes("&")
- esc_lt = strings.Bytes("<")
- esc_gt = strings.Bytes(">")
+ esc_quot = []byte(""") // shorter than """
+ esc_apos = []byte("'") // shorter than "'"
+ esc_amp = []byte("&")
+ esc_lt = []byte("<")
+ esc_gt = []byte(">")
)
// Escape writes to w the properly escaped XML equivalent
"io"
"os"
"reflect"
- "strings"
"testing"
)
</body><!-- missing final newline -->`
var rawTokens = []Token{
- CharData(strings.Bytes("\n")),
- ProcInst{"xml", strings.Bytes(`version="1.0" encoding="UTF-8"`)},
- CharData(strings.Bytes("\n")),
- Directive(strings.Bytes(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`)),
- CharData(strings.Bytes("\n")),
+ CharData([]byte("\n")),
+ ProcInst{"xml", []byte(`version="1.0" encoding="UTF-8"`)},
+ CharData([]byte("\n")),
+ Directive([]byte(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`),
+ ),
+ CharData([]byte("\n")),
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"}}},
- CharData(strings.Bytes("World <>'\" 白鵬翔")),
+ CharData([]byte("World <>'\" 白鵬翔")),
EndElement{Name{"", "hello"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
StartElement{Name{"", "goodbye"}, nil},
EndElement{Name{"", "goodbye"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
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},
EndElement{Name{"", "inner"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
EndElement{Name{"", "outer"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
StartElement{Name{"tag", "name"}, nil},
- CharData(strings.Bytes("\n ")),
- CharData(strings.Bytes("Some text here.")),
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
+ CharData([]byte("Some text here.")),
+ CharData([]byte("\n ")),
EndElement{Name{"tag", "name"}},
- CharData(strings.Bytes("\n")),
+ CharData([]byte("\n")),
EndElement{Name{"", "body"}},
- Comment(strings.Bytes(" missing final newline ")),
+ Comment([]byte(" missing final newline ")),
}
var cookedTokens = []Token{
- CharData(strings.Bytes("\n")),
- ProcInst{"xml", strings.Bytes(`version="1.0" encoding="UTF-8"`)},
- CharData(strings.Bytes("\n")),
- Directive(strings.Bytes(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`)),
- CharData(strings.Bytes("\n")),
+ CharData([]byte("\n")),
+ ProcInst{"xml", []byte(`version="1.0" encoding="UTF-8"`)},
+ CharData([]byte("\n")),
+ Directive([]byte(`DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"`),
+ ),
+ CharData([]byte("\n")),
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"}}},
- CharData(strings.Bytes("World <>'\" 白鵬翔")),
+ CharData([]byte("World <>'\" 白鵬翔")),
EndElement{Name{"ns2", "hello"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
StartElement{Name{"ns2", "goodbye"}, nil},
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"}}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
StartElement{Name{"ns2", "inner"}, nil},
EndElement{Name{"ns2", "inner"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
EndElement{Name{"ns2", "outer"}},
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
StartElement{Name{"ns3", "name"}, nil},
- CharData(strings.Bytes("\n ")),
- CharData(strings.Bytes("Some text here.")),
- CharData(strings.Bytes("\n ")),
+ CharData([]byte("\n ")),
+ CharData([]byte("Some text here.")),
+ CharData([]byte("\n ")),
EndElement{Name{"ns3", "name"}},
- CharData(strings.Bytes("\n")),
+ CharData([]byte("\n")),
EndElement{Name{"ns2", "body"}},
- Comment(strings.Bytes(" missing final newline ")),
+ Comment([]byte(" missing final newline ")),
}
var xmlInput = []string{
fmt.Println(msg)
tot := 0
// wait for all results
- for _ = range (cols) {
+ for _ = range cols {
result := <-ended
tot += result.met
fmt.Printf("%v%v\n", result.met, spell(result.same, true))
"bufio"
"flag"
"os"
- "strings"
)
var out *bufio.Writer
AccumulateProbabilities(iub)
AccumulateProbabilities(homosapiens)
- alu := strings.Bytes(
+ alu := []byte(
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
"io/ioutil"
"os"
"sort"
- "strings"
)
var in *bufio.Reader
func main() {
in = bufio.NewReader(os.Stdin)
- three := strings.Bytes(">THREE ")
+ three := []byte(">THREE ")
for {
line, err := in.ReadSlice('\n')
if err != nil {
/* Calculate islands while solving the board.
-*/
+ */
func boardHasIslands(cell int8) int8 {
/* Too low on board, don't bother checking */
if cell >= 40 {
"io/ioutil"
"os"
"regexp"
- "strings"
)
var variants = []string{
fmt.Printf("%s %d\n", s, countMatches(s, bytes))
}
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))
}