Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
424f4f0f
Commit
424f4f0f
authored
Jun 04, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the new bytes package
R=rsc DELTA=61 (8 added, 31 deleted, 22 changed) OCL=29897 CL=29899
parent
9a9ffb2b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
34 deletions
+23
-34
src/lib/Make.deps
src/lib/Make.deps
+3
-3
src/lib/bytes/bytes.go
src/lib/bytes/bytes.go
+3
-2
src/lib/io/io.go
src/lib/io/io.go
+2
-3
src/lib/strconv/decimal.go
src/lib/strconv/decimal.go
+6
-5
src/lib/tabwriter/tabwriter.go
src/lib/tabwriter/tabwriter.go
+2
-3
src/lib/utf8/utf8_test.go
src/lib/utf8/utf8_test.go
+7
-18
No files found.
src/lib/Make.deps
View file @
424f4f0f
...
@@ -22,7 +22,7 @@ hash.install: io.install
...
@@ -22,7 +22,7 @@ hash.install: io.install
hash/adler32.install: hash.install os.install
hash/adler32.install: hash.install os.install
hash/crc32.install: hash.install os.install
hash/crc32.install: hash.install os.install
http.install: bufio.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install
http.install: bufio.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install
io.install: os.install sync.install
io.install:
bytes.install
os.install sync.install
json.install: container/vector.install fmt.install io.install math.install reflect.install strconv.install strings.install utf8.install
json.install: container/vector.install fmt.install io.install math.install reflect.install strconv.install strings.install utf8.install
log.install: fmt.install io.install os.install runtime.install time.install
log.install: fmt.install io.install os.install runtime.install time.install
malloc.install:
malloc.install:
...
@@ -36,11 +36,11 @@ reflect.install: strconv.install sync.install utf8.install
...
@@ -36,11 +36,11 @@ reflect.install: strconv.install sync.install utf8.install
regexp.install: container/vector.install os.install runtime.install utf8.install
regexp.install: container/vector.install os.install runtime.install utf8.install
runtime.install:
runtime.install:
sort.install:
sort.install:
strconv.install: math.install os.install utf8.install
strconv.install:
bytes.install
math.install os.install utf8.install
strings.install: utf8.install
strings.install: utf8.install
sync.install:
sync.install:
syscall.install: sync.install
syscall.install: sync.install
tabwriter.install: container/vector.install io.install os.install utf8.install
tabwriter.install:
bytes.install
container/vector.install io.install os.install utf8.install
template.install: container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
template.install: container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
testing.install: flag.install fmt.install os.install runtime.install
testing.install: flag.install fmt.install os.install runtime.install
testing/iotest.install: io.install log.install os.install
testing/iotest.install: io.install log.install os.install
...
...
src/lib/bytes/bytes.go
View file @
424f4f0f
...
@@ -43,11 +43,12 @@ func Equal(a, b []byte) bool {
...
@@ -43,11 +43,12 @@ func Equal(a, b []byte) bool {
// Copy copies the source to the destination, stopping when the source
// Copy copies the source to the destination, stopping when the source
// is all transferred. The caller must guarantee that there is enough
// is all transferred. The caller must guarantee that there is enough
// room in the destination.
// room in the destination.
It returns the number of bytes copied
func
Copy
(
dst
,
src
[]
byte
)
{
func
Copy
(
dst
,
src
[]
byte
)
int
{
for
i
,
x
:=
range
src
{
for
i
,
x
:=
range
src
{
dst
[
i
]
=
x
dst
[
i
]
=
x
}
}
return
len
(
src
)
}
}
// Explode splits s into an array of UTF-8 sequences, one per Unicode character (still arrays of bytes).
// Explode splits s into an array of UTF-8 sequences, one per Unicode character (still arrays of bytes).
...
...
src/lib/io/io.go
View file @
424f4f0f
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
package
io
package
io
import
(
import
(
"bytes"
;
"os"
;
"os"
;
)
)
...
@@ -210,9 +211,7 @@ func (r ByteReader) Read(p []byte) (int, os.Error) {
...
@@ -210,9 +211,7 @@ func (r ByteReader) Read(p []byte) (int, os.Error) {
if
n
>
len
(
b
)
{
if
n
>
len
(
b
)
{
n
=
len
(
b
);
n
=
len
(
b
);
}
}
for
i
:=
0
;
i
<
n
;
i
++
{
bytes
.
Copy
(
p
,
b
[
0
:
n
]);
p
[
i
]
=
b
[
i
];
}
*
b
=
b
[
n
:
len
(
b
)];
*
b
=
b
[
n
:
len
(
b
)];
return
n
,
nil
;
return
n
,
nil
;
}
}
...
...
src/lib/strconv/decimal.go
View file @
424f4f0f
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
package
strconv
package
strconv
import
"bytes"
type
decimal
struct
{
type
decimal
struct
{
// TODO(rsc): Can make d[] a bit smaller and add
// TODO(rsc): Can make d[] a bit smaller and add
// truncated bool;
// truncated bool;
...
@@ -27,7 +29,6 @@ func (a *decimal) RoundDown(nd int) *decimal;
...
@@ -27,7 +29,6 @@ func (a *decimal) RoundDown(nd int) *decimal;
func
(
a
*
decimal
)
RoundedInteger
()
uint64
;
func
(
a
*
decimal
)
RoundedInteger
()
uint64
;
func
copy
(
dst
[]
byte
,
src
[]
byte
)
int
;
func
digitZero
(
dst
[]
byte
)
int
;
func
digitZero
(
dst
[]
byte
)
int
;
func
(
a
*
decimal
)
String
()
string
{
func
(
a
*
decimal
)
String
()
string
{
...
@@ -52,18 +53,18 @@ func (a *decimal) String() string {
...
@@ -52,18 +53,18 @@ func (a *decimal) String() string {
buf
[
w
]
=
'.'
;
buf
[
w
]
=
'.'
;
w
++
;
w
++
;
w
+=
digitZero
(
buf
[
w
:
w
+-
a
.
dp
]);
w
+=
digitZero
(
buf
[
w
:
w
+-
a
.
dp
]);
w
+=
c
opy
(
buf
[
w
:
w
+
a
.
nd
],
a
.
d
[
0
:
a
.
nd
]);
w
+=
bytes
.
C
opy
(
buf
[
w
:
w
+
a
.
nd
],
a
.
d
[
0
:
a
.
nd
]);
case
a
.
dp
<
a
.
nd
:
case
a
.
dp
<
a
.
nd
:
// decimal point in middle of digits
// decimal point in middle of digits
w
+=
c
opy
(
buf
[
w
:
w
+
a
.
dp
],
a
.
d
[
0
:
a
.
dp
]);
w
+=
bytes
.
C
opy
(
buf
[
w
:
w
+
a
.
dp
],
a
.
d
[
0
:
a
.
dp
]);
buf
[
w
]
=
'.'
;
buf
[
w
]
=
'.'
;
w
++
;
w
++
;
w
+=
c
opy
(
buf
[
w
:
w
+
a
.
nd
-
a
.
dp
],
a
.
d
[
a
.
dp
:
a
.
nd
]);
w
+=
bytes
.
C
opy
(
buf
[
w
:
w
+
a
.
nd
-
a
.
dp
],
a
.
d
[
a
.
dp
:
a
.
nd
]);
default
:
default
:
// zeros fill space between digits and decimal point
// zeros fill space between digits and decimal point
w
+=
c
opy
(
buf
[
w
:
w
+
a
.
nd
],
a
.
d
[
0
:
a
.
nd
]);
w
+=
bytes
.
C
opy
(
buf
[
w
:
w
+
a
.
nd
],
a
.
d
[
0
:
a
.
nd
]);
w
+=
digitZero
(
buf
[
w
:
w
+
a
.
dp
-
a
.
nd
]);
w
+=
digitZero
(
buf
[
w
:
w
+
a
.
dp
-
a
.
nd
]);
}
}
return
string
(
buf
[
0
:
w
]);
return
string
(
buf
[
0
:
w
]);
...
...
src/lib/tabwriter/tabwriter.go
View file @
424f4f0f
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
package
tabwriter
package
tabwriter
import
(
import
(
"bytes"
;
"container/vector"
;
"container/vector"
;
"io"
;
"io"
;
"os"
;
"os"
;
...
@@ -56,9 +57,7 @@ func (b *byteArray) append(s []byte) {
...
@@ -56,9 +57,7 @@ func (b *byteArray) append(s []byte) {
n2
=
m
;
n2
=
m
;
}
}
b
:=
make
([]
byte
,
n2
);
b
:=
make
([]
byte
,
n2
);
for
i
:=
0
;
i
<
n
;
i
++
{
bytes
.
Copy
(
b
,
a
);
b
[
i
]
=
a
[
i
];
}
a
=
b
;
a
=
b
;
}
}
...
...
src/lib/utf8/utf8_test.go
View file @
424f4f0f
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
utf8
package
utf8
import
(
import
(
"bytes"
;
"fmt"
;
"fmt"
;
"io"
;
"io"
;
"testing"
;
"testing"
;
...
@@ -45,7 +46,7 @@ var utf8map = []Utf8Map {
...
@@ -45,7 +46,7 @@ var utf8map = []Utf8Map {
}
}
// io.StringBytes with one extra byte at end
// io.StringBytes with one extra byte at end
func
b
ytes
(
s
string
)
[]
byte
{
func
makeB
ytes
(
s
string
)
[]
byte
{
s
+=
"
\x00
"
;
s
+=
"
\x00
"
;
b
:=
io
.
StringBytes
(
s
);
b
:=
io
.
StringBytes
(
s
);
return
b
[
0
:
len
(
s
)
-
1
];
return
b
[
0
:
len
(
s
)
-
1
];
...
@@ -54,7 +55,7 @@ func bytes(s string) []byte {
...
@@ -54,7 +55,7 @@ func bytes(s string) []byte {
func
TestFullRune
(
t
*
testing
.
T
)
{
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
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
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
);
}
}
...
@@ -73,26 +74,14 @@ func TestFullRune(t *testing.T) {
...
@@ -73,26 +74,14 @@ func TestFullRune(t *testing.T) {
}
}
}
}
func
equalBytes
(
a
,
b
[]
byte
)
bool
{
if
len
(
a
)
!=
len
(
b
)
{
return
false
;
}
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
if
a
[
i
]
!=
b
[
i
]
{
return
false
;
}
}
return
true
;
}
func
TestEncodeRune
(
t
*
testing
.
T
)
{
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
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
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
!
bytes
.
Equal
(
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
);
}
}
}
}
...
@@ -101,7 +90,7 @@ func TestEncodeRune(t *testing.T) {
...
@@ -101,7 +90,7 @@ func TestEncodeRune(t *testing.T) {
func
TestDecodeRune
(
t
*
testing
.
T
)
{
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
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
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
));
...
@@ -172,7 +161,7 @@ func TestRuneCount(t *testing.T) {
...
@@ -172,7 +161,7 @@ func TestRuneCount(t *testing.T) {
if
out
:=
utf8
.
RuneCountInString
(
tt
.
in
);
out
!=
tt
.
out
{
if
out
:=
utf8
.
RuneCountInString
(
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
(
b
ytes
(
tt
.
in
));
out
!=
tt
.
out
{
if
out
:=
utf8
.
RuneCount
(
makeB
ytes
(
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
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment