//set a new position //if going too much back, restart the iterator streampos StringIteratorStreamBuf::seekpos ( streampos sp, ios_base::openmode which ) { if(!(which & ios_base::in)) return -1; if(sp < begin_offset) { setg(eback(), eback(), egptr()); pbackfail(EOF); if(sp < begin_offset) { //restart the iterator if(!reset()) return -1; buffer[0].resize(0); buffer[1].resize(0); current_buffer = last_buffer = 0; begin_offset = 0; is_eof = false; setg(NULL, NULL, NULL); } } while(sp >= (begin_offset+(streamoff)buffer[current_buffer].length())) { if(underflow() == EOF) { if(sp == (begin_offset+(streamoff)buffer[current_buffer].length())) break; return -1; } } setg(eback(), eback() + (streamoff)(sp - begin_offset), egptr()); return sp; }
int streambuf::sputbackc(char c) { if (_gptr > _eback && (unsigned char)_gptr[-1] == (unsigned char)c) { _gptr--; return (unsigned char)c; } return pbackfail(c); }
int streambuf::sungetc() { if (_gptr > _eback) { _gptr--; return (unsigned char)*_gptr; } else return pbackfail(EOF); }
// Unput one character. int_type sunputc() { if( (!pptr()) || (pptr() == pbase()) ) return pbackfail(); pbump(-1); // This is safe because *epptr() always is '\0' and inside // the backing buffer. return traits_type::to_int_type(*(pptr()+1)); }
int streambuf::sputbackc(char c) { #if defined(OS_INCLUDE_STREAMBUF_BUFFERS) if (mgbeg == 0 || mgnext == mgbeg || !traits::eq(c, gptr()[-1])) { return pbackfail(traits::to_int(c)); } gbump(-1); return traits::to_int(*gptr()); #else c = c; return traits::eof(); #endif }
/** Move get pointer backwards and return bit at new position. \param[out] value Bit before position prior to call. \return Whether okay (eof has not been encountered). */ bool sungetb(bitfield &b) { bool unget_succeeded; if (gptr() == std::streampos(-1) || gptr() == eback()) { bitfield dummy; unget_succeeded = pbackfail(dummy); } else { gbump(-1); unget_succeeded = atgptrb(b); } return unget_succeeded; }
/** Put bit at get pointer. \param[out] b Bit to be put back. \return Whether okay (eof has not been encountered). */ bool sputbackb(bitfield b) { bool putback_succeeded; if (gptr() == std::streampos(-1) || gptr() == eback() || b != atgptrb(-1)) { putback_succeeded = pbackfail(b); } else { gbump(-1); putback_succeeded = gptr() != std::streampos(-1); } return putback_succeeded; }