Thinkai's Blog

Autohotkey|Python|php|aardio|VOIP|IT 爱好者

转换效率 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)
}



来了就留个评论吧! 1个评论




友情链接:Autohotkey中文帮助Autohotkey官网Autohotkey中文网联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

60 queries in 1.878 seconds |