Function isSogl(c:Char):Boolean; begin Result:=c in SoglChar; end;
Function isGlas(c:Char):Boolean; begin Result:=c in GlasChar; end;
Function isSpecSign(c:Char):Boolean; begin Result:=c in SpecSign; end;
Function GetSymbType(c:Char):TSymbol; begin if isSogl(c) thenbegin Result:=st_Sogl;exit;end;
if isGlas(c) thenbegin Result:=st_Glas;exit;end; if isSpecSign(c) thenbegin Result:=st_Spec;exit;end; Result:=st_NoDefined; end;
Function isSlogMore(c:pSymbAr;start,len:Integer):Boolean; var i:Integer; glFlag:Boolean; begin glFlag:=false; for i:=Start to Len-1do begin if c^[i]=st_NoDefined thenbegin Result:=false;exit;end; if (c^[i]=st_Glas)and((c^[i+1]<>st_Nodefined)or(i<>Start)) then begin Result:=True; exit; end; end;
Result:=false; end;
{ ¨ð¸¸?ðòû ûúð ÿõ¨õýþ¸þò } Function SetHyph(pc:PChar;MaxSize:Integer):PChar; var HypBuff : Pointer; h : PSymbAr; i : Integer; len : Integer; Cur : Integer; { } cw : Integer; { =þüõ¨ ñ?úòv ò ¸ûþòõ } Lock: Integer; { ¸?õ??øú ñûþúø¨þòþú } begin Cur:=0; len := StrLen(pc); if (MaxSize=0)OR(Len=0) then begin Result:=nil; Exit; end;
GetMem(HypBuff,MaxSize); GetMem(h,Len+1);
for i:=0to len-1do h^[i]:=GetSymbType(pc[i]);
cw:=0; Lock:=0; for i:=0to Len-1do begin PChar(HypBuff)[cur]:=PChar(pc)[i];Inc(Cur);
if i>=Len-2then Continue; if h^[i]=st_NoDefined thenbegin cw:=0;Continue;endelse Inc(cw); if Lock<>0thenbegin Dec(Lock);Continue;end; if cw<=1then Continue; ifnot(isSlogMore(h,i+1,len)) then Continue;
if (h^[i]=st_Sogl)and(h^[i-1]=st_Glas)and(h^[i+1]=st_Sogl)and(h^[i+2]<>st_Spec)
Function Red_GlasMore(p:Pchar;pos:Integer):Boolean; begin While p[pos]<>#0do begin if p[pos] in Spaces thenbegin Result:=False; Exit; end; if isGlas(p[pos]) thenbegin Result:=True; Exit; end;
Inc(pos); end; Result:=False; end;
Function Red_SlogMore(p:Pchar;pos:Integer):Boolean; Var BeSogl,BeGlas:Boolean; begin BeSogl:=False; BeGlas:=False; While p[pos]<>#0do begin if p[pos] in Spaces then Break; ifNot BeGlas then BeGlas:=isGlas(p[pos]); ifNot BeSogl then BeSogl:=isSogl(p[pos]); Inc(pos); end; Result:=BeGlas and BeSogl; end;
Function MayBeHyph(p:PChar;pos:Integer):Boolean; var i:Integer; len:Integer; begin i:=pos; Len:=StrLen(p); Result:= (Len>3) AND (i>2)
AND (i<Len-2) AND (not (p[i] in Spaces)) AND (not (p[i+1] in Spaces)) AND (not (p[i-1] in Spaces)) AND ( (isSogl(p[i])and isGlas(p[i-1])and isSogl(p[i+1])and Red_SlogMore(p,i+1)) OR ((isGlas(p[i]))and(isSogl(p[i-1]))and(isSogl(p[i+1]))and(isGlas(p[i+2]))) OR ((isGlas(p[i]))and(isSogl(p[i-1]))and(isGlas(p[i+1])) and Red_SlogMore(p,i+1) ) OR ((isSpecSign(p[i]))) );
end;
Function SetHyphString(s : String):String;
Var Res:PChar; begin Res:=SetHyph(PChar(S),Length(S)*2) Result:=Res; FreeMem(Res,Length(S)*2); end;
end.
Alex Gorbunov acdc@media-press.donetsk.ua www.media-press.donetsk.ua (2:465/85.4) . Âçÿòî èç FAQ: Delphi and Windows API Tips'n'Tricks olmal@mail.ru http://www.chat.ru/~olmal