#include-once #include #include #include "..\include\dump.au3" ; Unicode Normalization Forms Global Enum $UNF_NormC = 1, $UNF_NormD, $UNF_NormKC = 5, $UNF_NormKD Func CW($s = "") If @Compiled Then _CUI_ConsoleWrite($s) Else _ConsoleWrite($s) EndIf EndFunc ;==>CW Func _CUI_ConsoleWrite(ByRef $s) Local Static $hDll = DllOpen("kernel32.dll") Local Static $hCon = __CUI_ConsoleInit($hDll) DllCall($hDll, "bool", "WriteConsoleW", "handle", $hCon, "wstr", $s & @LF, "dword", StringLen($s) + 1, "dword*", 0, "ptr", 0) Return EndFunc ;==>_CUI_ConsoleWrite ; internal use only Func __CUI_ConsoleInit(ByRef $hDll) DllCall($hDll, "bool", "AllocConsole") ;~ The following 2 lines don't work for compiled scripts due to a MS bug ;~ see last post in thread https://developercommunity.visualstudio.com/t/setconsoleoutputcpcp-utf8-results-in-code-page-850/413190 ;~ where MS support acknowledges it's a (still unfixed) bug in Windows itself ;~ So you can only display current locale codepage using current console font in a console when your script is compiled ;~ When running your script from SciTE, the UTF8 setting of SciTE overrides this bug and Unicode can be displayed ;~ DllCall("Kernel32.dll", "bool", "SetConsoleCP", "uint", 65001) ;~ DllCall("Kernel32.dll", "bool", "SetConsoleOutputCP", "uint", 65001) Return DllCall($hDll, "handle", "GetStdHandle", "int", -11)[0] EndFunc ;==>__CUI_ConsoleInit ; Unicode-aware ConsoleWrite Func _ConsoleWrite(ByRef $s) ConsoleWrite(BinaryToString(StringToBinary($s & @LF, 4), 1)) EndFunc ;==>_ConsoleWrite Func _UNF_Change(ByRef $sIn, $iForm) If $iForm = $UNF_NormC Or $iForm = $UNF_NormD Or $iForm = $UNF_NormKC Or $iForm = $UNF_NormKD Then Local $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", 0, "int", 0) Local $tOut = DllStructCreate("wchar[" & 2 * ($aRet[0] + 20) & "]") $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", DllStructGetPtr($tOut, 1), "int", 2 * ($aRet[0] + 20)) $sIn = DllStructGetData($tOut, 1) Else SetError(1, 0) EndIf EndFunc ;==>_UNF_Change Func _Unaccent(ByRef $s, $iMode = 0) Local Static $aPat = [ _ "(*UCP)[\x{300}-\x{36F}`'¨^¸¯]", _ ; $iMode = 0 : remove combining accents only "(*UCP)\p{Mn}|\p{Lm}|\p{Sk}" _ ; $iMode = 1 : " " " and modifying letters ] $s = StringRegExpReplace(_UNF_Change($s, $UNF_NormD), $aPat[Mod($iMode, 2)], "") EndFunc ;==>_Unaccent