code_cvt()
Convert a string from one codeset to another.
Syntax
Parameters
Parameter | Definition |
---|---|
source_cs | codeset of textValid Values |
dest_cs | codeset to which you want to convert textValid Values |
text | text string that you want to convert |
Description
The code_cvt() function converts text from the codeset specified by source_cs to the dest_cs codeset and returns text. You can convert only between two codesets that represent the same language. For example, you can convert between CP932 and eucJP because both codesets represent the Japanese language.
The following table shows the codesets that you can use with this function.
Supported Codeset Names
Codeset Name | Language |
---|---|
C | English |
CP932 | Japanese |
eucJP | Japanese |
SJIS | Japanese |
eucKR | Korean |
gb | Simplified Chinese |
big5 | Traditional Chinese |
eucTW | Traditional Chinese |
If the code_cvt() function fails, it returns an empty string and sets the PSL errnovariable to one of the values in the following table:
errno Value | Description of Failure |
---|---|
135 | E_PSL_CODECVT_INVALID_MB |
136 | E_PSL_CODECVT_NO_CONV |
137 | E_PSL_CODECVT_SAME |
Example
In this example, a user-defined function runs the code_cvt() function, verifies that the conversion was successful, and displays the result:
{
ret = code_cvt(from, to, data);
if (ret == 0 || errno != err)
{
printf("Conversion %d failed. ret = 0, errno = %d,
expect_err = %d\n",id, errno, err);
}
else
{
save_err = errno;
printf("ID %d, conversion is complete -- \n", id);
printf(" [from] %s\n", data);
printf(" [to] %s<<<errno=%d>>>\n", ret, save_err);
}
}