Open Chinese Convert  0.4.3
A project for conversion between Traditional and Simplified Chinese
Defines | Functions
OpenCC API

API in C language. More...

Defines

#define OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD   "zhs2zht.ini"
 Filename of default Simplified to Traditional configuration.
#define OPENCC_DEFAULT_CONFIG_TRAD_TO_SIMP   "zht2zhs.ini"
 Filename of default Traditional to Simplified configuration.

Functions

opencc_t opencc_open (const char *config_file)
 Makes an instance of opencc.
size_t opencc_convert (opencc_t od, ucs4_t **inbuf, size_t *inbufleft, ucs4_t **outbuf, size_t *outbufleft)
 Converts a UCS-4 string from *inbuf to *outbuf.
char * opencc_convert_utf8 (opencc_t od, const char *inbuf, size_t length)
 Converts UTF-8 string from inbuf.
void opencc_convert_utf8_free (char *buf)
 Releases allocated buffer by opencc_convert_utf8.
int opencc_dict_load (opencc_t od, const char *dict_filename, opencc_dictionary_type dict_type)
 Loads a dictionary to default dictionary chain.
void opencc_set_conversion_mode (opencc_t od, opencc_conversion_mode conversion_mode)
 Changes the mode of conversion.
void opencc_perror (const char *spec)
 Prints the error message to stderr.

Detailed Description

API in C language.


Function Documentation

size_t opencc_convert ( opencc_t  od,
ucs4_t **  inbuf,
size_t *  inbufleft,
ucs4_t **  outbuf,
size_t *  outbufleft 
)

Converts a UCS-4 string from *inbuf to *outbuf.

Do not forget to assign **outbuf to L'\0' after called if you want to use it as a C-Style string.

Parameters:
odThe opencc description pointer.
inbufThe pointer to the UCS-4 string.
inbufleftThe maximum number of characters in *inbuf to be converted.
outbufThe pointer to the output buffer.
outbufleftThe size of output buffer.
Returns:
The number of characters in the input buffer that has been converted.

Definition at line 46 of file opencc.c.

char* opencc_convert_utf8 ( opencc_t  od,
const char *  inbuf,
size_t  length 
)

Converts UTF-8 string from inbuf.

This function returns an allocated C-Style string via malloc(), which stores the converted string. You should call opencc_convert_utf8_free() to release allocated memory.

Parameters:
odThe opencc description pointer.
inbufThe UTF-8 encoded string.
lengthThe maximum length of inbuf to convert. If length is set to -1, the whole c-style string in inbuf will be converted.
Returns:
The newly allocated UTF-8 string that stores text converted from inbuf.

Definition at line 66 of file opencc.c.

void opencc_convert_utf8_free ( char *  buf)

Releases allocated buffer by opencc_convert_utf8.

Parameters:
bufPointer to the allocated string buffer by opencc_convert_utf8.

Definition at line 138 of file opencc.c.

int opencc_dict_load ( opencc_t  od,
const char *  dict_filename,
opencc_dictionary_type  dict_type 
)

Loads a dictionary to default dictionary chain.

Parameters:
odThe opencc description pointer.
dict_filenameThe name (or location) of the dictionary file.
dict_typeThe type of the dictionary.
Returns:
0 on success or non-zero number on failure.
Deprecated:
This function is not recommended to use and will be removed.

Definition at line 181 of file opencc.c.

opencc_t opencc_open ( const char *  config_file)

Makes an instance of opencc.

Leave config_file to NULL if you do not want to load any configuration file.

Parameters:
config_fileLocation of configuration file.
Returns:
A description pointer of the newly allocated instance of opencc. On error the return value will be (opencc_t) -1.

Definition at line 142 of file opencc.c.

void opencc_perror ( const char *  spec)

Prints the error message to stderr.

Parameters:
specPrefix message.

Definition at line 220 of file opencc.c.

void opencc_set_conversion_mode ( opencc_t  od,
opencc_conversion_mode  conversion_mode 
)

Changes the mode of conversion.

Parameters:
odThe opencc description pointer.
conversion_modeConversion mode. Options are
  • OPENCC_CONVERSION_FAST
  • OPENCC_CONVERSION_SEGMENT_ONLY
  • OPENCC_CONVERSION_LIST_CANDIDATES

Definition at line 204 of file opencc.c.

 All Data Structures Files Functions Variables Defines