Ticket #3896: Bug in BinaryToString for single non-ANSI character (correct file).au3

File Bug in BinaryToString for single non-ANSI character (correct file).au3, 1.5 KB (added by anonymous, 2 years ago)
Line 
1#cs ----------------------------------------------------------------------------
2
3 AutoIt Version: 3.3.16.0
4 Author:         myName
5
6 Script Function:
7        Template AutoIt script.
8
9#ce ----------------------------------------------------------------------------
10
11; Script Start - Add your code below here
12
13; Bug in BinaryToString with single non-ANSI character
14$single_r_hacek = 0x99C5 ; LE UTF-code C599 for ř U+0159 LATIN SMALL LETTER R WITH CARON, NOT in ANSI
15$UTF8_single_r_hacek = BinaryToString($single_r_hacek, 4) ; convert to UTF-8 string
16ConsoleWrite(StringLen($UTF8_single_r_hacek))            ; gives WRONG output 3 instead of 1
17MsgBox(0, "", $UTF8_single_r_hacek)                      ; correct ř output
18FileWrite("single_test.txt", $UTF8_single_r_hacek)       ; WRONG 0xC5990000 in file
19$binfile = FileOpen("single_test_bin.txt", 16 + 2)
20FileWrite($binfile, $UTF8_single_r_hacek)                ; WRONG 0x720000 in binary file (ANSI/ASCII r)
21FileClose($binfile)
22
23$double_r_hacek = 0x99C599C5
24$UTF8_double_r_hacek = BinaryToString($double_r_hacek, 4) ; convert to UTF-8 string
25ConsoleWrite(StringLen($UTF8_double_r_hacek))            ; gives correct output 2
26MsgBox(0, "", $UTF8_double_r_hacek)                      ; correct řř output
27FileWrite("double_test.txt", $UTF8_double_r_hacek)       ; correct 0xC599C599 in file
28$binfile = FileOpen("double_test_bin.txt", 16 + 2)
29FileWrite($binfile, $UTF8_double_r_hacek)                ; WRONG 0x7272 in binary file
30FileClose($binfile)
31