| 看板: BudaTech ◎ 佛典電子化討論 板主: HeavenChow |
| 閱讀文章: 第 1098/2032 篇 | 上篇 | 下篇 | 回覆 | 轉寄 | 轉貼 | m H d | 返回 |
發信人: huiray@Lion (ray), 信區: BudaTech
標 題: 中文識別函式
發信站: 獅子吼站 (Sun Dec 28 11:43:08 1997)
轉信站: Lion
關於中文識別函式,已實作出來,待進一步包裝成物件後提
供給大家使用,Heaven (不知有沒有記錯?)說半天以內可
以做出來,事實上沒錯,不難。這裡提供原始碼讓大家參考
用法是呼叫 Tbig5.isdefine(字串第n個byte,字串)
將回應是否是中文字。
如果要辨識造字或GB, JIS 等碼,只要修改isleading 和
isending 兩個函式就可以了。
----------
interface
type
TBig5 = class
private
class function isleading(c:char):boolean;
class function isending(c:char):boolean;
public
class function isdefine(pos:cardinal;s:pchar):boolean;
end;
implementation
class function tbig5.isleading(c:char):boolean;
begin
result:=(c>=#129) and ( c<=#254 );
end;
class function tbig5.isending(c:char):boolean;
begin
result:=((c>=#64) and (c<=#126)) or ((c>=#161) and (c<=#254));
end;
class function Tbig5.isdefine(pos:cardinal;s:pchar):boolean;
var
len,i:cardinal;
begin
result:=false;
len:=strlen(s);
if pos>len-2 then exit;
i:=0;
while i<pos+1 do begin
if isleading((s+i)^) and isending((s+i+1)^) then begin
if i=pos then begin result:=true;exit;end;
inc(i,2);
end
else inc(i);
end;
end;
OPEN 98 研發部
--
Ξ Origin: 獅子吼站 <cbs.ntu.edu.tw> [FROM: 210.61.183.51]
|
| 閱讀文章: 第 1098/2032 篇 | 上篇 | 下篇 | 回覆 | 轉寄 | 轉貼 | m H d | 返回 |
卍 台大獅子吼佛學專站 http://buddhaspace.org |