BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlde::Utf8CheckingInStreamBufWrapper Class Reference

#include <bdlde_utf8checkinginstreambufwrapper.h>

Inheritance diagram for bdlde::Utf8CheckingInStreamBufWrapper:

Public Types

enum  { k_SEEK_FAIL = +1 }
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (Utf8CheckingInStreamBufWrapper, bslma::UsesBslmaAllocator)
 
 Utf8CheckingInStreamBufWrapper ()
 
 Utf8CheckingInStreamBufWrapper (bslma::Allocator *basicAllocator)
 
 Utf8CheckingInStreamBufWrapper (bsl::streambuf *streamBuf, bslma::Allocator *basicAllocator=0)
 
 ~Utf8CheckingInStreamBufWrapper () BSLS_KEYWORD_OVERRIDE
 Destroy this object.
 
void reset (bsl::streambuf *streamBuf)
 
int errorStatus () const
 
bool isValid () const
 

Static Public Member Functions

static const char * toAscii (int errorStatus)
 

Protected Member Functions

int_type overflow (int_type=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
 
bsl::streamsize showmanyc () BSLS_KEYWORD_OVERRIDE
 
int_type underflow () BSLS_KEYWORD_OVERRIDE
 
void imbue (const bsl::locale &locale) BSLS_KEYWORD_OVERRIDE
 
int_type pbackfail (int_type c=traits_type::eof()) BSLS_KEYWORD_OVERRIDE
 
pos_type seekoff (off_type offset, bsl::ios_base::seekdir whence, bsl::ios_base::openmode mode) BSLS_KEYWORD_OVERRIDE
 
pos_type seekpos (pos_type offset, bsl::ios_base::openmode mode) BSLS_KEYWORD_OVERRIDE
 
bsl::streamsize xsgetn (char *buffer, bsl::streamsize numBytes) BSLS_KEYWORD_OVERRIDE
 
bsl::streamsize xsputn (const char *, bsl::streamsize) BSLS_KEYWORD_OVERRIDE
 

Detailed Description

This class inherits from bsl::streambuf, and holds and wraps another streambuf. It forwards input through the held streambuf, and checks for invalid UTF-8. The wrapping object does not support ouput, only input. If the held streambuf supports seeking, seeks are supported, though not forward seeks, and pubseekoff(0, bsl::ios_base::cur) is supported whether the wrapped streambuf supports seeking or not.

See bdlde_utf8checkinginstreambufwrapper

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
k_SEEK_FAIL 

Constructor & Destructor Documentation

◆ Utf8CheckingInStreamBufWrapper() [1/3]

bdlde::Utf8CheckingInStreamBufWrapper::Utf8CheckingInStreamBufWrapper ( )

◆ Utf8CheckingInStreamBufWrapper() [2/3]

bdlde::Utf8CheckingInStreamBufWrapper::Utf8CheckingInStreamBufWrapper ( bslma::Allocator basicAllocator)
explicit

Create a Utf8StreamBufInputWrapper object having no associated streambuf. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0 or not specified, the currently installed default allocator is used.

◆ Utf8CheckingInStreamBufWrapper() [3/3]

bdlde::Utf8CheckingInStreamBufWrapper::Utf8CheckingInStreamBufWrapper ( bsl::streambuf *  streamBuf,
bslma::Allocator basicAllocator = 0 
)
explicit

Create a Utf8StreamBufInputWrapper associated with the specified streamBuf. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~Utf8CheckingInStreamBufWrapper()

bdlde::Utf8CheckingInStreamBufWrapper::~Utf8CheckingInStreamBufWrapper ( )

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

bdlde::Utf8CheckingInStreamBufWrapper::BSLMF_NESTED_TRAIT_DECLARATION ( Utf8CheckingInStreamBufWrapper  ,
bslma::UsesBslmaAllocator   
)

◆ errorStatus()

int bdlde::Utf8CheckingInStreamBufWrapper::errorStatus ( ) const
inline

Return the current error mode of this object. This will be either 0 (no errors or end of data), k_SEEK_FAIL, which is positive, or a value from Utf8Util::ErrorStatus, which are all negative.

◆ imbue()

void bdlde::Utf8CheckingInStreamBufWrapper::imbue ( const bsl::locale &  locale)
protected

If sb is the name of the streambuf held by this object, set sb to the specified locale as though sb.pubimbue(locale) had been called. If this object does not hold a streambuf, this method has no effect. Note that this function is forwarded to by the public method pubimbue in the base class.

◆ isValid()

bool bdlde::Utf8CheckingInStreamBufWrapper::isValid ( ) const
inline

Return true if this wrapper currently holds a streambuf and is not in a failed seek state.

◆ overflow()

int_type bdlde::Utf8CheckingInStreamBufWrapper::overflow ( int_type  = traits_type::eof())
protected

Unconditionally return traits_type::eof(). The optionally specified argument is ignored.

◆ pbackfail()

int_type bdlde::Utf8CheckingInStreamBufWrapper::pbackfail ( int_type  c = traits_type::eof())
protected

Back up input one byte. Return the byte at the new position, or eof with the state of this object unchanged on failure. If the optionally specified c is not eof, substitute c for the previous byte and return that value. If c is eof, do not substitute it for the previous byte and return the byte was there, or if the previous byte is unknown, fail. If values of c that are not eof are specified, this function will succeed for at least 8 successive calls, possibly many more times. The behavior is undefined unless c is either eof or a value representable as a char_type . Note that this is forwarded to with a char_type passed to c by the public method sputbackc in the base class, and called with eof passed to c by the public method sungetc in the base class.

◆ reset()

void bdlde::Utf8CheckingInStreamBufWrapper::reset ( bsl::streambuf *  streamBuf)

Associate this object with the specified streamBuf, releasing any previously held streambuf.

◆ seekoff()

pos_type bdlde::Utf8CheckingInStreamBufWrapper::seekoff ( off_type  offset,
bsl::ios_base::seekdir  whence,
bsl::ios_base::openmode  mode 
)
protected

Move the position associated with this object according to the specified offset and whence:

  • If whence is bsl::ios_base::beg, set the position to offset bytes from the beginning.
  • If whence is bsl::ios_base::cur, advance the position by offset bytes (note that offset is signed).
  • whence == bsl::ios_base::end is unsupported and a seek fail will result.

A seek can fail if

  • the object was already in a failed seek state and the seek was not an absolute seek to the beginning,
  • the object is not bound to a held streambuf,
  • whence is not bsl::ios_base::beg or bsl::ios_base::cur,
  • the destination is negative,
  • the destination is forward of the current position, or
  • a seek on the held streambuf is necessary and that streambuf does not support seeking,

which will put the object into a failed seek state. When the object is in a failed seek state, errorStatus() will equal k_SEEK_FAIL and the object will no longer have a valid position, meaning that input and relative seeks will fail, until the object is made to recover by either calling reset or an absolute seek to position 0.

If a seek is performed on the held streambuf, the specified mode will be propagated to it. The behavior is undefined unless bsl::ios_base::in is set in mode. Note that this function is forwarded to by the public method pubseekoff in the base class.

seekoff(0, bsl::ios_base::cur, mode) is permissible whether the held streambuf is seekable or not and will never result in a seek on the held streambuf, returning the position in terms of the held streambuf if that streambuf is seekable and returning the position relative to when the held streambuf was bound to this object otherwise.

Some non-zero seeks will be performed without a seek on the held streambuf, but there is no simple way for the client to predict when this will be the case.

◆ seekpos()

pos_type bdlde::Utf8CheckingInStreamBufWrapper::seekpos ( pos_type  offset,
bsl::ios_base::openmode  mode 
)
protected

Set the position of this object to the specified absolute offset. If a seek on the held streambuf occurs, the specified mode is passed to it. This function delegates to seekoff(offset, bsl::ios_base::beg, mode), see that function for further detail. The behavior is undefined unless bsl::ios_base::in is set in mode. Note that this function is forwarded to by the public method pubseekpos in the base class.

◆ showmanyc()

bsl::streamsize bdlde::Utf8CheckingInStreamBufWrapper::showmanyc ( )
protected

Return the number of bytes that are guaranteed that can be read before underflow returns eof. If the object is not in a valid state, -1 will be returned. Note that often, the actual number of bytes that can be read will be much greater than the value returned by this function.

◆ toAscii()

static const char * bdlde::Utf8CheckingInStreamBufWrapper::toAscii ( int  errorStatus)
static

Return a description of the specified errorStatus. Note that errorStatus is either:

  • k_SEEK_FAIL
  • A value from Utf8Util::ErrorStatus, which are all negative, in the case of invalid UTF-8.
  • 0 if no errors have occurred, in which case NO_ERROR will be returned. Note that this includes the case where end of file has been reached without any error occurring.
  • If errorStatus is an invalid value, "(* unrecognized value *)" will be returned.

◆ underflow()

int_type bdlde::Utf8CheckingInStreamBufWrapper::underflow ( )
protected

Replenish the input buffer with data obtained from the held streambuf, and return the next byte of input (or eof if no input is available). This function assumes that either the input buffer is empty or that the end of it has been reached. If this object is not in a valid state, eof will be returned.

◆ xsgetn()

bsl::streamsize bdlde::Utf8CheckingInStreamBufWrapper::xsgetn ( char *  buffer,
bsl::streamsize  numBytes 
)
protected

Read up to the specified numBytes characters from this object to the specified buffer and return the number of characters successfully read. A return value of 0 means that either a UTF-8 error or end of file has been encountered (errorStatus must be called to distinguish between the two), but a non-zero return value less than numBytes will usually be returned when neither end of file nor a UTF-8 error has been encountered. The behavior is undefined unless 4 <= numBytes. Note that this function is forwarded to by the public method sgetn in the base class.

◆ xsputn()

bsl::streamsize bdlde::Utf8CheckingInStreamBufWrapper::xsputn ( const char *  ,
bsl::streamsize   
)
protected

Output function, not supported in this input-only implementation; stubbed out, arguments ignored, returns 0. Note that this function is forwarded to by sputn in the base class.


The documentation for this class was generated from the following file: