mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-03 21:06:25 +01:00
added Buffer append()
This commit is contained in:
parent
c41196bd5b
commit
11539da851
@ -116,6 +116,22 @@ public:
|
|||||||
_used = newCapacity;
|
_used = newCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void append(const T* buf, std::size_t sz)
|
||||||
|
/// Resizes this buffer and appends the argument buffer.
|
||||||
|
{
|
||||||
|
if (0 == sz)
|
||||||
|
return;
|
||||||
|
std::size_t oldSize = _used;
|
||||||
|
resize(_used + sz, true);
|
||||||
|
std::memcpy(_ptr + oldSize, buf, sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
void append(const Buffer& buf)
|
||||||
|
/// Resizes this buffer and appends the argument buffer.
|
||||||
|
{
|
||||||
|
append(buf.begin(), buf.size());
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t capacity() const
|
std::size_t capacity() const
|
||||||
/// Returns the allocated memory size.
|
/// Returns the allocated memory size.
|
||||||
{
|
{
|
||||||
|
@ -251,6 +251,14 @@ void CoreTest::testBuffer()
|
|||||||
|
|
||||||
Buffer<int> f = e;
|
Buffer<int> f = e;
|
||||||
assert (f == e);
|
assert (f == e);
|
||||||
|
|
||||||
|
buffer<char> g;
|
||||||
|
g.append("hello", 5);
|
||||||
|
assert (g.size() == 5);
|
||||||
|
|
||||||
|
g.append(g);
|
||||||
|
assert (g.size() == 10);
|
||||||
|
assert ( !memcmp(g.begin(), "hellohello", 10) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user