Utf8Validator Class Reference

#include <Pt/Utf8.h>

Incremental UTF-8 well-formedness checker. More...

Public Member Functions

 Utf8Validator ()
 Creates an empty validator.
bool advance (const char *data, std::size_t n)
 Feeds the next bytes.
bool finish () const
 Returns true if no error occurred and no character is incomplete.
void reset ()
 Returns the validator to the empty initial state.

(Note that these are not member symbols.)

bool isValidUtf8 (const char *data, std::size_t n)
 Returns true if data is a complete well-formed UTF-8 sequence.

Detailed Description

Utf8Validator checks that a byte sequence is well-formed UTF-8 as defined by RFC 3629. Bytes may arrive in chunks; a character may be split across feeds. Overlong encodings, surrogate code points and values above U+10FFFF are rejected. After an error, further feeds fail until reset().

v.advance(part1, n1);
v.advance(part2, n2);
if( ! v.finish() )
{
// incomplete or ill-formed
}
Incremental UTF-8 well-formedness checker.
Definition Utf8.h:342
bool advance(const char *data, std::size_t n)
Feeds the next bytes.
bool finish() const
Returns true if no error occurred and no character is incomplete.
Definition Utf8.h:360

isValidUtf8() checks a complete sequence in one call.

Member Function Documentation

◆ advance()

bool advance ( const char * data,
std::size_t n )
Returns
False if the sequence is ill-formed.