Myicq

Testfile CJK - result is empty ?

4 posts in this topic

#1 ·  Posted (edited)

I am doing some test with iconv, to see what characters can be converted. To do this, I am creating a list of chinese characters, according to the list here.

For blocks 1 and 2 this works as expected.

But for some reason, blocks 3, 4 and 5 does not return a byte for the chinese character.

Am I missing something ?

My code :

$of = FileOpen("utf_block4.txt", 2+128) ; 32 = UTF16LE, 128 = UTF8 BOM
$myvar = ""

for $i = 0x2A700 to 0x2B734
        $myvar &= hex($i, 6) & " : >" & ChrW($i) & "<" & @CRLF
Next

FileWrite($of, $myvar)
FileWriteLine($of, "")
FileClose($of)

Edit: the forum won't let me post what I should get for the code.

Working version of block 1, first 5 lines - to see example output - is:

4E00 : >一<
4E01 : >丁<
4E02 : >丂<
4E03 : >七<
4E04 : >丄<
Edited by Myicq

I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites



OK, so I found the culprit:

 

ChrW(x):

UNICODEcode A unicode code in the range 0-65535 (e.g., 65 returns the capital letter A).

 

Now, what do I do to return a string above 0xFFFF codepoints ?


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites

Thanks to trancexx  - you are a true Wizard.

Func _ChrW($iCodePoint) ; By trancexx
    If $iCodePoint <= 0xFFFF Then Return ChrW($iCodePoint)
; 
; uncomment if you need the @error value
;    If $iCodePoint > 0x10FFFF Then Return SetError(1, 0, "")
    Local $tOut = DllStructCreate("word[2]")
    DllStructSetData($tOut, 1, BitShift($iCodePoint, 10) + 0xD7C0, 1)
    DllStructSetData($tOut, 1, BitAND($iCodePoint, 0x3FF) + 0xDC00, 2)
    Return BinaryToString(DllStructGetData(DllStructCreate("byte[4]", DllStructGetPtr($tOut)), 1), 2)
EndFunc

Would be nice to have support for codepoints above 0xFFFF natively. But for now, problem solved.


I am just a hobby programmer, and nothing great to publish right now.

Share this post


Link to post
Share on other sites

Yeah, currently AutoIt is limited to UCS-2 charset, which is (roughly) the same as Unicode plane 0, representing every codepoint into a single 16-bit unit. Hence higher Unicode planes can't be represented natively like them would under UTF-16.

This will be a growing concern in future as higher planes become more commonly used.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now