- Timestamp:
- Jul 11, 2018, 3:36:39 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UCommon.pas
r515 r517 75 75 FilterMethod: TFilterMethodMethod = nil); 76 76 function GetStringPart(var Text: string; Separator: string): string; 77 function PosFromIndex(SubStr: string; Text: string; 78 StartIndex: Integer): Integer; 79 function PosFromIndexReverse(SubStr: string; Text: string; 80 StartIndex: Integer): Integer; 77 81 78 82 … … 559 563 end; 560 564 561 565 function PosFromIndex(SubStr: string; Text: string; 566 StartIndex: Integer): Integer; 567 var 568 I, MaxLen: SizeInt; 569 Ptr: PAnsiChar; 570 begin 571 Result := 0; 572 if (StartIndex < 1) or (StartIndex > Length(Text) - Length(SubStr)) then Exit; 573 if Length(SubStr) > 0 then begin 574 MaxLen := Length(Text) - Length(SubStr) + 1; 575 I := StartIndex; 576 Ptr := @Text[StartIndex]; 577 while (I <= MaxLen) do begin 578 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 579 Result := I; 580 Exit; 581 end; 582 Inc(I); 583 Inc(Ptr); 584 end; 585 end; 586 end; 587 588 function PosFromIndexReverse(SubStr: string; Text: string; 589 StartIndex: Integer): Integer; 590 var 591 I: SizeInt; 592 Ptr: PAnsiChar; 593 begin 594 Result := 0; 595 if (StartIndex < 1) or (StartIndex > Length(Text)) then Exit; 596 if Length(SubStr) > 0 then begin 597 I := StartIndex; 598 Ptr := @Text[StartIndex]; 599 while (I > 0) do begin 600 if (SubStr[1] = Ptr^) and (CompareByte(Substr[1], Ptr^, Length(SubStr)) = 0) then begin 601 Result := I; 602 Exit; 603 end; 604 Dec(I); 605 Dec(Ptr); 606 end; 607 end; 608 end; 562 609 563 610 initialization
Note:
See TracChangeset
for help on using the changeset viewer.