mirror of
https://github.com/golang/go.git
synced 2025-05-29 11:25:43 +00:00
casify misc
R=r DELTA=247 (20 added, 50 deleted, 177 changed) OCL=22951 CL=22955
This commit is contained in:
parent
116a6e9c9c
commit
aedfb397ae
@ -190,7 +190,7 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var f []string;
|
var f []string;
|
||||||
if f = strings.split(s, " "); len(f) != 3 {
|
if f = strings.Split(s, " "); len(f) != 3 {
|
||||||
return nil, BadRequest
|
return nil, BadRequest
|
||||||
}
|
}
|
||||||
req.method, req.rawurl, req.proto = f[0], f[1], f[2];
|
req.method, req.rawurl, req.proto = f[0], f[1], f[2];
|
||||||
|
@ -156,7 +156,7 @@ export func ParseURL(rawurl string) (url *URL, err *os.Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there's no @, split's default is wrong. Check explicitly.
|
// If there's no @, split's default is wrong. Check explicitly.
|
||||||
if strings.index(url.authority, "@") < 0 {
|
if strings.Index(url.authority, "@") < 0 {
|
||||||
url.host = url.authority;
|
url.host = url.authority;
|
||||||
} else {
|
} else {
|
||||||
url.userinfo, url.host = split(url.authority, '@', true);
|
url.userinfo, url.host = split(url.authority, '@', true);
|
||||||
|
@ -60,21 +60,21 @@ export func Readn(fd Read, buf []byte) (n int, err *os.Error) {
|
|||||||
|
|
||||||
// Convert something that implements Read into something
|
// Convert something that implements Read into something
|
||||||
// whose Reads are always Readn
|
// whose Reads are always Readn
|
||||||
type FullRead struct {
|
type _FullRead struct {
|
||||||
fd Read;
|
fd Read;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fd *FullRead) Read(p []byte) (n int, err *os.Error) {
|
func (fd *_FullRead) Read(p []byte) (n int, err *os.Error) {
|
||||||
n, err = Readn(fd.fd, p);
|
n, err = Readn(fd.fd, p);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
export func MakeFullReader(fd Read) Read {
|
export func Make_FullReader(fd Read) Read {
|
||||||
if fr, ok := fd.(*FullRead); ok {
|
if fr, ok := fd.(*_FullRead); ok {
|
||||||
// already a FullRead
|
// already a _FullRead
|
||||||
return fd
|
return fd
|
||||||
}
|
}
|
||||||
return &FullRead{fd}
|
return &_FullRead{fd}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copies n bytes (or until EOF is reached) from src to dst.
|
// Copies n bytes (or until EOF is reached) from src to dst.
|
||||||
|
@ -131,7 +131,7 @@ func (j *_Map) String() string {
|
|||||||
export func Walk(j Json, path string) Json {
|
export func Walk(j Json, path string) Json {
|
||||||
for len(path) > 0 {
|
for len(path) > 0 {
|
||||||
var elem string;
|
var elem string;
|
||||||
if i := strings.index(path, "/"); i >= 0 {
|
if i := strings.Index(path, "/"); i >= 0 {
|
||||||
elem = path[0:i];
|
elem = path[0:i];
|
||||||
path = path[i+1:len(path)];
|
path = path[i+1:len(path)];
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
package malloc
|
package malloc
|
||||||
|
|
||||||
type Stats struct {
|
export type Stats struct {
|
||||||
alloc uint64;
|
alloc uint64;
|
||||||
sys uint64;
|
sys uint64;
|
||||||
};
|
};
|
||||||
|
@ -184,7 +184,7 @@ export func LookupHost(name string) (name1 string, addrs []string, err *os.Error
|
|||||||
// If name is rooted (trailing dot) or has enough dots,
|
// If name is rooted (trailing dot) or has enough dots,
|
||||||
// try it by itself first.
|
// try it by itself first.
|
||||||
rooted := len(name) > 0 && name[len(name)-1] == '.';
|
rooted := len(name) > 0 && name[len(name)-1] == '.';
|
||||||
if rooted || strings.count(name, ".") >= cfg.ndots {
|
if rooted || strings.Count(name, ".") >= cfg.ndots {
|
||||||
rname := name;
|
rname := name;
|
||||||
if !rooted {
|
if !rooted {
|
||||||
rname += ".";
|
rname += ".";
|
||||||
|
@ -11,30 +11,29 @@
|
|||||||
|
|
||||||
package once
|
package once
|
||||||
|
|
||||||
type Job struct {
|
type _Job struct {
|
||||||
done bool;
|
done bool;
|
||||||
doit chan bool; // buffer of 1
|
doit chan bool; // buffer of 1
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type _Request struct {
|
||||||
f *();
|
f *();
|
||||||
reply chan *Job
|
reply chan *_Job
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Would like to use chan Request but 6g rejects it.
|
var service = make(chan _Request)
|
||||||
var service = make(chan *Request)
|
var jobmap = make(map[*()]*_Job)
|
||||||
var jobmap = make(map[*()]*Job)
|
|
||||||
|
|
||||||
// Moderate access to the jobmap.
|
// Moderate access to the jobmap.
|
||||||
// Even if accesses were thread-safe (they should be but are not)
|
// Even if accesses were thread-safe (they should be but are not)
|
||||||
// something needs to serialize creation of new jobs.
|
// something needs to serialize creation of new jobs.
|
||||||
// That's what the Server does.
|
// That's what the Server does.
|
||||||
func Server() {
|
func server() {
|
||||||
for {
|
for {
|
||||||
req := <-service;
|
req := <-service;
|
||||||
job, present := jobmap[req.f];
|
job, present := jobmap[req.f];
|
||||||
if !present {
|
if !present {
|
||||||
job = new(Job);
|
job = new(_Job);
|
||||||
job.doit = make(chan bool, 1);
|
job.doit = make(chan bool, 1);
|
||||||
job.doit <- true;
|
job.doit <- true;
|
||||||
jobmap[req.f] = job
|
jobmap[req.f] = job
|
||||||
@ -48,13 +47,12 @@ export func Do(f *()) {
|
|||||||
// If not there, ask map server to make one.
|
// If not there, ask map server to make one.
|
||||||
// TODO: Uncomment use of jobmap[f] once
|
// TODO: Uncomment use of jobmap[f] once
|
||||||
// maps are thread-safe.
|
// maps are thread-safe.
|
||||||
var job *Job;
|
var job *_Job;
|
||||||
var present bool;
|
var present bool;
|
||||||
// job, present = jobmap[f]
|
// job, present = jobmap[f]
|
||||||
if !present {
|
if !present {
|
||||||
c := make(chan *Job);
|
c := make(chan *_Job);
|
||||||
req := Request{f, c};
|
service <- _Request{f, c};
|
||||||
service <- &req;
|
|
||||||
job = <-c
|
job = <-c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +72,6 @@ export func Do(f *()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
go Server()
|
go server()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,22 +10,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ncall int;
|
var ncall int;
|
||||||
func Call() {
|
func call() {
|
||||||
ncall++
|
ncall++
|
||||||
}
|
}
|
||||||
|
|
||||||
export func TestOnce(t *testing.T) {
|
export func TestOnce(t *testing.T) {
|
||||||
ncall = 0;
|
ncall = 0;
|
||||||
once.Do(&Call);
|
once.Do(&call);
|
||||||
if ncall != 1 {
|
if ncall != 1 {
|
||||||
t.Fatalf("once.Do(&Call) didn't Call(): ncall=%d", ncall);
|
t.Fatalf("once.Do(&call) didn't call(): ncall=%d", ncall);
|
||||||
}
|
}
|
||||||
once.Do(&Call);
|
once.Do(&call);
|
||||||
if ncall != 1 {
|
if ncall != 1 {
|
||||||
t.Fatalf("second once.Do(&Call) did Call(): ncall=%d", ncall);
|
t.Fatalf("second once.Do(&call) did call(): ncall=%d", ncall);
|
||||||
}
|
}
|
||||||
once.Do(&Call);
|
once.Do(&call);
|
||||||
if ncall != 1 {
|
if ncall != 1 {
|
||||||
t.Fatalf("third once.Do(&Call) did Call(): ncall=%d", ncall);
|
t.Fatalf("third once.Do(&call) did call(): ncall=%d", ncall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
133
src/lib/rand.go
133
src/lib/rand.go
@ -10,60 +10,54 @@
|
|||||||
|
|
||||||
package rand
|
package rand
|
||||||
|
|
||||||
// rand, rand31, rand63 - return non-negative random int, int32, int64
|
// rand, rand31, Int63 - return non-negative random int, int32, int64
|
||||||
// urand32 - return random uint32
|
// urand32 - return random uint32
|
||||||
// nrand, nrand31, nrand63 - return 0 <= random < n
|
// nrand, nrand31, Int63n - return 0 <= random < n
|
||||||
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1
|
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1
|
||||||
// perm gives a random permutation []int
|
// perm gives a random permutation []int
|
||||||
|
|
||||||
const
|
const (
|
||||||
(
|
_LEN = 607;
|
||||||
LEN = 607;
|
_TAP = 273;
|
||||||
TAP = 273;
|
_MASK = (1<<63)-1;
|
||||||
MASK = (1<<63)-1;
|
_A = 48271;
|
||||||
A = 48271;
|
_M = 2147483647;
|
||||||
M = 2147483647;
|
_Q = 44488;
|
||||||
Q = 44488;
|
_R = 3399;
|
||||||
R = 3399;
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var
|
var (
|
||||||
(
|
rng_cooked [_LEN]int64; // cooked random numbers
|
||||||
rng_cooked [LEN]int64; // cooked random numbers
|
rng_vec [_LEN]int64; // current feedback register
|
||||||
rng_vec [LEN]int64; // current feedback register
|
|
||||||
rng_tap int; // index into vector
|
rng_tap int; // index into vector
|
||||||
rng_feed int; // index into vector
|
rng_feed int; // index into vector
|
||||||
)
|
)
|
||||||
|
|
||||||
func
|
func seedrand(x int32) int32 {
|
||||||
seedrand(x int32) int32
|
|
||||||
{
|
|
||||||
// seed rng x[n+1] = 48271 * x[n] mod (2**31 - 1)
|
// seed rng x[n+1] = 48271 * x[n] mod (2**31 - 1)
|
||||||
hi := x / Q;
|
hi := x / _Q;
|
||||||
lo := x % Q;
|
lo := x % _Q;
|
||||||
x = A*lo - R*hi;
|
x = _A*lo - _R*hi;
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
x += M;
|
x += _M;
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Seed(seed int32) {
|
||||||
srand(seed int32)
|
|
||||||
{
|
|
||||||
rng_tap = 0;
|
rng_tap = 0;
|
||||||
rng_feed = LEN-TAP;
|
rng_feed = _LEN-_TAP;
|
||||||
|
|
||||||
seed = seed%M;
|
seed = seed%_M;
|
||||||
if seed < 0 {
|
if seed < 0 {
|
||||||
seed += M;
|
seed += _M;
|
||||||
}
|
}
|
||||||
if seed == 0 {
|
if seed == 0 {
|
||||||
seed = 89482311;
|
seed = 89482311;
|
||||||
}
|
}
|
||||||
|
|
||||||
x := seed;
|
x := seed;
|
||||||
for i := -20; i < LEN; i++ {
|
for i := -20; i < _LEN; i++ {
|
||||||
x = seedrand(x);
|
x = seedrand(x);
|
||||||
if i >= 0 {
|
if i >= 0 {
|
||||||
var u int64;
|
var u int64;
|
||||||
@ -73,105 +67,84 @@ srand(seed int32)
|
|||||||
x = seedrand(x);
|
x = seedrand(x);
|
||||||
u ^= int64(x);
|
u ^= int64(x);
|
||||||
u ^= rng_cooked[i];
|
u ^= rng_cooked[i];
|
||||||
rng_vec[i] = u & MASK;
|
rng_vec[i] = u & _MASK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Int63() int64 {
|
||||||
rand63() int64
|
|
||||||
{
|
|
||||||
rng_tap--;
|
rng_tap--;
|
||||||
if rng_tap < 0 {
|
if rng_tap < 0 {
|
||||||
rng_tap += LEN;
|
rng_tap += _LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
rng_feed--;
|
rng_feed--;
|
||||||
if rng_feed < 0 {
|
if rng_feed < 0 {
|
||||||
rng_feed += LEN;
|
rng_feed += _LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & MASK;
|
x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & _MASK;
|
||||||
rng_vec[rng_feed] = x;
|
rng_vec[rng_feed] = x;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Uint32() uint32 {
|
||||||
urand32() uint32
|
return uint32(Int63() >> 31);
|
||||||
{
|
|
||||||
return uint32(rand63() >> 31);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Int31() int32 {
|
||||||
rand31() int32
|
return int32(Int63() >> 32);
|
||||||
{
|
|
||||||
return int32(rand63() >> 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Int() int {
|
||||||
rand() int
|
u := uint(Int63());
|
||||||
{
|
|
||||||
u := uint(rand63());
|
|
||||||
return int(u << 1 >> 1); // clear sign bit if int == int32
|
return int(u << 1 >> 1); // clear sign bit if int == int32
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Int63n(n int64) int64 {
|
||||||
nrand63(n int64) int64
|
|
||||||
{
|
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
max := int64((1<<63)-1 - (1<<63) % uint64(n));
|
max := int64((1<<63)-1 - (1<<63) % uint64(n));
|
||||||
v := rand63();
|
v := Int63();
|
||||||
for v > max {
|
for v > max {
|
||||||
v = rand63()
|
v = Int63()
|
||||||
}
|
}
|
||||||
return v % n
|
return v % n
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Int31n(n int32) int32 {
|
||||||
nrand31(n int32) int32
|
return int32(Int63n(int64(n)))
|
||||||
{
|
|
||||||
return int32(nrand63(int64(n)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Intn(n int) int {
|
||||||
nrand(n int) int
|
return int(Int63n(int64(n)))
|
||||||
{
|
|
||||||
return int(nrand63(int64(n)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Float64() float64 {
|
||||||
frand64() float64
|
x := float64(Int63()) / float64(_MASK);
|
||||||
{
|
|
||||||
x := float64(rand63()) / float64(MASK);
|
|
||||||
for x >= 1 {
|
for x >= 1 {
|
||||||
x = float64(rand63()) / float64(MASK);
|
x = float64(Int63()) / float64(_MASK);
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Float32() float32 {
|
||||||
frand32() float32
|
return float32(Float64())
|
||||||
{
|
|
||||||
return float32(frand64())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Float() float
|
||||||
frand() float
|
|
||||||
{
|
{
|
||||||
return float(frand64())
|
return float(Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
export func
|
export func Perm(n int) []int {
|
||||||
perm(n int) []int
|
|
||||||
{
|
|
||||||
m := make([]int, n);
|
m := make([]int, n);
|
||||||
for i:=0; i<n; i++ {
|
for i:=0; i<n; i++ {
|
||||||
m[i] = i;
|
m[i] = i;
|
||||||
}
|
}
|
||||||
for i:=0; i<n; i++ {
|
for i:=0; i<n; i++ {
|
||||||
j := nrand(n);
|
j := Intn(n);
|
||||||
t := m[i];
|
t := m[i];
|
||||||
m[i] = m[j];
|
m[i] = m[j];
|
||||||
m[j] = t;
|
m[j] = t;
|
||||||
@ -179,9 +152,7 @@ perm(n int) []int
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
func
|
func init() {
|
||||||
init()
|
|
||||||
{
|
|
||||||
// the state of the rng
|
// the state of the rng
|
||||||
// after 780e10 iterations
|
// after 780e10 iterations
|
||||||
|
|
||||||
@ -793,5 +764,5 @@ init()
|
|||||||
rng_cooked[605] = 9103922860780351547;
|
rng_cooked[605] = 9103922860780351547;
|
||||||
rng_cooked[606] = 4152330101494654406;
|
rng_cooked[606] = 4152330101494654406;
|
||||||
|
|
||||||
srand(1);
|
Seed(1);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ export func TestSortStrings(t *testing.T) {
|
|||||||
export func TestSortLarge_Random(t *testing.T) {
|
export func TestSortLarge_Random(t *testing.T) {
|
||||||
data := make([]int, 1000000);
|
data := make([]int, 1000000);
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
data[i] = rand.rand() % 100;
|
data[i] = rand.Intn(100);
|
||||||
}
|
}
|
||||||
if sort.IntsAreSorted(data) {
|
if sort.IntsAreSorted(data) {
|
||||||
t.Fatalf("terrible rand.rand");
|
t.Fatalf("terrible rand.rand");
|
||||||
@ -150,13 +150,13 @@ export func TestBentleyMcIlroy(t *testing.T) {
|
|||||||
case _Sawtooth:
|
case _Sawtooth:
|
||||||
data[i] = i % m;
|
data[i] = i % m;
|
||||||
case _Rand:
|
case _Rand:
|
||||||
data[i] = rand.rand() % m;
|
data[i] = rand.Intn(m);
|
||||||
case _Stagger:
|
case _Stagger:
|
||||||
data[i] = (i*m + i) % n;
|
data[i] = (i*m + i) % n;
|
||||||
case _Plateau:
|
case _Plateau:
|
||||||
data[i] = min(i, m);
|
data[i] = min(i, m);
|
||||||
case _Shuffle:
|
case _Shuffle:
|
||||||
if rand.rand() % m != 0 {
|
if rand.Intn(m) != 0 {
|
||||||
j += 2;
|
j += 2;
|
||||||
data[i] = j;
|
data[i] = j;
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,7 +7,7 @@ package strings
|
|||||||
import "utf8"
|
import "utf8"
|
||||||
|
|
||||||
// Split string into array of UTF-8 sequences (still strings)
|
// Split string into array of UTF-8 sequences (still strings)
|
||||||
export func explode(s string) []string {
|
export func Explode(s string) []string {
|
||||||
a := make([]string, utf8.RuneCountInString(s, 0, len(s)));
|
a := make([]string, utf8.RuneCountInString(s, 0, len(s)));
|
||||||
j := 0;
|
j := 0;
|
||||||
var size, rune int;
|
var size, rune int;
|
||||||
@ -20,7 +20,7 @@ export func explode(s string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count non-overlapping instances of sep in s.
|
// Count non-overlapping instances of sep in s.
|
||||||
export func count(s, sep string) int {
|
export func Count(s, sep string) int {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return utf8.RuneCountInString(s, 0, len(s))+1
|
return utf8.RuneCountInString(s, 0, len(s))+1
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ export func count(s, sep string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return index of first instance of sep in s.
|
// Return index of first instance of sep in s.
|
||||||
export func index(s, sep string) int {
|
export func Index(s, sep string) int {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -50,13 +50,13 @@ export func index(s, sep string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Split string into list of strings at separators
|
// Split string into list of strings at separators
|
||||||
export func split(s, sep string) []string {
|
export func Split(s, sep string) []string {
|
||||||
if sep == "" {
|
if sep == "" {
|
||||||
return explode(s)
|
return Explode(s)
|
||||||
}
|
}
|
||||||
c := sep[0];
|
c := sep[0];
|
||||||
start := 0;
|
start := 0;
|
||||||
n := count(s, sep)+1;
|
n := Count(s, sep)+1;
|
||||||
a := make([]string, n);
|
a := make([]string, n);
|
||||||
na := 0;
|
na := 0;
|
||||||
for i := 0; i+len(sep) <= len(s); i++ {
|
for i := 0; i+len(sep) <= len(s); i++ {
|
||||||
@ -72,7 +72,7 @@ export func split(s, sep string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Join list of strings with separators between them.
|
// Join list of strings with separators between them.
|
||||||
export func join(a []string, sep string) string {
|
export func Join(a []string, sep string) string {
|
||||||
if len(a) == 0 {
|
if len(a) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ var faces = "☺☻☹";
|
|||||||
var commas = "1,2,3,4";
|
var commas = "1,2,3,4";
|
||||||
var dots = "1....2....3....4";
|
var dots = "1....2....3....4";
|
||||||
|
|
||||||
type ExplodeTest struct {
|
export type ExplodeTest struct {
|
||||||
s string;
|
s string;
|
||||||
a []string;
|
a []string;
|
||||||
}
|
}
|
||||||
@ -37,19 +37,19 @@ var explodetests = []ExplodeTest {
|
|||||||
export func TestExplode(t *testing.T) {
|
export func TestExplode(t *testing.T) {
|
||||||
for i := 0; i < len(explodetests); i++ {
|
for i := 0; i < len(explodetests); i++ {
|
||||||
tt := explodetests[i];
|
tt := explodetests[i];
|
||||||
a := explode(tt.s);
|
a := Explode(tt.s);
|
||||||
if !eq(a, tt.a) {
|
if !eq(a, tt.a) {
|
||||||
t.Errorf("Explode(%q) = %v; want %v", tt.s, a, tt.a);
|
t.Errorf("Explode(%q) = %v; want %v", tt.s, a, tt.a);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s := join(a, "");
|
s := Join(a, "");
|
||||||
if s != tt.s {
|
if s != tt.s {
|
||||||
t.Errorf(`Join(Explode(%q), "") = %q`, tt.s, s);
|
t.Errorf(`Join(Explode(%q), "") = %q`, tt.s, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SplitTest struct {
|
export type SplitTest struct {
|
||||||
s string;
|
s string;
|
||||||
sep string;
|
sep string;
|
||||||
a []string;
|
a []string;
|
||||||
@ -67,12 +67,12 @@ var splittests = []SplitTest {
|
|||||||
export func TestSplit(t *testing.T) {
|
export func TestSplit(t *testing.T) {
|
||||||
for i := 0; i < len(splittests); i++ {
|
for i := 0; i < len(splittests); i++ {
|
||||||
tt := splittests[i];
|
tt := splittests[i];
|
||||||
a := split(tt.s, tt.sep);
|
a := Split(tt.s, tt.sep);
|
||||||
if !eq(a, tt.a) {
|
if !eq(a, tt.a) {
|
||||||
t.Errorf("Split(%q, %q) = %v; want %v", tt.s, tt.sep, a, tt.a);
|
t.Errorf("Split(%q, %q) = %v; want %v", tt.s, tt.sep, a, tt.a);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s := join(a, tt.sep);
|
s := Join(a, tt.sep);
|
||||||
if s != tt.s {
|
if s != tt.s {
|
||||||
t.Errorf("Join(Split(%q, %q), %q) = %q", tt.s, tt.sep, tt.sep, s);
|
t.Errorf("Join(Split(%q, %q), %q) = %q", tt.s, tt.sep, tt.sep, s);
|
||||||
}
|
}
|
||||||
|
130
src/lib/utf8.go
130
src/lib/utf8.go
@ -14,25 +14,25 @@ export const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
T1 = 0x00; // 0000 0000
|
_T1 = 0x00; // 0000 0000
|
||||||
Tx = 0x80; // 1000 0000
|
_Tx = 0x80; // 1000 0000
|
||||||
T2 = 0xC0; // 1100 0000
|
_T2 = 0xC0; // 1100 0000
|
||||||
T3 = 0xE0; // 1110 0000
|
_T3 = 0xE0; // 1110 0000
|
||||||
T4 = 0xF0; // 1111 0000
|
_T4 = 0xF0; // 1111 0000
|
||||||
T5 = 0xF8; // 1111 1000
|
_T5 = 0xF8; // 1111 1000
|
||||||
|
|
||||||
Maskx = 0x3F; // 0011 1111
|
_Maskx = 0x3F; // 0011 1111
|
||||||
Mask2 = 0x1F; // 0001 1111
|
_Mask2 = 0x1F; // 0001 1111
|
||||||
Mask3 = 0x0F; // 0000 1111
|
_Mask3 = 0x0F; // 0000 1111
|
||||||
Mask4 = 0x07; // 0000 0111
|
_Mask4 = 0x07; // 0000 0111
|
||||||
|
|
||||||
Rune1Max = 1<<7 - 1;
|
_Rune1Max = 1<<7 - 1;
|
||||||
Rune2Max = 1<<11 - 1;
|
_Rune2Max = 1<<11 - 1;
|
||||||
Rune3Max = 1<<16 - 1;
|
_Rune3Max = 1<<16 - 1;
|
||||||
Rune4Max = 1<<21 - 1;
|
_Rune4Max = 1<<21 - 1;
|
||||||
)
|
)
|
||||||
|
|
||||||
func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
func decodeRuneInternal(p []byte) (rune, size int, short bool) {
|
||||||
n := len(p);
|
n := len(p);
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
return RuneError, 0, true;
|
return RuneError, 0, true;
|
||||||
@ -40,12 +40,12 @@ func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
|||||||
c0 := p[0];
|
c0 := p[0];
|
||||||
|
|
||||||
// 1-byte, 7-bit sequence?
|
// 1-byte, 7-bit sequence?
|
||||||
if c0 < Tx {
|
if c0 < _Tx {
|
||||||
return int(c0), 1, false
|
return int(c0), 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// unexpected continuation byte?
|
// unexpected continuation byte?
|
||||||
if c0 < T2 {
|
if c0 < _T2 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +54,14 @@ func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c1 := p[1];
|
c1 := p[1];
|
||||||
if c1 < Tx || T2 <= c1 {
|
if c1 < _Tx || _T2 <= c1 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2-byte, 11-bit sequence?
|
// 2-byte, 11-bit sequence?
|
||||||
if c0 < T3 {
|
if c0 < _T3 {
|
||||||
rune = int(c0&Mask2)<<6 | int(c1&Maskx);
|
rune = int(c0&_Mask2)<<6 | int(c1&_Maskx);
|
||||||
if rune <= Rune1Max {
|
if rune <= _Rune1Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 2, false
|
return rune, 2, false
|
||||||
@ -72,14 +72,14 @@ func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c2 := p[2];
|
c2 := p[2];
|
||||||
if c2 < Tx || T2 <= c2 {
|
if c2 < _Tx || _T2 <= c2 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3-byte, 16-bit sequence?
|
// 3-byte, 16-bit sequence?
|
||||||
if c0 < T4 {
|
if c0 < _T4 {
|
||||||
rune = int(c0&Mask3)<<12 | int(c1&Maskx)<<6 | int(c2&Maskx);
|
rune = int(c0&_Mask3)<<12 | int(c1&_Maskx)<<6 | int(c2&_Maskx);
|
||||||
if rune <= Rune2Max {
|
if rune <= _Rune2Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 3, false
|
return rune, 3, false
|
||||||
@ -90,14 +90,14 @@ func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c3 := p[3];
|
c3 := p[3];
|
||||||
if c3 < Tx || T2 <= c3 {
|
if c3 < _Tx || _T2 <= c3 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4-byte, 21-bit sequence?
|
// 4-byte, 21-bit sequence?
|
||||||
if c0 < T5 {
|
if c0 < _T5 {
|
||||||
rune = int(c0&Mask4)<<18 | int(c1&Maskx)<<12 | int(c2&Maskx)<<6 | int(c3&Maskx);
|
rune = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx);
|
||||||
if rune <= Rune3Max {
|
if rune <= _Rune3Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 4, false
|
return rune, 4, false
|
||||||
@ -107,19 +107,19 @@ func DecodeRuneInternal(p []byte) (rune, size int, short bool) {
|
|||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short bool) {
|
func decodeRuneInStringInternal(s string, i int, n int) (rune, size int, short bool) {
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
return RuneError, 0, true;
|
return RuneError, 0, true;
|
||||||
}
|
}
|
||||||
c0 := s[i];
|
c0 := s[i];
|
||||||
|
|
||||||
// 1-byte, 7-bit sequence?
|
// 1-byte, 7-bit sequence?
|
||||||
if c0 < Tx {
|
if c0 < _Tx {
|
||||||
return int(c0), 1, false
|
return int(c0), 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// unexpected continuation byte?
|
// unexpected continuation byte?
|
||||||
if c0 < T2 {
|
if c0 < _T2 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,14 +128,14 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c1 := s[i+1];
|
c1 := s[i+1];
|
||||||
if c1 < Tx || T2 <= c1 {
|
if c1 < _Tx || _T2 <= c1 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2-byte, 11-bit sequence?
|
// 2-byte, 11-bit sequence?
|
||||||
if c0 < T3 {
|
if c0 < _T3 {
|
||||||
rune = int(c0&Mask2)<<6 | int(c1&Maskx);
|
rune = int(c0&_Mask2)<<6 | int(c1&_Maskx);
|
||||||
if rune <= Rune1Max {
|
if rune <= _Rune1Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 2, false
|
return rune, 2, false
|
||||||
@ -146,14 +146,14 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c2 := s[i+2];
|
c2 := s[i+2];
|
||||||
if c2 < Tx || T2 <= c2 {
|
if c2 < _Tx || _T2 <= c2 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3-byte, 16-bit sequence?
|
// 3-byte, 16-bit sequence?
|
||||||
if c0 < T4 {
|
if c0 < _T4 {
|
||||||
rune = int(c0&Mask3)<<12 | int(c1&Maskx)<<6 | int(c2&Maskx);
|
rune = int(c0&_Mask3)<<12 | int(c1&_Maskx)<<6 | int(c2&_Maskx);
|
||||||
if rune <= Rune2Max {
|
if rune <= _Rune2Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 3, false
|
return rune, 3, false
|
||||||
@ -164,14 +164,14 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b
|
|||||||
return RuneError, 1, true
|
return RuneError, 1, true
|
||||||
}
|
}
|
||||||
c3 := s[i+3];
|
c3 := s[i+3];
|
||||||
if c3 < Tx || T2 <= c3 {
|
if c3 < _Tx || _T2 <= c3 {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4-byte, 21-bit sequence?
|
// 4-byte, 21-bit sequence?
|
||||||
if c0 < T5 {
|
if c0 < _T5 {
|
||||||
rune = int(c0&Mask4)<<18 | int(c1&Maskx)<<12 | int(c2&Maskx)<<6 | int(c3&Maskx);
|
rune = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx);
|
||||||
if rune <= Rune3Max {
|
if rune <= _Rune3Max {
|
||||||
return RuneError, 1, false
|
return RuneError, 1, false
|
||||||
}
|
}
|
||||||
return rune, 4, false
|
return rune, 4, false
|
||||||
@ -182,50 +182,50 @@ func DecodeRuneInStringInternal(s string, i int, n int) (rune, size int, short b
|
|||||||
}
|
}
|
||||||
|
|
||||||
export func FullRune(p []byte) bool {
|
export func FullRune(p []byte) bool {
|
||||||
rune, size, short := DecodeRuneInternal(p);
|
rune, size, short := decodeRuneInternal(p);
|
||||||
return !short
|
return !short
|
||||||
}
|
}
|
||||||
|
|
||||||
export func FullRuneInString(s string, i int) bool {
|
export func FullRuneInString(s string, i int) bool {
|
||||||
rune, size, short := DecodeRuneInStringInternal(s, i, len(s) - i);
|
rune, size, short := decodeRuneInStringInternal(s, i, len(s) - i);
|
||||||
return !short
|
return !short
|
||||||
}
|
}
|
||||||
|
|
||||||
export func DecodeRune(p []byte) (rune, size int) {
|
export func DecodeRune(p []byte) (rune, size int) {
|
||||||
var short bool;
|
var short bool;
|
||||||
rune, size, short = DecodeRuneInternal(p);
|
rune, size, short = decodeRuneInternal(p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func DecodeRuneInString(s string, i int) (rune, size int) {
|
export func DecodeRuneInString(s string, i int) (rune, size int) {
|
||||||
var short bool;
|
var short bool;
|
||||||
rune, size, short = DecodeRuneInStringInternal(s, i, len(s) - i);
|
rune, size, short = decodeRuneInStringInternal(s, i, len(s) - i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func RuneLen(rune int) int {
|
export func RuneLen(rune int) int {
|
||||||
switch {
|
switch {
|
||||||
case rune <= Rune1Max:
|
case rune <= _Rune1Max:
|
||||||
return 1;
|
return 1;
|
||||||
case rune <= Rune2Max:
|
case rune <= _Rune2Max:
|
||||||
return 2;
|
return 2;
|
||||||
case rune <= Rune3Max:
|
case rune <= _Rune3Max:
|
||||||
return 3;
|
return 3;
|
||||||
case rune <= Rune4Max:
|
case rune <= _Rune4Max:
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export func EncodeRune(rune int, p []byte) int {
|
export func EncodeRune(rune int, p []byte) int {
|
||||||
if rune <= Rune1Max {
|
if rune <= _Rune1Max {
|
||||||
p[0] = byte(rune);
|
p[0] = byte(rune);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if rune <= Rune2Max {
|
if rune <= _Rune2Max {
|
||||||
p[0] = T2 | byte(rune>>6);
|
p[0] = _T2 | byte(rune>>6);
|
||||||
p[1] = Tx | byte(rune)&Maskx;
|
p[1] = _Tx | byte(rune)&_Maskx;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,17 +233,17 @@ export func EncodeRune(rune int, p []byte) int {
|
|||||||
rune = RuneError
|
rune = RuneError
|
||||||
}
|
}
|
||||||
|
|
||||||
if rune <= Rune3Max {
|
if rune <= _Rune3Max {
|
||||||
p[0] = T3 | byte(rune>>12);
|
p[0] = _T3 | byte(rune>>12);
|
||||||
p[1] = Tx | byte(rune>>6)&Maskx;
|
p[1] = _Tx | byte(rune>>6)&_Maskx;
|
||||||
p[2] = Tx | byte(rune)&Maskx;
|
p[2] = _Tx | byte(rune)&_Maskx;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
p[0] = T4 | byte(rune>>18);
|
p[0] = _T4 | byte(rune>>18);
|
||||||
p[1] = Tx | byte(rune>>12)&Maskx;
|
p[1] = _Tx | byte(rune>>12)&_Maskx;
|
||||||
p[2] = Tx | byte(rune>>6)&Maskx;
|
p[2] = _Tx | byte(rune>>6)&_Maskx;
|
||||||
p[3] = Tx | byte(rune)&Maskx;
|
p[3] = _Tx | byte(rune)&_Maskx;
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ export func RuneCountInString(s string, i int, l int) int {
|
|||||||
if s[i] < RuneSelf {
|
if s[i] < RuneSelf {
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
rune, size, short := DecodeRuneInStringInternal(s, i, ei - i);
|
rune, size, short := decodeRuneInStringInternal(s, i, ei - i);
|
||||||
i += size;
|
i += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"utf8";
|
"utf8";
|
||||||
)
|
)
|
||||||
|
|
||||||
type Utf8Map struct {
|
export type Utf8Map struct {
|
||||||
rune int;
|
rune int;
|
||||||
str string;
|
str string;
|
||||||
}
|
}
|
||||||
@ -44,10 +44,11 @@ var utf8map = []Utf8Map {
|
|||||||
Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" },
|
Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" },
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bytes(s string) []byte {
|
// like io.StringBytes but leaves one extra byte at end
|
||||||
|
func bytes(s string) []byte {
|
||||||
b := make([]byte, len(s)+1);
|
b := make([]byte, len(s)+1);
|
||||||
if !syscall.StringToBytes(b, s) {
|
if !syscall.StringToBytes(b, s) {
|
||||||
panic("StringToBytes failed");
|
panic("StringTobytes failed");
|
||||||
}
|
}
|
||||||
return b[0:len(s)];
|
return b[0:len(s)];
|
||||||
}
|
}
|
||||||
@ -55,7 +56,7 @@ func Bytes(s string) []byte {
|
|||||||
export func TestFullRune(t *testing.T) {
|
export func TestFullRune(t *testing.T) {
|
||||||
for i := 0; i < len(utf8map); i++ {
|
for i := 0; i < len(utf8map); i++ {
|
||||||
m := utf8map[i];
|
m := utf8map[i];
|
||||||
b := Bytes(m.str);
|
b := bytes(m.str);
|
||||||
if !utf8.FullRune(b) {
|
if !utf8.FullRune(b) {
|
||||||
t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune);
|
t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune);
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ export func TestFullRune(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func EqualBytes(a, b []byte) bool {
|
func equalBytes(a, b []byte) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -89,11 +90,11 @@ func EqualBytes(a, b []byte) bool {
|
|||||||
export func TestEncodeRune(t *testing.T) {
|
export func TestEncodeRune(t *testing.T) {
|
||||||
for i := 0; i < len(utf8map); i++ {
|
for i := 0; i < len(utf8map); i++ {
|
||||||
m := utf8map[i];
|
m := utf8map[i];
|
||||||
b := Bytes(m.str);
|
b := bytes(m.str);
|
||||||
var buf [10]byte;
|
var buf [10]byte;
|
||||||
n := utf8.EncodeRune(m.rune, buf);
|
n := utf8.EncodeRune(m.rune, buf);
|
||||||
b1 := buf[0:n];
|
b1 := buf[0:n];
|
||||||
if !EqualBytes(b, b1) {
|
if !equalBytes(b, b1) {
|
||||||
t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b);
|
t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ export func TestEncodeRune(t *testing.T) {
|
|||||||
export func TestDecodeRune(t *testing.T) {
|
export func TestDecodeRune(t *testing.T) {
|
||||||
for i := 0; i < len(utf8map); i++ {
|
for i := 0; i < len(utf8map); i++ {
|
||||||
m := utf8map[i];
|
m := utf8map[i];
|
||||||
b := Bytes(m.str);
|
b := bytes(m.str);
|
||||||
rune, size := utf8.DecodeRune(b);
|
rune, size := utf8.DecodeRune(b);
|
||||||
if rune != m.rune || size != len(b) {
|
if rune != m.rune || size != len(b) {
|
||||||
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
|
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
|
||||||
@ -113,7 +114,7 @@ export func TestDecodeRune(t *testing.T) {
|
|||||||
t.Errorf("DecodeRune(%q, 2) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b));
|
t.Errorf("DecodeRune(%q, 2) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// there's an extra byte that Bytes left behind - make sure trailing byte works
|
// there's an extra byte that bytes left behind - make sure trailing byte works
|
||||||
rune, size = utf8.DecodeRune(b[0:cap(b)]);
|
rune, size = utf8.DecodeRune(b[0:cap(b)]);
|
||||||
if rune != m.rune || size != len(b) {
|
if rune != m.rune || size != len(b) {
|
||||||
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
|
t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b));
|
||||||
@ -157,7 +158,7 @@ export func TestDecodeRune(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuneCountTest struct {
|
export type RuneCountTest struct {
|
||||||
in string;
|
in string;
|
||||||
out int;
|
out int;
|
||||||
}
|
}
|
||||||
@ -173,7 +174,7 @@ export func TestRuneCount(t *testing.T) {
|
|||||||
if out := utf8.RuneCountInString(tt.in, 0, len(tt.in)); out != tt.out {
|
if out := utf8.RuneCountInString(tt.in, 0, len(tt.in)); out != tt.out {
|
||||||
t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out);
|
t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out);
|
||||||
}
|
}
|
||||||
if out := utf8.RuneCount(Bytes(tt.in)); out != tt.out {
|
if out := utf8.RuneCount(bytes(tt.in)); out != tt.out {
|
||||||
t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out);
|
t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user