Open Chinese Convert 1.1.5
A project for conversion between Traditional and Simplified Chinese
Macros | Typedefs | Functions
OpenCC C API

API in C language. More...

Macros

#define OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD   "s2t.json"
 Filename of default Simplified to Traditional configuration.
 
#define OPENCC_DEFAULT_CONFIG_TRAD_TO_SIMP   "t2s.json"
 Filename of default Traditional to Simplified configuration.
 

Typedefs

typedef void * opencc_t
 Type of opencc descriptor.
 

Functions

OPENCC_EXPORT opencc_t opencc_open (const char *configFileName)
 Makes an instance of opencc. More...
 
OPENCC_EXPORT int opencc_close (opencc_t opencc)
 Destroys an instance of opencc. More...
 
OPENCC_EXPORT size_t opencc_convert_utf8_to_buffer (opencc_t opencc, const char *input, size_t length, char *output)
 Converts UTF-8 std::string. More...
 
OPENCC_EXPORT char * opencc_convert_utf8 (opencc_t opencc, const char *input, size_t length)
 Converts UTF-8 std::string This function returns an allocated C-Style std::string, which stores the converted std::string. More...
 
OPENCC_EXPORT void opencc_convert_utf8_free (char *str)
 Releases allocated buffer by opencc_convert_utf8. More...
 
OPENCC_EXPORT const char * opencc_error (void)
 Returns the last error message. More...
 

Detailed Description

API in C language.

Function Documentation

◆ opencc_close()

OPENCC_EXPORT int opencc_close ( opencc_t  opencc)

Destroys an instance of opencc.

Parameters
openccThe description pointer.
Returns
0 on success or non-zero number on failure.

◆ opencc_convert_utf8()

OPENCC_EXPORT char * opencc_convert_utf8 ( opencc_t  opencc,
const char *  input,
size_t  length 
)

Converts UTF-8 std::string This function returns an allocated C-Style std::string, which stores the converted std::string.

You MUST call opencc_convert_utf8_free() to release allocated memory.

Parameters
openccThe opencc description pointer.
inputThe UTF-8 encoded std::string.
lengthThe maximum length in byte to convert. If length is (size_t)-1, the whole std::string (terminated by '\0') will be converted.
Returns
The newly allocated UTF-8 std::string that stores text converted, or NULL on error.

◆ opencc_convert_utf8_free()

OPENCC_EXPORT void opencc_convert_utf8_free ( char *  str)

Releases allocated buffer by opencc_convert_utf8.

Parameters
strPointer to the allocated std::string buffer by opencc_convert_utf8.

◆ opencc_convert_utf8_to_buffer()

OPENCC_EXPORT size_t opencc_convert_utf8_to_buffer ( opencc_t  opencc,
const char *  input,
size_t  length,
char *  output 
)

Converts UTF-8 std::string.

Parameters
openccThe opencc description pointer.
inputThe UTF-8 encoded std::string.
lengthThe maximum length in byte to convert. If length is (size_t)-1, the whole std::string (terminated by '\0') will be converted.
outputThe buffer to store converted text. You MUST make sure this buffer has sufficient space.
Returns
The length of converted std::string or (size_t)-1 on error.

◆ opencc_error()

OPENCC_EXPORT const char * opencc_error ( void  )

Returns the last error message.

Note that this function is the only one which is NOT thread-safe.

◆ opencc_open()

OPENCC_EXPORT opencc_t opencc_open ( const char *  configFileName)

Makes an instance of opencc.

Parameters
configFileNameLocation of configuration file. If this is set to NULL, OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD will be loaded.
Returns
A description pointer of the newly allocated instance of opencc. On error the return value will be (opencc_t) -1.