[#BloombergLP-bdlde-Utf8Util-readIfValid]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlde.adoc[bdlde]::xref:BloombergLP/bdlde/Utf8Util.adoc[Utf8Util]::readIfValid
:relfileprefix: ../../../
:mrdocs:

Read from the specified `input` and copy _valid_ UTF&hyphen;8 (only) to the specified `outputBuffer` having the specified `outputBufferLength` (in bytes)&period; Load the specified `status` with&colon; &ast; 0 if `input` reached `eof` without encountering any invalid UTF&hyphen;8 or prematurely exhausting `outputBuffer`&period; &ast; A positive value if `input` was not completely read due to `outputBuffer` being filled (or nearly filled) without encountering any invalid UTF&hyphen;8&period; &ast; A negative value from `ErrorStatus` if invalid UTF&hyphen;8 was encountered (without having written the invalid sequence to `outputBuffer`)&period; Return the number of bytes of valid UTF&hyphen;8 written to &apos;outputBuffer&period; If no invalid UTF&hyphen;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&hyphen;8 read, otherwise, `input` will be left in an unspecified state&period; The behavior is undefined unless `4 &lt;&equals; outputBufferLength`&period; 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&hyphen;byte UTF&hyphen;8 sequence being truncated partway through&period;

== Synopsis

Declared in `&lt;bdlde&lowbar;utf8util&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
xref:BloombergLP/bdlde/Utf8Util/size_type.adoc[size&lowbar;type]
readIfValid(
    int* status,
    char* outputBuffer,
    xref:BloombergLP/bdlde/Utf8Util/size_type.adoc[size&lowbar;type] outputBufferLength,
    std::streambuf* input);
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
