本文来自于Thinkai’s Blog,thinkai也是我在ahk上面的引路人,对thinkai感兴趣的朋友请关注他的博客。
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。转换效率 decodeu3>decodeu4>decodeu2>decodeu
thinkai的博客简洁、有趣,即便是转载过来我也尽量保持作者原有的风格,主要是方便大家查阅。转换效率 decodeu3>decodeu4>decodeu2>decodeu
使用环境Autohotkey ansi32,输出gb2312字符串
decodeu2(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := RegExReplace(out,"\u" m1 m2, tmpstr)
return out
}
decodeu3(out){
foundpos := 1
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})",m))
Unicode2Ansi(Chr("0x" m2) Chr("0x" m1),tmpstr,0),out := strReplace(out,"u" m1 m2, tmpstr)
return out
}
decodeu4(out){
foundpos := 1, VarSetCapacity(char,3,0)
while(foundpos := RegExMatch(out,"\u([A-Fa-f0-9]{4})",m))
NumPut("0x" m1,&char,,"UShort"),out := strReplace(out,"u" m1 m2, StrGet(&char,,"CP1200"))
return out
}
decodeu(ustr){
Loop
{
if !ustr
break
if RegExMatch(ustr,"^s*\u([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})(.*)",m)
{
word_u := Chr("0x" m2) Chr("0x" m1), ustr := m3, word_a := ""
Unicode2Ansi(word_u,word_a,0)
out .= word_a
}
else if RegExMatch(ustr, "^([a-zA-Z0-9.?-!s:""]*)(.*)",n)
{
ustr := n2
out .= n1
}
}
return out
}
Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
nSize := DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "Uint", 0
, "int", 0
, "Uint", 0
, "Uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte"
, "Uint", CP
, "Uint", 0
, "Uint", &wString
, "int", -1
, "str", sString
, "int", nSize
, "Uint", 0
, "Uint", 0)
}