BloombergLP::bdlde::Utf8Util::readIfValid

Copy valid UTF-8 from input into outputBuffer.

Synopsis

Declared in <bdlde_utf8util.h>

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

Description

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.

Return Value

number of valid UTF-8 bytes written to outputBuffer

Parameters

NameDescription
statusreceives 0, a positive truncated-read value, or ErrorStatus
outputBufferbuffer that receives valid UTF-8 bytes
outputBufferLengthcapacity of outputBuffer in bytes
inputstream buffer from which UTF-8 is read