BloombergLP::bdlde::Utf8Util::readIfValid

Read from the specified input and copy valid UTF-8 (only) to the specified outputBuffer having the specified outputBufferLength (in bytes). Load the specified status with: * 0 if input reached eof without encountering any invalid UTF-8 or prematurely exhausting outputBuffer. * A positive value if input was not completely read due to outputBuffer being filled (or nearly filled) without encountering any invalid UTF-8. * A negative value from ErrorStatus if invalid UTF-8 was encountered (without having written the invalid sequence to outputBuffer). Return the number of bytes of valid UTF-8 written to 'outputBuffer. If no invalid UTF-8 is encountered, or if input supports sputbackc with a putback buffer capacity of at least 4 bytes, input will be left positioned at the end of the valid UTF-8 read, otherwise, input will be left in an unspecified state. The behavior is undefined unless 4 <= outputBufferLength. Note that this function will stop reading input when less than 4 bytes of space remain in outputBuffer to prevent the possibility of a 4-byte UTF-8 sequence being truncated partway through.

Synopsis

Declared in <bdlde_utf8util.h>

static
size_type
readIfValid(
    int* status,
    char* outputBuffer,
    size_type outputBufferLength,
    std::streambuf* input);