Syntax
char *CONV_LocalToUtf8String(
char *src,
int length,
int *error_code,
size_t *output_length,
CONV_LOCAL_TO_UNICODE LocalToUnicodeCallback
);
Parameters
- src
- [in] A pointer to a string of custom code.
- length
- [in] Specifies the number of bytes to convert. Negative values convert the range until the string pointed to by src ends with a NUL.
- error_code
- [out] A pointer to a variable that returns an error code. Specify NULL when no error code is required.
- output_length
- [out] A pointer to a variable that returns the number of output bytes excluding the NUL at the end of the conversion result. Specify NULL when the number of output bytes is not required.
- LocalToUnicodeCallback
- [in] A pointer to a callback function that converts custom code to Unicode.
Return value
Returns a pointer to the buffer that stores the conversion result if the conversion is successful, NULL otherwise.Remarks
Use this function to convert a string of custom code (original code) defined by the application program to the UTF-8 string.Converts a string of the length specified by length from the beginning of the custom code string pointed to by src with using the callback function specified in LocalToUnicodeCallback, and returns a pointer to the buffer that stores the conversion result.
If you specify a negative value for length, the range until the string pointed to by src ends with NUL is converted.
If a NUL is detected before the string pointed to by src reaches the length specified by length, the string up to the NUL is converted.
If the string pointed to by src contains a character code that cannot be converted to Unicode, replace that character with '?' and continue the conversion. In this case, it returns the following error code in the variable pointed to by error_code.
Error code | Description |
---|---|
CONV_UNSUPPORTED_CODE_WARNING | It contained a character code that could not be converted. |
If the conversion is successful, end the conversion result string with a NUL and return the number of bytes of the conversion result excluding the NUL to the variable pointed to by output_length.
If the conversion fails, it returns NULL and returns the following error code in the variable pointed to by error_code.
Error code | Desription |
---|---|
CONV_INVALID_PARAMETER_ERROR | Parameter error. |
CONV_MEMORY_ALLOCATION_ERROR | Memory allocation error. |
If this function returns a value other than NULL, you need to free the buffer with the free function.
Convert your custom code to Unicode with a callback function specified in LocalToUnicodeCallback. The interface of the callback function is as follows:
Syntax
typedef int (*CONV_LOCAL_TO_UNICODE)(
int localByte
);
Parameters
- localByte
- [in] Character code in the range 1-255. Specify custom character code.
Return value
Returns Unicode if the conversion is successful, -1 otherwise.Remarks
Converts the custom code specified in localByte to Unicode and returns it.This interface of the callback function is compatible with the following function:
CONV_CP437oseToUnicode function
Requirements
Header file:
CodeConversion.hLibrary file:
libCodeConversion.a
libSTARTUPOPH5000.a
Sample
Sample
// Callback function
int MyCP437ToUnicode(int localByte)
{
if (localByte == 0x9B){
return 0x00A2; // 0x9B -> '¢'
}else if (localByte == 0x9D){
return 0x00A5; // 0x9D -> '¥'
}else{
// Use CONV_CP437oseToUnicode() for the other code.
return CONV_CP437oseToUnicode(localByte);
}
}
// Customized conversion
char *MyCP437ToUtf8String(char *src, int length, int *error_code, size_t *output_length)
{
char *ret = CONV_LocalToUtf8String(src, length, error_code, output_length, MyCP437ToUnicode);
return ret;
}
See also
Last updated: 2021/08/02