注册会员 登录
Project1 返回首页

zh99998的个人空间 https://rpg.blue/?42757 [收藏] [复制] [分享] [RSS]

日志

Iconv

已有 431 次阅读2010-8-8 16:39

#RM可用的Iconv转码,因为经常用到所以来这做个备份了
module Iconv
  CP_ACP = 0
  CP_UTF8 = 65001
  def self.utf8_to_gb2312(text)
    m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
    w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
    n = 0
    i = m2w.call(CP_UTF8, 0 , text, -1,nil,0)
    buffer = "\0" * (i*2)
    m2w.call(CP_UTF8, 0 , text, -1, buffer, i)
    i = w2m.call(CP_ACP, 0, buffer, -1, nil, 0, nil, nil)
    result = "\0" * i
    w2m.call(CP_ACP, 0, buffer, -1, result, i, nil, nil)
    result.chop!
    return result
  end
  def self.gb2312_to_utf8(text)
    m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
    w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
    n = text.size
    i = m2w.call(CP_ACP, 0, text, n+1, nil, 0)
    buffer = "\0" * (i*2)
    m2w.call(CP_ACP, 0, text, n+1, buffer, i)
    i = w2m.call(CP_UTF8, 0, buffer, -1, nil, 0, nil, nil)
    result = "\0" * i
    w2m.call(CP_UTF8, 0, buffer, -1, result, i, nil, nil)
    result.chop!
    return result
  end
end


鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-26 13:19

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部