Utf8Convert Class Reference

#include <Pt/Utf8.h>

UTF-8 string converter. More...

Public Member Functions

 Utf8Convert (TextCodec< Char, char > *codec)
 Construct with codec.
 
 ~Utf8Convert ()
 Destructor.
 
std::string fromBytes (const char *bytes, std::size_t n)
 Decode from external encoding.
 
std::string fromBytes (const std::string &bytes)
 Decode from external encoding.
 
std::string toBytes (const char *utf8, std::size_t n)
 Encode to external encoding.
 
std::string toBytes (const std::string &bytes)
 Encode to external encoding.
 

Detailed Description

Utf8Convert converts between strings in external encodings and UTF-8. It uses a fixed internal buffer for the conversion, so temporary allocations are not performed. A Wave::TextCodec facet is used for the actual conversion. It can either be default constructed with new and ownership is passed to the Utf8Convert or with a refcount greater than 0, which indicates ownership by the caller.

// converter deletes codec
Pt::Utf8Convert conv(new Pt::Latin1Codec);
std::string latin1 = ...;
std::string utf8 = conv.fromBytes(latin1);
// converter doe not delete codec
Pt::Latin1Codec codec(1);
Pt::Utf8Convert conv(codec);
string utf8 = ...;
std::string latin1 = conv.toBytes(utf8);