[progress Communities] [progress Openedge Abl] Forum Post: Re: Codepage Problems Utf8

Status
Not open for further replies.
P

Paul Clare

Guest
Hi Geir Otto, I would expect the data to be converted to iso8859-1 in your case. According to the rules for assignment when assigning character data to a longchar, data should be converted to -cpinternal or the fixed code page. The is a bug where this isn't happening for database CLOBs (article 000074626), but I made a quick test, and this seems to work as I would expect: DEF VARIABLE oStreamReader AS CLASS System.IO.StreamReader. DEFINE VARIABLE cPath AS CHARACTER NO-UNDO. DEF VARIABLE oEncoding AS System.Text.Encoding. DEFINE VARIABLE lc AS LONGCHAR NO-UNDO. DEFINE VARIABLE coutString AS CHARACTER NO-UNDO. /* Write UTF-8 vaue '££' (C2,A3 C2,A3) to text file. Total length 8 bytes */ OUTPUT to "C:\temp\MyTest.txt" CONVERT SOURCE SESSION:CPINTERNAL TARGET "UTF-8". DISPLAY CHR(163,SESSION:CPINTERNAL,"iso8859-1") + CHR(163,SESSION:CPINTERNAL,"iso8859-1") WITH NO-LABELS. OUTPUT close. oEncoding = System.Text.Encoding:UTF8. cPath = "C:\temp\MyTest.txt". oStreamReader = NEW System.IO.StreamReader(cPath,oEncoding,TRUE). lc = oStreamReader:ReadToEnd(). cOutstring = lc. MESSAGE "SESSION:CPINTERNAL : " SESSION:CPINTERNAL SKIP(2) "StreamReader to LONGCHAR" SKIP "---------------------------------------------------" SKIP "Longchar data length in Bytes (4 bytes for CR LF) : " LENGTH(lc,"RAW") SKIP "Longchar code page : " GET-CODEPAGE(lc) SKIP (2) "LONGCHAR copied to string" SKIP "---------------------------------------------------" SKIP "Variable data : " TRIM(coutString) SKIP "Variable data length in Bytes (4 bytes for CR LF) : " LENGTH(coutString,"RAW") SKIP SKIP(2) VIEW-AS ALERT-BOX INFO BUTTONS OK. Start the session with -cpinternal iso8859-1 -cpstream iso8859-1 and the byte length should be 6. Two bytes for the data converted to two single byte pound signs (£) and 4 bytes for the CR LF. Then do the same with -cpinternal UTF-8 -cpstream UTF-8 to see the unconverted difference. Paul.

Continue reading...
 
Status
Not open for further replies.
Top