mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-06 03:33:00 +02:00
+ Implemented all functions
This commit is contained in:
parent
d03877c186
commit
ebead1b5ee
@ -85,8 +85,9 @@ const
|
||||
WordDelimiters: set of Char = [#0..#255] - ['a'..'z','A'..'Z','1'..'9','0'];
|
||||
|
||||
type
|
||||
TStringSeachOption = (soDown, soMatchCase, soWholeWord);
|
||||
TStringSearchOptions = set of TStringSeachOption;
|
||||
TStringSearchOption = (soDown, soMatchCase, soWholeWord);
|
||||
TStringSearchOptions = set of TStringSearchOption;
|
||||
TStringSeachOption = TStringSearchOption;
|
||||
|
||||
Function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions): PChar;
|
||||
Function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String): PChar; // ; Options: TStringSearchOptions = [soDown]
|
||||
@ -189,7 +190,10 @@ end;
|
||||
Function AnsiResemblesText(const AText, AOther: string): Boolean;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' AnsiResemblesText');
|
||||
if Assigned(AnsiResemblesProc) then
|
||||
Result:=AnsiResemblesProc(AText,AOther)
|
||||
else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
Function AnsiContainsText(const AText, ASubText: string): Boolean;
|
||||
@ -233,14 +237,8 @@ end;
|
||||
|
||||
Function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;
|
||||
|
||||
var i : longint;
|
||||
|
||||
begin
|
||||
result:=false;
|
||||
if high(AValues)=-1 Then exit;
|
||||
for i:=low(AValues) to High(Avalues) do
|
||||
if avalues[i]=atext Then
|
||||
result:=true;
|
||||
Result:=(AnsiIndexText(AText,AValues)<>-1)
|
||||
end;
|
||||
|
||||
|
||||
@ -251,10 +249,11 @@ var i : longint;
|
||||
|
||||
begin
|
||||
result:=-1;
|
||||
if high(AValues)=-1 Then exit;
|
||||
if high(AValues)=-1 Then
|
||||
Exit;
|
||||
for i:=low(AValues) to High(Avalues) do
|
||||
if avalues[i]=atext Then
|
||||
exit(i); // make sure it is the first val.
|
||||
if CompareText(avalues[i],atext)=0 Then
|
||||
exit(i); // make sure it is the first val.
|
||||
end;
|
||||
|
||||
|
||||
@ -295,47 +294,22 @@ end;
|
||||
|
||||
Function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean;
|
||||
|
||||
var
|
||||
counter: integer;
|
||||
begin
|
||||
counter := 0;
|
||||
{$ifdef INTERNLENGTH}
|
||||
while(counter < length(AValues)) do
|
||||
{$else}
|
||||
while(counter < high(AValues)+1) do
|
||||
{$endif}
|
||||
begin
|
||||
if(AText = AValues[counter]) then
|
||||
begin
|
||||
Result := true;
|
||||
exit;
|
||||
end;
|
||||
inc(counter);
|
||||
end;
|
||||
Result := false;
|
||||
Result:=AnsiIndexStr(AText,Avalues)<>-1;
|
||||
end;
|
||||
|
||||
|
||||
Function AnsiIndexStr(const AText: string; const AValues: array of string): Integer;
|
||||
|
||||
var
|
||||
counter: integer;
|
||||
var i : longint;
|
||||
|
||||
begin
|
||||
counter := 0;
|
||||
{$ifdef INTERNLENGTH}
|
||||
while(counter < length(AValues)) do
|
||||
{$else}
|
||||
while(counter < high(AValues)+1) do
|
||||
{$endif}
|
||||
begin
|
||||
if(AText = AValues[counter]) then
|
||||
begin
|
||||
Result := counter;
|
||||
exit;
|
||||
end;
|
||||
inc(counter);
|
||||
end;
|
||||
Result := -1;
|
||||
result:=-1;
|
||||
if high(AValues)=-1 Then
|
||||
Exit;
|
||||
for i:=low(AValues) to High(Avalues) do
|
||||
if (avalues[i]=AText) Then
|
||||
exit(i); // make sure it is the first val.
|
||||
end;
|
||||
|
||||
|
||||
@ -379,7 +353,7 @@ end;
|
||||
Function AnsiReverseString(const AText: AnsiString): AnsiString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' AnsiReverseString');
|
||||
Result:=ReverseString(AText);
|
||||
end;
|
||||
|
||||
|
||||
@ -411,7 +385,10 @@ end;
|
||||
Function IfThen(AValue: Boolean; const ATrue: string; AFalse: string): string;
|
||||
|
||||
begin
|
||||
if avalue then result:=atrue else result:=afalse;
|
||||
if avalue then
|
||||
result:=atrue
|
||||
else
|
||||
result:=afalse;
|
||||
end;
|
||||
|
||||
|
||||
@ -419,7 +396,10 @@ end;
|
||||
Function IfThen(AValue: Boolean; const ATrue: string): string; // ; AFalse: string = ''
|
||||
|
||||
begin
|
||||
if avalue then result:=atrue else result:='';
|
||||
if avalue then
|
||||
result:=atrue
|
||||
else
|
||||
result:='';
|
||||
end;
|
||||
|
||||
|
||||
@ -458,7 +438,7 @@ end;
|
||||
Function LeftBStr(const AText: AnsiString; const AByteCount: Integer): AnsiString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' LeftBStr');
|
||||
Result:=LeftStr(AText,AByteCount);
|
||||
end;
|
||||
|
||||
|
||||
@ -466,7 +446,7 @@ end;
|
||||
Function RightBStr(const AText: AnsiString; const AByteCount: Integer): AnsiString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' RightBStr');
|
||||
Result:=RightStr(Atext,AByteCount);
|
||||
end;
|
||||
|
||||
|
||||
@ -474,7 +454,7 @@ end;
|
||||
Function MidBStr(const AText: AnsiString; const AByteStart, AByteCount: Integer): AnsiString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' MidBStr');
|
||||
Result:=MidStr(AText,AByteStart,AByteCount);
|
||||
end;
|
||||
|
||||
|
||||
@ -498,22 +478,28 @@ end;
|
||||
Function AnsiMidStr(const AText: AnsiString; const AStart, ACount: Integer): AnsiString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' AnsiMidStr');
|
||||
Result:=Copy(AText,AStart,ACount);
|
||||
end;
|
||||
|
||||
{$ifndef ver1_0}
|
||||
Function LeftStr(const AText: WideString; const ACount: Integer): WideString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' LeftStr');
|
||||
Result:=Copy(AText,1,ACount);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function RightStr(const AText: WideString; const ACount: Integer): WideString;
|
||||
|
||||
var
|
||||
j,l:integer;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' RightStr');
|
||||
l:=length(atext);
|
||||
j:=ACount;
|
||||
if j>l then j:=l;
|
||||
Result:=Copy(AText,l-j+1,j);
|
||||
end;
|
||||
|
||||
|
||||
@ -521,7 +507,7 @@ end;
|
||||
Function MidStr(const AText: WideString; const AStart, ACount: Integer): WideString;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' MidStr');
|
||||
Result:=Copy(AText,AStart,ACount);
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
@ -534,8 +520,109 @@ end;
|
||||
|
||||
Function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions): PChar;
|
||||
|
||||
var
|
||||
Len,I,SLen: Integer;
|
||||
C: Char;
|
||||
Found : Boolean;
|
||||
Direction: Shortint;
|
||||
CharMap: array[Char] of Char;
|
||||
|
||||
Function GotoNextWord(var P : PChar): Boolean;
|
||||
|
||||
begin
|
||||
if (Direction=1) then
|
||||
begin
|
||||
// Skip characters
|
||||
While (Len>0) and not (P^ in WordDelimiters) do
|
||||
begin
|
||||
Inc(P);
|
||||
Dec(Len);
|
||||
end;
|
||||
// skip delimiters
|
||||
While (Len>0) and (P^ in WordDelimiters) do
|
||||
begin
|
||||
Inc(P);
|
||||
Dec(Len);
|
||||
end;
|
||||
Result:=Len>0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Skip Delimiters
|
||||
While (Len>0) and (P^ in WordDelimiters) do
|
||||
begin
|
||||
Dec(P);
|
||||
Dec(Len);
|
||||
end;
|
||||
// skip characters
|
||||
While (Len>0) and not (P^ in WordDelimiters) do
|
||||
begin
|
||||
Dec(P);
|
||||
Dec(Len);
|
||||
end;
|
||||
Result:=Len>0;
|
||||
// We're on the first delimiter. Pos back on char.
|
||||
Inc(P);
|
||||
Inc(Len);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SearchBuf');
|
||||
Result:=nil;
|
||||
Slen:=Length(SearchString);
|
||||
if (BufLen<=0) or (Slen=0) then
|
||||
Exit;
|
||||
if soDown in Options then
|
||||
begin
|
||||
Direction:=1;
|
||||
Inc(SelStart,SelLength);
|
||||
Len:=BufLen-SelStart-SLen+1;
|
||||
if (Len<=0) then
|
||||
Exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Direction:=-1;
|
||||
Dec(SelStart,Length(SearchString));
|
||||
Len:=SelStart+1;
|
||||
end;
|
||||
if (SelStart<0) or (SelStart>BufLen) then
|
||||
Exit;
|
||||
Result:=@Buf[SelStart];
|
||||
for C:=Low(Char) to High(Char) do
|
||||
if (soMatchCase in Options) then
|
||||
CharMap[C]:=C
|
||||
else
|
||||
CharMap[C]:=Upcase(C);
|
||||
if Not (soMatchCase in Options) then
|
||||
SearchString:=UpCase(SearchString);
|
||||
Found:=False;
|
||||
while (Result<>Nil) and (Not Found) do
|
||||
begin
|
||||
if ((soWholeWord in Options) and
|
||||
(Result<>@Buf[SelStart]) and
|
||||
not GotoNextWord(Result)) then
|
||||
Result:=Nil
|
||||
else
|
||||
begin
|
||||
// try to match whole searchstring
|
||||
I:=0;
|
||||
while (I<Slen) and (CharMap[Result[I]]=SearchString[I+1]) do
|
||||
Inc(I);
|
||||
// Whole searchstring matched ?
|
||||
if (I=SLen) then
|
||||
Found:=(Len=0) or
|
||||
(not (soWholeWord in Options)) or
|
||||
(Result[SLen] in WordDelimiters);
|
||||
if not Found then
|
||||
begin
|
||||
Inc(Result,Direction);
|
||||
Dec(Len);
|
||||
If (Len=0) then
|
||||
Result:=Nil;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -543,7 +630,7 @@ end;
|
||||
Function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String): PChar; // ; Options: TStringSearchOptions = [soDown]
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SearchBuf');
|
||||
Result:=SearchBuf(Buf,BufLen,SelStart,SelLength,SearchString,[soDown]);
|
||||
end;
|
||||
|
||||
|
||||
@ -642,12 +729,30 @@ begin
|
||||
Result:=Soundex(AText,4);
|
||||
end;
|
||||
|
||||
|
||||
Const
|
||||
Ord0 = Ord('0');
|
||||
OrdA = Ord('A');
|
||||
|
||||
Function SoundexInt(const AText: string; ALength: TSoundexIntLength): Integer;
|
||||
|
||||
var
|
||||
SE: string;
|
||||
I: Integer;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexInt');
|
||||
Result:=-1;
|
||||
SE:=Soundex(AText,ALength);
|
||||
If Length(SE)>0 then
|
||||
begin
|
||||
Result:=Ord(SE[1])-OrdA;
|
||||
if ALength > 1 then
|
||||
begin
|
||||
Result:=Result*26+(Ord(SE[2])-Ord0);
|
||||
for I:=3 to ALength do
|
||||
Result:=(Ord(SE[I])-Ord0)+Result*7;
|
||||
end;
|
||||
Result:=ALength+Result*9;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -655,15 +760,29 @@ end;
|
||||
Function SoundexInt(const AText: string): Integer; //; ALength: TSoundexIntLength = 4
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexInt');
|
||||
Result:=SoundexInt(AText,4);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function DecodeSoundexInt(AValue: Integer): string;
|
||||
|
||||
var
|
||||
I, Len: Integer;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' DecodeSoundexInt');
|
||||
Result := '';
|
||||
Len := AValue mod 9;
|
||||
AValue := AValue div 9;
|
||||
for I:=Len downto 3 do
|
||||
begin
|
||||
Result:=Chr(Ord0+(AValue mod 7))+Result;
|
||||
AValue:=AValue div 7;
|
||||
end;
|
||||
if Len>2 then
|
||||
Result:=IntToStr(AValue mod 26)+Result;
|
||||
AValue:=AValue div 26;
|
||||
Result:=Chr(OrdA+AValue)+Result;
|
||||
end;
|
||||
|
||||
|
||||
@ -675,8 +794,7 @@ Var
|
||||
|
||||
begin
|
||||
S:=SoundEx(Atext,4);
|
||||
Writeln('Soundex result : "',S,'"');
|
||||
Result:=Ord(S[1])-Ord('A');
|
||||
Result:=Ord(S[1])-OrdA;
|
||||
Result:=Result*26+StrToInt(S[2]);
|
||||
Result:=Result*7+StrToInt(S[3]);
|
||||
Result:=Result*7+StrToInt(S[4]);
|
||||
@ -687,7 +805,13 @@ end;
|
||||
Function DecodeSoundexWord(AValue: Word): string;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' DecodeSoundexWord');
|
||||
Result := Chr(Ord0+ (AValue mod 7)) + Result;
|
||||
AValue := AValue div 7;
|
||||
Result := Chr(Ord0+ (AValue mod 7)) + Result;
|
||||
AValue := AValue div 7;
|
||||
Result := IntToStr(AValue mod 26) + Result;
|
||||
AValue := AValue div 26;
|
||||
Result := Chr(OrdA+AValue) + Result;
|
||||
end;
|
||||
|
||||
|
||||
@ -695,7 +819,7 @@ end;
|
||||
Function SoundexSimilar(const AText, AOther: string; ALength: TSoundexLength): Boolean;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexSimilar');
|
||||
Result:=Soundex(AText,ALength)=Soundex(AOther,ALength);
|
||||
end;
|
||||
|
||||
|
||||
@ -703,7 +827,7 @@ end;
|
||||
Function SoundexSimilar(const AText, AOther: string): Boolean; //; ALength: TSoundexLength = 4
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexSimilar');
|
||||
Result:=SoundexSimilar(AText,AOther,4);
|
||||
end;
|
||||
|
||||
|
||||
@ -711,7 +835,7 @@ end;
|
||||
Function SoundexCompare(const AText, AOther: string; ALength: TSoundexLength): Integer;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexCompare');
|
||||
Result:=AnsiCompareStr(Soundex(AText,ALength),Soundex(AOther,ALength));
|
||||
end;
|
||||
|
||||
|
||||
@ -719,7 +843,7 @@ end;
|
||||
Function SoundexCompare(const AText, AOther: string): Integer; //; ALength: TSoundexLength = 4
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexCompare');
|
||||
Result:=SoundexCompare(AText,AOther,4);
|
||||
end;
|
||||
|
||||
|
||||
@ -727,7 +851,7 @@ end;
|
||||
Function SoundexProc(const AText, AOther: string): Boolean;
|
||||
|
||||
begin
|
||||
NotYetImplemented(' SoundexProc');
|
||||
Result:=SoundexSimilar(AText,AOther);
|
||||
end;
|
||||
|
||||
{ ---------------------------------------------------------------------
|
||||
@ -1405,7 +1529,10 @@ end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.8 2004-07-13 18:42:39 michael
|
||||
Revision 1.9 2004-07-21 20:37:03 michael
|
||||
+ Implemented all functions
|
||||
|
||||
Revision 1.8 2004/07/13 18:42:39 michael
|
||||
+ Added some RxStrUtils functions for Rx compatibility
|
||||
|
||||
Revision 1.7 2004/07/01 15:42:18 peter
|
||||
|
Loading…
Reference in New Issue
Block a user