Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
34 deletions
+23
-34
Make.deps
src/lib/Make.deps
+3
-3
bytes.go
src/lib/bytes/bytes.go
+3
-2
io.go
src/lib/io/io.go
+2
-3
decimal.go
src/lib/strconv/decimal.go
+6
-5
tabwriter.go
src/lib/tabwriter/tabwriter.go
+2
-3
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
hash/adler32.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
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
log.install: fmt.install io.install os.install runtime.install time.install
malloc.install:
...
...
@@ -36,11 +36,11 @@ reflect.install: strconv.install sync.install utf8.install
regexp.install: container/vector.install os.install runtime.install utf8.install
runtime.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
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
testing.install: flag.install fmt.install os.install runtime.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 {
// Copy copies the source to the destination, stopping when the source
// is all transferred. The caller must guarantee that there is enough
// room in the destination.
func
Copy
(
dst
,
src
[]
byte
)
{
// room in the destination.
It returns the number of bytes copied
func
Copy
(
dst
,
src
[]
byte
)
int
{
for
i
,
x
:=
range
src
{
dst
[
i
]
=
x
}
return
len
(
src
)
}
// 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 @@
package
io
import
(
"bytes"
;
"os"
;
)
...
...
@@ -210,9 +211,7 @@ func (r ByteReader) Read(p []byte) (int, os.Error) {
if
n
>
len
(
b
)
{
n
=
len
(
b
);
}
for
i
:=
0
;
i
<
n
;
i
++
{
p
[
i
]
=
b
[
i
];
}
bytes
.
Copy
(
p
,
b
[
0
:
n
]);
*
b
=
b
[
n
:
len
(
b
)];
return
n
,
nil
;
}
...
...
src/lib/strconv/decimal.go
View file @
424f4f0f
...
...
@@ -11,6 +11,8 @@
package
strconv
import
"bytes"
type
decimal
struct
{
// TODO(rsc): Can make d[] a bit smaller and add
// truncated bool;
...
...
@@ -27,7 +29,6 @@ func (a *decimal) RoundDown(nd int) *decimal;
func
(
a
*
decimal
)
RoundedInteger
()
uint64
;
func
copy
(
dst
[]
byte
,
src
[]
byte
)
int
;
func
digitZero
(
dst
[]
byte
)
int
;
func
(
a
*
decimal
)
String
()
string
{
...
...
@@ -52,18 +53,18 @@ func (a *decimal) String() string {
buf
[
w
]
=
'.'
;
w
++
;
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
:
// 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
]
=
'.'
;
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
:
// 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
]);
}
return
string
(
buf
[
0
:
w
]);
...
...
src/lib/tabwriter/tabwriter.go
View file @
424f4f0f
...
...
@@ -10,6 +10,7 @@
package
tabwriter
import
(
"bytes"
;
"container/vector"
;
"io"
;
"os"
;
...
...
@@ -56,9 +57,7 @@ func (b *byteArray) append(s []byte) {
n2
=
m
;
}
b
:=
make
([]
byte
,
n2
);
for
i
:=
0
;
i
<
n
;
i
++
{
b
[
i
]
=
a
[
i
];
}
bytes
.
Copy
(
b
,
a
);
a
=
b
;
}
...
...
src/lib/utf8/utf8_test.go
View file @
424f4f0f
...
...
@@ -5,6 +5,7 @@
package
utf8
import
(
"bytes"
;
"fmt"
;
"io"
;
"testing"
;
...
...
@@ -45,7 +46,7 @@ var utf8map = []Utf8Map {
}
// io.StringBytes with one extra byte at end
func
b
ytes
(
s
string
)
[]
byte
{
func
makeB
ytes
(
s
string
)
[]
byte
{
s
+=
"
\x00
"
;
b
:=
io
.
StringBytes
(
s
);
return
b
[
0
:
len
(
s
)
-
1
];
...
...
@@ -54,7 +55,7 @@ func bytes(s string) []byte {
func
TestFullRune
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
m
:=
utf8map
[
i
];
b
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
m
.
str
);
if
!
utf8
.
FullRune
(
b
)
{
t
.
Errorf
(
"FullRune(%q) (rune %04x) = false, want true"
,
b
,
m
.
rune
);
}
...
...
@@ -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
)
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
m
:=
utf8map
[
i
];
b
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
m
.
str
);
var
buf
[
10
]
byte
;
n
:=
utf8
.
EncodeRune
(
m
.
rune
,
&
buf
);
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
);
}
}
...
...
@@ -101,7 +90,7 @@ func TestEncodeRune(t *testing.T) {
func
TestDecodeRune
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
m
:=
utf8map
[
i
];
b
:=
b
ytes
(
m
.
str
);
b
:=
makeB
ytes
(
m
.
str
);
rune
,
size
:=
utf8
.
DecodeRune
(
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
));
...
...
@@ -172,7 +161,7 @@ func TestRuneCount(t *testing.T) {
if
out
:=
utf8
.
RuneCountInString
(
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
);
}
}
...
...
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