code_cvt()


Convert a string from one codeset to another.

Syntax

code_cvt(source_cs, dest_cs, text)

Parameters

Parameter

Definition

source_cs

codeset of textValid Values 
0, "", or any supported codeset name ( Supported Codeset Names)
If 0 or "" is specified, this function uses the codeset of the CTYPE locale category.

dest_cs

codeset to which you want to convert textValid Values 
Same as source_cs.

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

Note

 This function provides support for internationalized PSL scripts. For more information about internationalization, see PATROL Script Language Reference Manual Volume 1 --PSL Essentials.

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 
text contains invalid characters. This function replaces each invalid character with a question mark and returns text.

136

E_PSL_CODECVT_NO_CONV 
No support for conversion between source_cs and dest_cs.

137

E_PSL_CODECVT_SAME 
Source_cs and dest_cs are the same codeset.

If text is an empty string, code_cvt() returns an empty string, but it does not assign a value to errno. 

Example

In this example, a user-defined function runs the code_cvt() function, verifies that the conversion was successful, and displays the result:

function use_code_cvt(id, from, to, data, err)
{
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);
}
}

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*