求GB和BIG5的编码规则。(我要写个内码转换)(50分)

  • 主题发起人 主题发起人 sim_might
  • 开始时间 开始时间
S

sim_might

Unregistered / Unconfirmed
GUEST, unregistred user!
求GB和BIG5的编码规则。(我要写个内码转换)
 
用内码转换工具生成一个GB-BIG5的码表,通过查表变换
 
抄来的,不知道好不好使.
昨天摔了一跤 <windoze@yeah.net>
在Win2K下自己写很容易,下面给你几个函数,函数名里有String的是AnsiString版,
没有的是PChar版

uses
SysUtils, Windows;

function StrConv(pszSrc : PChar; cpSrc : UINT; pszDest : PChar; cbDest :
Longint; cpDest : UINT) : Longint;
var
buf : PWideChar;
cwLen : LongInt;
begin
cwLen := MultiByteToWideChar(cpSrc,
0,
pszSrc,
-1,
nil,
0);
GetMem(buf, (cwLen+1) * SizeOf(WideChar));
ZeroMemory(buf, (cwLen+1) * SizeOf(WideChar));
MultiByteToWideChar(cpSrc,
0,
pszSrc,
StrLen(pszSrc),
buf,
cwLen+1);
Result := WideCharToMultiByte(cpDest,
0,
buf,
-1,
pszDest,
cbDest,
nil,
nil);
FreeMem(buf);
end;

function StringConv(const Src : string; cpSrc, cpDest : UINT) : string;
var
buf : PChar;
len : Longint;
begin
len := StrConv(PChar(Src), cpSrc, nil, 0, cpDest);
GetMem(buf, len);
ZeroMemory(buf, len);
StrConv(PChar(Src), cpSrc, buf, len, cpDest);
Result := string(buf);
FreeMem(buf);
end;

function CHTStringToCHSString(Src : string) : string;
var
buf : PChar;
len : Integer;
begin
len := LCMapString($804, // LCID_CHINESE_SIMPLIFIED
LCMAP_SIMPLIFIED_CHINESE,
PChar(Src),
-1,
nil,
0);
GetMem(buf, len);
ZeroMemory(buf, len);
LCMapString($804, // LCID_CHINESE_SIMPLIFIED
LCMAP_SIMPLIFIED_CHINESE,
PChar(Src),
-1,
buf,
len);
Result := string(buf);
FreeMem(buf);
end;

function CHSStringToCHTString(Src : string) : string;
var
buf : PChar;
len : Integer;
begin
len := LCMapString($404, // LCID_CHINESE_SIMPLIFIED
LCMAP_TRADITIONAL_CHINESE,
PChar(Src),
-1,
nil,
0);
GetMem(buf, len);
ZeroMemory(buf, len);
LCMapString($404, // LCID_CHINESE_SIMPLIFIED
LCMAP_TRADITIONAL_CHINESE,
PChar(Src),
-1,
buf,
len);
Result := string(buf);
FreeMem(buf);
end;

function CHTToCHS(pszSrc, pszDest : PChar; cbDest : Longint) : Longint;
begin
Result := LCMapString($804, // LCID_CHINESE_SIMPLIFIED
LCMAP_SIMPLIFIED_CHINESE,
pszSrc,
-1,
pszDest,
cbDest);
end;

function CHSToCHT(pszSrc, pszDest : PChar; cbDest : Longint) : Longint;
begin
Result := LCMapString($404, // LCID_CHINESE_SIMPLIFIED
LCMAP_TRADITIONAL_CHINESE,
pszSrc,
-1,
pszDest,
cbDest);
end;

function Big5StringToGBString(Src : string) : string;
begin
Result := CHTStringToCHSString(StringConv(Src, 950, 936));
end;

function Big5ToGB(pszSrc, pszDest : PChar; cbDest : Longint) : Longint;
var
buf : PChar;
len : Integer;
begin
len := StrLen(pszSrc)+1;
GetMem(buf, len*2);
ZeroMemory(buf, len*2);
StrConv(pszSrc, 950, buf, 936, len*2);
Result := CHTToCHS(buf, pszDest, cbDest);
FreeMem(buf);
end;

function GBStringToBig5String(Src : string) : string;
begin
Result := CHSStringToCHTString(StringConv(Src, 936, 950));
end;

function GBToBig5(pszSrc, pszDest : PChar; cbDest : Longint) : Longint;
var
buf : PChar;
len : Integer;
begin
len := StrLen(pszSrc)+1;
GetMem(buf, len*2);
ZeroMemory(buf, len*2);
StrConv(pszSrc, 936, buf, 950, len*2);
Result := CHSToCHT(buf, pszDest, cbDest);
FreeMem(buf);
end;
 
给我你的EMail,我发给你一个Unit
 
sim_might@sohu.com
 
也发给我一芬好吗?shaoss@163.net
 
也发给我一芬好吗?e1208640@963.net
 
有现在的例子呀,我找一下看看
 
给我一份好吗?shaoss@163.net
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2509663
帮个忙好么
 
后退
顶部