Skip to content

Commit

Permalink
Fix Issue 16062 - Add 'clear' method to OutBuffer (std.outbuffer)
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Jul 12, 2017
1 parent 0958adf commit 09ab8e9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions std/outbuffer.d
Expand Up @@ -202,6 +202,12 @@ class OutBuffer
fill0(alignsize - nbytes);
}

/// Clear the data in the buffer
void clear()
{
offset = 0;
}

/****************************************
* Optimize common special case alignSize(2)
*/
Expand Down Expand Up @@ -380,6 +386,11 @@ class OutBuffer
buf.write("world"[]);
buf.printf(" %d", 62665);
assert(cmp(buf.toString(), "hello world 62665") == 0);

buf.clear();
assert(cmp(buf.toString(), "") == 0);
buf.write("New data"[]);
assert(cmp(buf.toString(),"New data") == 0);
}

@safe unittest
Expand Down

0 comments on commit 09ab8e9

Please sign in to comment.