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
52e5d061
Commit
52e5d061
authored
Jun 04, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bytes.Copy
R=rsc DELTA=38 (38 added, 0 deleted, 0 changed) OCL=29895 CL=29895
parent
78933226
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
0 deletions
+38
-0
Make.deps
src/lib/Make.deps
+1
-0
Makefile
src/lib/Makefile
+1
-0
bytes.go
src/lib/bytes/bytes.go
+9
-0
bytes_test.go
src/lib/bytes/bytes_test.go
+27
-0
No files found.
src/lib/Make.deps
View file @
52e5d061
bignum.install: fmt.install
bufio.install: io.install os.install utf8.install
bytes.install: utf8.install
container/list.install:
container/vector.install:
crypto/aes.install: os.install
...
...
src/lib/Makefile
View file @
52e5d061
...
...
@@ -16,6 +16,7 @@ GC=6g
DIRS
=
\
bignum
\
bufio
\
bytes
\
container/list
\
container/vector
\
crypto/aes
\
...
...
src/lib/bytes/bytes.go
View file @
52e5d061
...
...
@@ -41,6 +41,15 @@ func Equal(a, b []byte) bool {
return
true
}
// 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
)
{
for
i
,
x
:=
range
src
{
dst
[
i
]
=
x
}
}
// Explode splits s into an array of UTF-8 sequences, one per Unicode character (still arrays of bytes).
// Invalid UTF-8 sequences become correct encodings of U+FFF8.
func
Explode
(
s
[]
byte
)
[][]
byte
{
...
...
src/lib/bytes/bytes_test.go
View file @
52e5d061
...
...
@@ -128,3 +128,30 @@ func TestSplit(t *testing.T) {
}
}
}
type
CopyTest
struct
{
a
string
;
b
string
;
res
string
;
}
var
copytests
=
[]
CopyTest
{
CopyTest
{
""
,
""
,
""
},
CopyTest
{
"a"
,
""
,
"a"
},
CopyTest
{
"a"
,
"a"
,
"a"
},
CopyTest
{
"a"
,
"b"
,
"b"
},
CopyTest
{
"xyz"
,
"abc"
,
"abc"
},
CopyTest
{
"wxyz"
,
"abc"
,
"abcz"
},
}
func
TestCopy
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
copytests
);
i
++
{
tt
:=
copytests
[
i
];
dst
:=
io
.
StringBytes
(
tt
.
a
);
Copy
(
dst
,
io
.
StringBytes
(
tt
.
b
));
result
:=
string
(
dst
);
if
result
!=
tt
.
res
{
t
.
Errorf
(
`Copy("%s", "%s") = "%s"; want "%s"`
,
tt
.
a
,
tt
.
b
,
result
,
tt
.
res
);
continue
;
}
}
}
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