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
28db3e84
Commit
28db3e84
authored
May 14, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ByteBuffer.Truncate(n int)
R=r DELTA=22 (17 added, 0 deleted, 5 changed) OCL=28781 CL=28815
parent
a8db4593
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
bytebuffer.go
src/lib/io/bytebuffer.go
+9
-1
bytebuffer_test.go
src/lib/io/bytebuffer_test.go
+13
-4
No files found.
src/lib/io/bytebuffer.go
View file @
28db3e84
...
...
@@ -39,9 +39,17 @@ func (b *ByteBuffer) Len() int {
return
len
(
b
.
buf
)
-
b
.
off
}
// Truncates the buffer so it contains n bytes.
// It preserves the data in the buffer at positions [0 : n].
// It is an error to call b.Truncate(n) with n > b.Len().
func
(
b
*
ByteBuffer
)
Truncate
(
n
int
)
{
b
.
buf
=
b
.
buf
[
0
:
b
.
off
+
n
];
}
// Reset resets the buffer so it has no content.
// b.Reset() is the same as b.Truncate(0).
func
(
b
*
ByteBuffer
)
Reset
()
{
b
.
off
=
len
(
b
.
buf
)
b
.
buf
=
b
.
buf
[
0
:
b
.
off
];
}
// Write appends the contents of p to the buffer. The return
...
...
src/lib/io/bytebuffer_test.go
View file @
28db3e84
...
...
@@ -89,6 +89,9 @@ func TestBasicOperations(t *testing.T) {
buf
.
Reset
();
check
(
t
,
"TestBasicOperations (2)"
,
&
buf
,
""
);
buf
.
Truncate
(
0
);
check
(
t
,
"TestBasicOperations (3)"
,
&
buf
,
""
);
n
,
err
:=
buf
.
Write
(
data
[
0
:
1
]);
if
n
!=
1
{
t
.
Errorf
(
"wrote 1 byte, but n == %d
\n
"
,
n
);
...
...
@@ -96,16 +99,22 @@ func TestBasicOperations(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"err should always be nil, but err == %s
\n
"
,
err
);
}
check
(
t
,
"TestBasicOperations (
3
)"
,
&
buf
,
"a"
);
check
(
t
,
"TestBasicOperations (
4
)"
,
&
buf
,
"a"
);
n
,
err
=
buf
.
Write
(
data
[
1
:
26
]);
if
n
!=
25
{
t
.
Errorf
(
"wrote 25 bytes, but n == %d
\n
"
,
n
);
}
check
(
t
,
"TestBasicOperations (4)"
,
&
buf
,
string
(
data
[
0
:
26
]));
check
(
t
,
"TestBasicOperations (5)"
,
&
buf
,
string
(
data
[
0
:
26
]));
buf
.
Truncate
(
26
);
check
(
t
,
"TestBasicOperations (6)"
,
&
buf
,
string
(
data
[
0
:
26
]));
buf
.
Truncate
(
20
);
check
(
t
,
"TestBasicOperations (7)"
,
&
buf
,
string
(
data
[
0
:
20
]));
empty
(
t
,
"TestBasicOperations (
5)"
,
&
buf
,
string
(
data
[
0
:
26
]),
make
([]
byte
,
5
));
empty
(
t
,
"TestBasicOperations (
6
)"
,
&
buf
,
""
,
make
([]
byte
,
100
));
empty
(
t
,
"TestBasicOperations (
8)"
,
&
buf
,
string
(
data
[
0
:
20
]),
make
([]
byte
,
5
));
empty
(
t
,
"TestBasicOperations (
9
)"
,
&
buf
,
""
,
make
([]
byte
,
100
));
}
}
...
...
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