Syntax
int CONV_OutputMode(
int mode
);
Parameters
- mode
-
[in] Specify the output mode of the conversion result.
Value Description CONV_OUTPUT_MODE_DEFAULT The conversion result is output as a character string terminated by NUL. (Default) CONV_OUTPUT_MODE_COMPOSITE Outputs the conversion result in a composite format that includes both the local character code string and the UTF-8 string. CURRENT_MODE Returns the current setting.
Return value
Returns the current output mode setting.Remarks
The output format of the following functions can be changed by setting the output mode with this function.
CONV_CP437oseToUtf8String function
CONV_LocalToUtf8String function
CONV_SjisToUtf8String function
CONV_Utf8ToCP437oseString function
CONV_Utf8ToLocalString function
CONV_Utf8ToSjisString function
CONV_LocalToUtf8String function
CONV_SjisToUtf8String function
CONV_Utf8ToCP437oseString function
CONV_Utf8ToLocalString function
CONV_Utf8ToSjisString function
The output format while CONV_OUTPUT_MODE_DEFAULT (default format) is selected by this function is as follows.
Conversion result string NUL
The output format while CONV_OUTPUT_MODE_COMPOSITE (composite format) is selected by this function is as follows.
If the conversion result is different from the character string before conversion:
Local character code string NUL UTF-8 string NUL
If the conversion result is the same as the character string before conversion:
String NUL NUL
In the output of composite format, regardless of the type of conversion function, the local character code string and the UTF-8 string are always output in that order. Also note that the value output to the output_length parameter of conversion functions returns the number of bytes in the string of the destination character code.
Example 1: Output of CONV_CP437oseToUtf8String function for "µΣ" of CP437_ose string.
Example 2: Output of CONV_Utf8ToCP437oseString function for "µΣ" of UTF-8 string.
Example 3: Output of CONV_CP437oseToUtf8String function for "123" of CP437_ose string.
"µΣ" of CP437_ose string | NUL | "µΣ" of UTF-8 string | NUL |
← output_length = 4 → |
Example 2: Output of CONV_Utf8ToCP437oseString function for "µΣ" of UTF-8 string.
"µΣ" of CP437_ose string | NUL | "µΣ" of UTF-8 string | NUL |
← output_length = 2 → |
Example 3: Output of CONV_CP437oseToUtf8String function for "123" of CP437_ose string.
"123" | NUL | NUL |
← output_length = 3 → |
Requirements
Header file:
CodeConversion.h : ver. 1.1.1 or later.Library file:
libCodeConversion.a : ver. 1.1.1 or later.
libSTARTUPOPH5000.a
Sample
#include <stdio.h>
#include "lib.h"
#include "CodeConversion.h"
// Get UTF-8 string from composite string buffer.
static char *getUtf8(char *buf)
{
char *rp = buf;
while(*rp++){ // skip the 1st string.
;
}
if (*rp){
return rp; // Return 2nd string if exists.
}else{
return buf; // Return 1st string otherwise.
}
}
void main(void)
{
size_t output_length;
char *src = "µΣ";
printf("src=[%s]\n\n", src);
// Save current output mode
int original_mode = CONV_OutputMode(CURRENT_MODE);
// Set CONV_OUTPUT_MODE_COMPOSITE
CONV_OutputMode(CONV_OUTPUT_MODE_COMPOSITE);
printf("CP437ose->UTF8\n");
char *output1 = CONV_CP437oseToUtf8String(src, -1, NULL, &output_length);
char *utf1 = getUtf8(output1);
printf(" CP437_ose=[%s]\n", output1);
printf(" UTF-8 =[%s]\n", utf1);
printf(" length =%d\n\n", (int)output_length); // = 4
printf("UTF-8->CP437ose\n");
char *output2 = CONV_Utf8ToCP437oseString(utf1, -1, NULL, &output_length);
char *utf2 = getUtf8(output2);
printf(" CP437_ose=[%s]\n", output2);
printf(" UTF-8 =[%s]\n", utf2);
printf(" length =%d\n", (int)output_length); // = 2
// Restore output mode
CONV_OutputMode(original_mode);
free(output1);
free(output2);
while(1)
{
Idle();
}
}
Last updated: 2021/09/02