Recent

Author Topic: A faster alternative to PosEx?  (Read 7219 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 6235
  • Compiler Developer
Re: A faster alternative to PosEx?
« Reply #15 on: September 18, 2020, 09:22:54 am »
The Haystack is made up of [A-Z] only, because that's what PosEx likes.

I'm not aware of any restrictions of PosEx regarding the character ranges it supports (of course restricted to $0 to $ff for the AnsiString variants and $0 to $ffff for the UnicodeString ones).

d2010

  • Full Member
  • ***
  • Posts: 235
Re: A faster alternative to PosEx?
« Reply #16 on: January 09, 2025, 09:04:54 am »
Here is my update
Code: [Select]
function Low_tally(exew:word;partstring:shortstring;const somestring:string;pos1:integer):tpoint;
var gap,i10,j10,sln,lnp,count:integer;
    ccd:char;
    cntall:boolean;
Label Parintelui_Arsenie2024Skip,
      Parintelui_Arsenie2025Skip;
Begin
if (length(partstring)<02) then begin result.x:=RTCAN;result.Y:=RTCAN;exit;end;
result.x :=00;Sln:=length(somestring);
result.y :=00;lnp:=length(partstring);
cntall:=false;

case exew and 03  of
01:Begin
        for i10:=001 to lnp do if (partstring[i10] in ['A'..'Z']) then inc(partstring[i10],032);
      End;//OFF("forced lowercase IF i am not sure partstring is lowered")
02: cntall:=true;
03:Begin
       for i10:=001 to lnp do if (partstring[i10] in ['A'..'Z']) then inc(partstring[i10],032);
       cntall:=true;
    End;
end;
partstring:=partstring+#00;
gap :=000; if (pos1<01) then pos1:=001;
case cntall of
true: for i10:=pos1 to sln do if (i10>=gap) then
       begin ccd:=somestring[i10];
         if (ccd in ['A'..'Z']) then inc(ccd,032);
         if (ccd <> partstring[01]) then goto Parintelui_Arsenie2025Skip;
        for j10:=001 to lnp  do
          begin  gap :=i10+j10-0000000001;
                 ccd :=somestring[gap];if (ccd in ['A'..'Z']) then inc(ccd,032);
                 if (ccd=partstring[j10]) then else goto Parintelui_Arsenie2025Skip;
           end;//far("LowPosEx, PosEx, LowPos Low_Pos, PosExLow")
        result.x:=i10;
        inc(result.y);
Parintelui_Arsenie2025Skip:
    end;//off"return x.last position")


false: for i10:=pos1 to sln do if (i10>=gap) then
       begin ccd:=somestring[i10];
         if (ccd in ['A'..'Z']) then inc(ccd,032);
         if (ccd <> partstring[01]) then goto Parintelui_Arsenie2024skip;
        for j10:=001 to lnp  do
          begin  gap :=i10+j10-0000000001;
                 ccd :=somestring[gap];if (ccd in ['A'..'Z']) then inc(ccd,032);
                 if (ccd=partstring[j10]) then else goto Parintelui_Arsenie2024Skip;
           end;//far("LowPosEx, PosEx, LowPos Low_Pos, PosExLow")
        result.x:=i10;result.y:=01;exit;
Parintelui_Arsenie2024Skip:
    end;//off"return x.last position")
 end;//off("case")
end;//off("Low_tally")


Code: [Select]
123"c:\\Vlaxcompil\\0user" tesfd
Coo. 0=6
Coo. 1=0
Coo. 2=6
Coo. 3=0
Coo. 4=6
Coo. 5=6
Coo. 6=0
Coo. 7=6
Coo. 8=6
Coo. 9=6
Coo.10=6
Coo.11=1
1

« Last Edit: January 09, 2025, 09:09:26 am by d2010 »

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: A faster alternative to PosEx?
« Reply #17 on: January 09, 2025, 10:22:09 am »
Note that you should also test TRegExpr with a compiled regex, because in many cases that can also beat posex. (not always, but always close)
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

BeniBela

  • Hero Member
  • *****
  • Posts: 948
    • homepage
Re: A faster alternative to PosEx?
« Reply #18 on: January 09, 2025, 06:25:24 pm »
Note that you should also test TRegExpr with a compiled regex, because in many cases that can also beat posex. (not always, but always close)

or TFLRE

Fast is in its name


Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: A faster alternative to PosEx?
« Reply #19 on: January 09, 2025, 06:58:21 pm »
Yes, in complex cases both may beat posex. Not always, but...
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018