class String# 转码--
MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
CP_JIS = 932
CP_UTF8 = 65001
def j2u
w2m(CP_UTF8, m2w(CP_JIS, self)).chop
end
# -
def m2w(cpi, buf)
nLen = MultiByteToWideChar.call(cpi, 0, buf, -1, nil, 0) * 2
wBuf = "\0" * nLen
MultiByteToWideChar.call(cpi, 0, buf, -1, wBuf, nLen)
return wBuf
end
def w2m(cpi, buf)
nLen = WideCharToMultiByte.call(cpi, 0, buf, -1, nil, 0, nil, nil) * 2
wBuf = "\0" * nLen
WideCharToMultiByte.call(cpi, 0, buf, -1, wBuf, nLen, nil, nil)
return wBuf
end
end
class String# 转码--
MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
CP_JIS = 932
CP_UTF8 = 65001
def j2u
w2m(CP_UTF8, m2w(CP_JIS, self)).chop
end
# -
def m2w(cpi, buf)
nLen = MultiByteToWideChar.call(cpi, 0, buf, -1, nil, 0) * 2
wBuf = "\0" * nLen
MultiByteToWideChar.call(cpi, 0, buf, -1, wBuf, nLen)
return wBuf
end
def w2m(cpi, buf)
nLen = WideCharToMultiByte.call(cpi, 0, buf, -1, nil, 0, nil, nil) * 2
wBuf = "\0" * nLen
WideCharToMultiByte.call(cpi, 0, buf, -1, wBuf, nLen, nil, nil)
return wBuf
end
end