| 1 | #include <file.au3>
|
|---|
| 2 | #include <Array.au3>
|
|---|
| 3 |
|
|---|
| 4 | Func ShowResults($CaseNo, $CaseDescription, $Results)
|
|---|
| 5 | MsgBox(0, _
|
|---|
| 6 | "Results - " & $CaseNo, _
|
|---|
| 7 | $CaseDescription & @LF & @LF & _
|
|---|
| 8 | $Results)
|
|---|
| 9 | EndFunc
|
|---|
| 10 |
|
|---|
| 11 | ;; UTF-8 log files with BOM
|
|---|
| 12 |
|
|---|
| 13 | Dim $aErrorLogFilesBOM
|
|---|
| 14 | $aErrorLogFilesBOM = _FileListToArray(@ScriptDir, "BOM_*.log", 1)
|
|---|
| 15 | If @Error=4 Then
|
|---|
| 16 | Exit
|
|---|
| 17 | Else
|
|---|
| 18 | _ArraySort($aErrorLogFilesBOM)
|
|---|
| 19 |
|
|---|
| 20 | $CaseNo = "Case 1"
|
|---|
| 21 | $CaseDescription = _
|
|---|
| 22 | "UTF-8 with BOM, encoding auto-detected:" & @LF & @LF & _
|
|---|
| 23 | " => FAILS: if 8-bit char contained, ignores all subsequent files!"
|
|---|
| 24 | $LoggedErrors = ""
|
|---|
| 25 | For $index = 1 to $aErrorLogFilesBOM[0]
|
|---|
| 26 | Local $filepath = @ScriptDir & "\" & $aErrorLogFilesBOM[$index]
|
|---|
| 27 | $ErrorLogFile = FileOpen($filepath, 0)
|
|---|
| 28 | $LoggedErrors = $LoggedErrors & FileRead($ErrorLogFile)
|
|---|
| 29 | FileClose($ErrorLogFile)
|
|---|
| 30 | Next
|
|---|
| 31 | ShowResults($CaseNo, $CaseDescription, $LoggedErrors)
|
|---|
| 32 |
|
|---|
| 33 | $CaseNo = "Case 2"
|
|---|
| 34 | $CaseDescription = _
|
|---|
| 35 | "UTF-8 with BOM, read as binary and decoded as UTF-8" & @LF & @LF & _
|
|---|
| 36 | " => OK after removal of BOM"
|
|---|
| 37 | $LoggedErrors = ""
|
|---|
| 38 | For $index = 1 to $aErrorLogFilesBOM[0]
|
|---|
| 39 | Local $filepath = @ScriptDir & "\" & $aErrorLogFilesBOM[$index]
|
|---|
| 40 | $ErrorLogFile = FileOpen($filepath, 16)
|
|---|
| 41 | ; BOM needs to be skipped
|
|---|
| 42 | $LoggedErrors = $LoggedErrors & _
|
|---|
| 43 | BinaryToString(BinaryMid(FileRead($ErrorLogFile), 4), 4)
|
|---|
| 44 | FileClose($ErrorLogFile)
|
|---|
| 45 | Next
|
|---|
| 46 | ShowResults($CaseNo, $CaseDescription, $LoggedErrors)
|
|---|
| 47 |
|
|---|
| 48 | EndIf
|
|---|
| 49 |
|
|---|
| 50 | ;; UTF-8 log files without BOM
|
|---|
| 51 |
|
|---|
| 52 | Dim $aErrorLogFilesNoBOM
|
|---|
| 53 | $aErrorLogFilesNoBOM = _FileListToArray(@ScriptDir, "NoBOM_*.log", 1)
|
|---|
| 54 | If @Error=4 Then
|
|---|
| 55 | Exit
|
|---|
| 56 | Else
|
|---|
| 57 | _ArraySort($aErrorLogFilesNoBOM)
|
|---|
| 58 |
|
|---|
| 59 | $CaseNo = "Case 3"
|
|---|
| 60 | $CaseDescription = _
|
|---|
| 61 | "UTF-8 without BOM, encoding auto-detected" & @LF & @LF & _
|
|---|
| 62 | " => FAILS: wrongly interprets characters as ANSI (of course)"
|
|---|
| 63 | $LoggedErrors = ""
|
|---|
| 64 | For $index = 1 to $aErrorLogFilesNoBOM[0]
|
|---|
| 65 | Local $filepath = @ScriptDir & "\" & $aErrorLogFilesNoBOM[$index]
|
|---|
| 66 | $ErrorLogFile = FileOpen($filepath, 0)
|
|---|
| 67 | $LoggedErrors = $LoggedErrors & FileRead($ErrorLogFile)
|
|---|
| 68 | FileClose($ErrorLogFile)
|
|---|
| 69 | Next
|
|---|
| 70 | ShowResults($CaseNo, $CaseDescription, $LoggedErrors)
|
|---|
| 71 |
|
|---|
| 72 | $CaseNo = "Case 4"
|
|---|
| 73 | $CaseDescription = _
|
|---|
| 74 | "UTF-8 without BOM, read as binary and decoded as UTF-8" & @LF & @LF & _
|
|---|
| 75 | " => OK in AutoIt V. 3.3 (but V. 3.2.12.1 interprets the characters as ANSI!)"
|
|---|
| 76 | $LoggedErrors = ""
|
|---|
| 77 | For $index = 1 to $aErrorLogFilesNoBOM[0]
|
|---|
| 78 | Local $filepath = @ScriptDir & "\" & $aErrorLogFilesNoBOM[$index]
|
|---|
| 79 | $ErrorLogFile = FileOpen($filepath, 16)
|
|---|
| 80 | $LoggedErrors = $LoggedErrors & _
|
|---|
| 81 | BinaryToString(FileRead($ErrorLogFile), 4)
|
|---|
| 82 | FileClose($ErrorLogFile)
|
|---|
| 83 | Next
|
|---|
| 84 | ShowResults($CaseNo, $CaseDescription, $LoggedErrors)
|
|---|
| 85 |
|
|---|
| 86 | EndIf
|
|---|