Converts a UTF-8 string to an SJIS string.

Syntax

char *CONV_Utf8ToSjisString(
  char *src,
  int length,
  int *error_code,
  size_t *output_length
);

Parameters

src
[in] A pointer to a UTF-8 string.
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.

Return value

Returns a pointer to the buffer that stores the conversion result if the conversion is successful, NULL otherwise.

Remarks

Converts a string of the length specified by length from the beginning of the UTF-8 string pointed to by src to a SJIS string, 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 the character code of the SJIS, 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 codeDescription
CONV_UNSUPPORTED_CODE_WARNINGIt 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 codeDesription
CONV_INVALID_PARAMETER_ERRORParameter error.
CONV_MEMORY_ALLOCATION_ERRORMemory allocation error.
CONV_INVALID_UTF8_FORMAT_ERRORA byte sequence that does not meet the UTF-8 standard has been detected.

If this function returns a value other than NULL, you need to free the buffer with the free function.

Requirements

Header file:
CodeConversion.h
Library file:
libCodeConversion.a
libSTARTUPOPH5000.a


Last updated: 2021/08/02