mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 17:10:05 +00:00
Basic parsing for Archive II file
This commit is contained in:
parent
59d06a8632
commit
33c114ee9d
14 changed files with 412 additions and 1 deletions
30
wxdata/source/scwx/util/rangebuf.cpp
Normal file
30
wxdata/source/scwx/util/rangebuf.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <scwx/util/rangebuf.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
rangebuf::rangebuf(std::streambuf* sbuf, size_t size) :
|
||||
size_(size), sbuf_(sbuf), data_()
|
||||
{
|
||||
size_t bufferSize = std::max<size_t>(size, 4096u);
|
||||
data_.reserve(bufferSize);
|
||||
}
|
||||
|
||||
int rangebuf::underflow()
|
||||
{
|
||||
char* buf = data_.data();
|
||||
ptrdiff_t bufSize = data_.capacity();
|
||||
|
||||
// Read from underlying stream buffer into own buffer until needed characters
|
||||
// have been consumed
|
||||
size_t r(sbuf_->sgetn(buf, std::min<size_t>(bufSize, size_)));
|
||||
size_ -= r;
|
||||
setg(buf, buf, buf + r);
|
||||
return gptr() == egptr() ? traits_type::eof() :
|
||||
traits_type::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue