Converting text between different character encodings.
More...
#include <charset_convert.hh>
Converting text between different character encodings.
CCharsetConvert uses iconv(3)
to perform charset conversion operations. It manages system resource allocation and deallocation, conversion adjustment and error handling.
- Note
- CCharsetConvert object can NOT be copied.
Conversion mode.
Enumerator |
---|
kNormal |
Default mode.
|
kTranslit |
Characters being converted are transliterated when needed and possible. This means that when a character cannot be represented in the target character set, it can be approximated through one or several similar looking characters. Characters that are outside of the target character set and cannot be transliterated are replaced with a question mark (?) in the output.
|
kIgnore |
Characters that cannot be converted are discarded and an error is printed after conversion.
|
CCharsetConvert::CCharsetConvert |
( |
| ) |
|
|
inline |
Construct a default object, with no ability for conversion.
Please use init to initialize this object for use.
- See also
- init
CCharsetConvert::CCharsetConvert |
( |
const std::string & |
fromCode, |
|
|
const std::string & |
toCode, |
|
|
EMode |
mode = kNormal |
|
) |
| |
|
inline |
Construct a usable converter.
For a full encoding names list supported by your system, please run iconv --list
.
- Parameters
-
fromCode | Encoding name for source text, e.g. "UTF8" |
toCode | Encoding name for destination text, e.g. "GB2312" |
mode | Conversion mode, see EMode |
bool CCharsetConvert::convert |
( |
const std::string & |
source, |
|
|
std::string & |
dest |
|
) |
| |
|
inline |
Convert text from source encoding to destination encoding.
If dest
is not empty, the conversion result will append to dest
.
- Parameters
-
[in] | source | Source text |
[out] | dest | A String to receive the result of conversion |
- Returns
true
if succeeded; otherwise false
const std::string CCharsetConvert::fromCode |
( |
| ) |
const |
|
inline |
Get encoding name for source text.
If this object is not initialized, an empty string will be returned.
- Returns
- Encoding name for source text
bool CCharsetConvert::init |
( |
const std::string & |
fromCode, |
|
|
const std::string & |
toCode, |
|
|
EMode |
mode = kNormal |
|
) |
| |
|
inline |
Initialize a usable converter.
If this object is already initialized, this function will fail.
For a full encoding names list supported by your system, please run iconv --list
.
- Parameters
-
fromCode | Encoding name for source text, e.g. "UTF8" |
toCode | Encoding name for destination text, e.g. "GB2312" |
mode | Conversion mode, see EMode |
- Returns
true
if succeeded; otherwise false
EMode CCharsetConvert::mode |
( |
| ) |
const |
|
inline |
Get conversion mode.
If this object is not initialized, kNormal
will be returned.
- Returns
- Conversion mode
const std::string CCharsetConvert::toCode |
( |
| ) |
const |
|
inline |
Get encoding name for destination text.
If this object is not initialized, an empty string will be returned.
- Returns
- Encoding name for destination text
std::string CCharsetConvert::toString |
( |
| ) |
const |
|
inline |
Get a readable description of this object.
- Returns
- A readable description of this object
bool CCharsetConvert::valid |
( |
| ) |
const |
|
inline |
Test whether this object is initialized.
- Returns
true
if this object is already initialized; otherwise false
The documentation for this class was generated from the following file: