Browse Source

* pos(shortstring,ansistring) for bug #4119

git-svn-id: trunk@828 -
marco 20 years ago
parent
commit
fa19bc05c8
2 changed files with 27 additions and 0 deletions
  1. 26 0
      rtl/inc/astrings.inc
  2. 1 0
      rtl/inc/systemh.inc

+ 26 - 0
rtl/inc/astrings.inc

@@ -495,6 +495,32 @@ begin
   Pointer(fpc_ansistr_Copy):=ResultAddress;
   Pointer(fpc_ansistr_Copy):=ResultAddress;
 end;
 end;
 
 
+Function Pos (Const Substr : ShortString; Const Source : AnsiString) : SizeInt;
+
+var
+  i,MaxLen : SizeInt;
+  pc : pchar;
+begin
+  Pos:=0;
+  if Length(SubStr)>0 then
+   begin
+     MaxLen:=Length(source)-Length(SubStr);
+     i:=0;
+     pc:=@source[1];
+     while (i<=MaxLen) do
+      begin
+        inc(i);
+        if (SubStr[1]=pc^) and
+           (CompareByte(Substr[1],pc^,Length(SubStr))=0) then
+         begin
+           Pos:=i;
+           exit;
+         end;
+        inc(pc);
+      end;
+   end;
+end;
+
 
 
 Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
 Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
 var
 var

+ 1 - 0
rtl/inc/systemh.inc

@@ -457,6 +457,7 @@ Procedure Insert(const source:shortstring;Var s:shortstring;index:SizeInt);
 Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
 Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
 Function  Pos(const substr:shortstring;const s:shortstring):SizeInt;
 Function  Pos(const substr:shortstring;const s:shortstring):SizeInt;
 Function  Pos(C:Char;const s:shortstring):SizeInt;
 Function  Pos(C:Char;const s:shortstring):SizeInt;
+Function  Pos (Const Substr : ShortString; Const Source : AnsiString) : SizeInt;
 Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
 Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
 Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
 Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
 Function  upCase(const s:shortstring):shortstring;
 Function  upCase(const s:shortstring):shortstring;