* Added Offset argument to Pos (exists in wide and ansi/short, forgotten for unicode)

git-svn-id: trunk@33056 -
This commit is contained in:
michael 2016-02-06 12:16:00 +00:00
parent cf530f117e
commit 6d051892e5
2 changed files with 21 additions and 21 deletions

View File

@ -16,12 +16,12 @@
Procedure UniqueString (Var S : UnicodeString);external name 'FPC_UNICODESTR_UNIQUE'; Procedure UniqueString (Var S : UnicodeString);external name 'FPC_UNICODESTR_UNIQUE';
Function Pos (Const Substr : UnicodeString; Const Source : UnicodeString) : SizeInt; Function Pos (Const Substr : UnicodeString; Const Source : UnicodeString; Offset: Sizeint = 1) : SizeInt;
Function Pos (c : Char; Const s : UnicodeString) : SizeInt; Function Pos (c : Char; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
Function Pos (c : UnicodeChar; Const s : UnicodeString) : SizeInt; Function Pos (c : UnicodeChar; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
Function Pos (const c : RawByteString; Const s : UnicodeString) : SizeInt; Function Pos (const c : RawByteString; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
Function Pos (const c : UnicodeString; Const s : RawByteString) : SizeInt; Function Pos (const c : UnicodeString; Const s : RawByteString; Offset: Sizeint = 1) : SizeInt;
Function Pos (const c : ShortString; Const s : UnicodeString) : SizeInt; Function Pos (const c : ShortString; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
Function UpCase(const s : UnicodeString) : UnicodeString; Function UpCase(const s : UnicodeString) : UnicodeString;
Function UpCase(c:UnicodeChar):UnicodeChar; Function UpCase(c:UnicodeChar):UnicodeChar;

View File

@ -1160,7 +1160,7 @@ end;
{$ifndef FPC_HAS_POS_UNICODESTR_UNICODESTR} {$ifndef FPC_HAS_POS_UNICODESTR_UNICODESTR}
{$define FPC_HAS_POS_UNICODESTR_UNICODESTR} {$define FPC_HAS_POS_UNICODESTR_UNICODESTR}
Function Pos (Const Substr : UnicodeString; Const Source : UnicodeString) : SizeInt; Function Pos (Const Substr : UnicodeString; Const Source : UnicodeString; Offset: Sizeint = 1) : SizeInt;
var var
i,MaxLen : SizeInt; i,MaxLen : SizeInt;
pc : punicodechar; pc : punicodechar;
@ -1168,9 +1168,9 @@ begin
Pos:=0; Pos:=0;
if Length(SubStr)>0 then if Length(SubStr)>0 then
begin begin
MaxLen:=Length(source)-Length(SubStr); MaxLen:=Length(source)-Length(SubStr)-(OffSet-1);
i:=0; i:=0;
pc:=@source[1]; pc:=@source[OffSet];
while (i<=MaxLen) do while (i<=MaxLen) do
begin begin
inc(i); inc(i);
@ -1190,13 +1190,13 @@ end;
{$ifndef FPC_HAS_POS_UNICODECHAR_UNICODESTR} {$ifndef FPC_HAS_POS_UNICODECHAR_UNICODESTR}
{$define FPC_HAS_POS_UNICODECHAR_UNICODESTR} {$define FPC_HAS_POS_UNICODECHAR_UNICODESTR}
{ Faster version for a unicodechar alone } { Faster version for a unicodechar alone }
Function Pos (c : UnicodeChar; Const s : UnicodeString) : SizeInt; Function Pos (c : UnicodeChar; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
var var
i: SizeInt; i: SizeInt;
pc : punicodechar; pc : punicodechar;
begin begin
pc:=@s[1]; pc:=@s[OffSet];
for i:=1 to length(s) do for i:=OffSet to length(s) do
begin begin
if pc^=c then if pc^=c then
begin begin
@ -1212,21 +1212,21 @@ end;
{ DO NOT inline these! Inlining a managed typecast creates an implicit try..finally { DO NOT inline these! Inlining a managed typecast creates an implicit try..finally
block, which is significant bloat without any sensible speed improvement. } block, which is significant bloat without any sensible speed improvement. }
Function Pos (const c : RawByteString; Const s : UnicodeString) : SizeInt; Function Pos (const c : RawByteString; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
begin begin
result:=Pos(UnicodeString(c),s); result:=Pos(UnicodeString(c),s,offset);
end; end;
Function Pos (const c : ShortString; Const s : UnicodeString) : SizeInt; Function Pos (const c : ShortString; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
begin begin
result:=Pos(UnicodeString(c),s); result:=Pos(UnicodeString(c),s,OffSet);
end; end;
Function Pos (const c : UnicodeString; Const s : RawByteString) : SizeInt; Function Pos (const c : UnicodeString; Const s : RawByteString; Offset: Sizeint = 1) : SizeInt;
begin begin
result:=Pos(c,UnicodeString(s)); result:=Pos(c,UnicodeString(s),OffSet);
end; end;
{$ifndef FPC_HAS_POS_CHAR_UNICODESTR} {$ifndef FPC_HAS_POS_CHAR_UNICODESTR}
@ -1235,15 +1235,15 @@ Function Pos (const c : UnicodeString; Const s : RawByteString) : SizeInt;
{ pos(c: char; const s: shortstring) also exists, so otherwise } { pos(c: char; const s: shortstring) also exists, so otherwise }
{ using pos(char,pchar) will always call the shortstring version } { using pos(char,pchar) will always call the shortstring version }
{ (exact match for first argument), also with $h+ (JM) } { (exact match for first argument), also with $h+ (JM) }
Function Pos (c : Char; Const s : UnicodeString) : SizeInt; Function Pos (c : Char; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
var var
i: SizeInt; i: SizeInt;
wc : unicodechar; wc : unicodechar;
pc : punicodechar; pc : punicodechar;
begin begin
wc:=c; wc:=c;
pc:=@s[1]; pc:=@s[OffSet];
for i:=1 to length(s) do for i:=OffSet to length(s) do
begin begin
if pc^=wc then if pc^=wc then
begin begin