38 opencc(
const char* config_file = NULL)
44 if (od != (opencc_t)-1) {
49 operator bool()
const {
50 return od != (opencc_t)-1;
53 int open(
const char* config_file) {
54 if (od != (opencc_t)-1) {
58 return (od == (opencc_t)-1) ? (-1) : (0);
61 int set_conversion_mode(opencc_conversion_mode conversion_mode) {
62 if (od == (opencc_t)-1) {
69 long convert(
const std::string& in, std::string& out,
long length = -1) {
70 if (od == (opencc_t)-1) {
77 if (outbuf == (
char*)-1) {
90 long convert(
const std::wstring& in, std::wstring& out,
long length = -1) {
91 if (od == (opencc_t)-1) {
94 size_t inbuf_left = in.length();
95 if ((length >= 0) && (length < (
long)inbuf_left)) {
98 const ucs4_t* inbuf = (
const ucs4_t*)in.c_str();
100 while (inbuf_left != 0) {
105 outbuf_left = inbuf_left + 64;
106 out.resize(count + outbuf_left);
107 outbuf = (ucs4_t*)out.c_str() + count;
109 &inbuf_left, &outbuf, &outbuf_left);
110 if (retval == (
size_t)-1) {
116 out.resize(count + 1);
121 opencc_error errno()
const {
125 void perror(
const char* spec =
"OpenCC")
const {
134 #endif // ifdef __cplusplus
char * opencc_convert_utf8(opencc_t t_opencc, const char *inbuf, size_t length)
Converts UTF-8 string from inbuf.
opencc_t opencc_open(const char *config_file)
Makes an instance of opencc.
int opencc_close(opencc_t t_opencc)
Destroys an instance of opencc.
void opencc_perror(const char *spec)
Prints the error message to stderr.
opencc_error opencc_errno(void)
Returns an opencc_convert_errno_t which describes the last error.
void opencc_set_conversion_mode(opencc_t t_opencc, opencc_conversion_mode conversion_mode)
Changes the mode of conversion.
size_t opencc_convert(opencc_t t_opencc, ucs4_t **inbuf, size_t *inbuf_left, ucs4_t **outbuf, size_t *outbuf_left)
Converts a UCS-4 string from *inbuf to *outbuf.