Kbase P179756: How to output data in the UTF-16LE or UTF-16BE codepage?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  30/12/2010 |
|
Status: Unverified
GOAL:
How to output data in the UTF-16LE or UTF-16BE codepage?
GOAL:
Is it possible to output data in UTF-16?
FACT(s) (Environment):
OpenEdge 10.x
FIX:
It is possible to output data using UTF-16, but because OpenEdge only supports conversions between UTF-8 and UTF-16, the session must be started with -cpinternal UTF-8. In addition because here is only partial support for UTF-16 for this example it is recommended to set -cpstream to UTF-8.
Start a session using:
prowin32.exe -cpinternal UTF-8 -cpstream UTF-8
Then use code similar to the following:
DEFINE VARIABLE vLongchar AS LONGCHAR NO-UNDO.
DEFINE VARIABLE vLongchar2 AS LONGCHAR NO-UNDO.
FIX-CODEPAGE(vLongChar) = "UTF-8".
FIX-CODEPAGE(vLongChar2) = "UTF-16LE". /* Change to UTF-16BE for BE */
/* create string 'A?A' in UTF-8 encoded longchar */
vLongChar = "A" + CHR(14844588,"UTF-8","UTF-8") + "A".
/* Copy and convert UTF-8 encoded longchar to UTF-16 encoded longchar */
COPY-LOB FROM vLongChar TO OBJECT vLongchar2.
/* Copy UTF-16 encoded longchar to output file */
/* NO-CONVERT is needed to prevent a conversion to cpstream at output */
COPY-LOB FROM vLongchar2 TO FILE "utf16out.txt" NO-CONVERT.
/* The resulting file will contain the following UTF-16LE byte sequence 41 00 AC 20 41 00 */
/* For UTF-16BE the resulting file will contain 00 41 20 AC 00 41 */