Module: EasyConv
- Defined in:
- lib/easy_conv.rb,
lib/easy_conv/version.rb
Constant Summary collapse
- CP_ACP =
API梡掕悢掕媊
0
- CP_UTF8 =
65001
- CP_UTF7 =
65000
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.s2u(text) ⇒ Object
————————————————————————– 仠 S-JIS -> UTF-8 ————————————————————————–.
-
.u2s(text) ⇒ Object
————————————————————————– 仠 UTF-8 -> S-JIS ————————————————————————–.
Class Method Details
.s2u(text) ⇒ Object
仠 S-JIS -> UTF-8
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/easy_conv.rb', line 12 def s2u(text) # API掕媊 m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i') w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i') # S-JIS -> Unicode len = m2w.call(CP_ACP, 0, text, -1, nil, 0); buf = "\0" * (len*2) m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2); # Unicode -> UTF-8 len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil); #---<shana marked>---<len - 1>--- ret = "\0" * (len - 1) #-------------------------------- w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil); return ret end |
.u2s(text) ⇒ Object
仠 UTF-8 -> S-JIS
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/easy_conv.rb', line 37 def u2s(text) # API掕媊 m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i') w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i') # UTF-8 -> Unicode len = m2w.call(CP_UTF8, 0, text, -1, nil, 0); buf = "\0" * (len*2) m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2); # Unicode -> S-JIS len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil); #---<shana marked>---<len - 1>--- ret = "\0" * (len - 1) #-------------------------------- w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil); return ret end |