Автор: ViSiToR
Дата сообщения: 18.10.2007 22:25
Kauffman
Я не знаком с кодировкой Unix/Mac, но можно попробовать функцию для конвертирования UTF в Ansi или в юникод, или строку в UTF-8 а потом в ansi...
Код: Func _Utf8ToUnicode($Utf8String)
Local $BufferSize = StringLen($Utf8String) * 2
Local $Buffer = DllStructCreate("byte[" & $BufferSize & "]")
Local $Return = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
"int", 65001, _
"int", 0, _
"str", $Utf8String, _
"int", StringLen($Utf8String), _
"ptr", DllStructGetPtr($Buffer), _
"int", $BufferSize)
Local $UnicodeBinary = DllStructGetData($Buffer, 1)
$UnicodeHex1 = StringReplace($UnicodeBinary, "0x", "")
$StrLen = StringLen($UnicodeHex1)
Local $UnicodeString
For $i = 1 To $StrLen Step 4
$UnicodeHex2 = StringMid($UnicodeHex1, $i, 4)
$UnicodeHex3 = StringMid($UnicodeHex2,3,2) & StringMid($UnicodeHex2,1,2)
$UnicodeString &= ChrW(Dec($UnicodeHex3))
Next
$Buffer = 0
Return $UnicodeString
EndFunc
Func _Utf8ToAnsi($utf8string)
Local $len = StringLen($utf8string)
Local $buf = DllStructCreate("byte[" & $len*2 & "];byte[2]")
Local $ret = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
"int", 65001, "int", 0, _
"str", $utf8string, "int", -1, _
"ptr", DllStructGetPtr($buf), "int", $len*2+2)
Local $out = DllStructCreate("char[" & $len & "];char")
$ret = DllCall("kernel32.dll", "int", "WideCharToMultiByte", _
"int", 0, "int", 0, _
"ptr", DllStructGetPtr($buf), "int", -1, _
"ptr", DllStructGetPtr($out), "int", $len+1, _
"int", 0, "int", 0)
Return DllStructGetData($out,1)
EndFunc
Func StringToUTF($String)
Dim $sResult = ""
$VarUTFArr = StringSplit($String, "")
For $i = 1 To $VarUTFArr[0]
$code = Asc($VarUTFArr[$i])
Select
Case $code >= 192 And $code <= 239
$VarUTFArr[$i] = Chr(208) & Chr($code - 48)
Case $code >= 240 And $code <= 255
$VarUTFArr[$i] = Chr(209) & Chr($code - 112)
Case $code = 168
$VarUTFArr[$i] = Chr(208) & Chr(129)
Case $code = 184
$VarUTFArr[$i] = Chr(209) & Chr(145)
Case Else
$VarUTFArr[$i] = Chr($code)
EndSelect
$sResult = $sResult & $VarUTFArr[$i]
Next
Return $sResult
EndFunc