Вниз
Скачать: CL | DM;

Binary search   Найти похожие ветки 

 
Jon ©   (2008-01-19 05:21) [0]

How can I search within a binary string for a substring?
Both Pos and IndexOfStr fail when a #$00 is encountered.


 
Vladimir Kladov ©   (2008-01-19 10:53) [1]

I"ll fix IndexOfStr (IndexOfChar) in the update (soon).


 
Jon ©   (2008-01-19 19:42) [2]

Works perfectly in v2.86 - many thanks!


 
Jon ©   (2008-01-20 06:16) [3]


> Works perfectly in v2.86 - many thanks!

Upon further testing I was wrong.

If the substring in IndexOfStr(String,Substring) is not found, the procedure locks up.

Also, if the substring contains #$00 such as IndexOfStr(String,#$00#$FF) the result is the position of first #$00 found.


 
Vladimir Kladov ©   (2008-01-20 11:27) [4]

PAS_VERSION works perfectly. Here is a fix for asm-version. When you test it, I"ll release an update.

function IndexOfStr( const S, Sub : String ) : Integer;
asm
       PUSH     EBX
       PUSH     ESI
       PUSH     EDI

       PUSH     EAX
       MOV      EAX, EDX
       PUSH     EDX
       CALL     System.@LStrLen
       MOV      EDI, EAX
       POP      EAX
       //CALL     System.@LStrToPChar
       CALL     EAX2PChar
       MOV      BL, [EAX]
       XCHG     EAX, [ESP]
       //CALL     System.@LStrToPChar
       CALL     EAX2PChar

       MOV      ESI, EAX

       DEC      EAX
@@1:    INC      EAX
       MOV      DL, BL
       MOV      ECX, [ESI-4]
       SUB      ECX, EAX
       ADD      ECX, ESI

       CMP      ECX, EDI
       JL       @@ret__1

       CALL     StrScanLen
       TEST     EAX, EAX
       JE       @@exit__1
       DEC      EAX

       POP      EDX
       PUSH     EDX

       MOV      ECX, EDI
       PUSH     EAX
       //CALL     StrLComp
       CALL     CompareMem
       TEST     AL, AL
       POP      EAX
       JZ       @@1

       SUB      EAX, ESI
       INC      EAX
       JMP      @@exit

@@ret__1:
       XOR      EAX, EAX
@@exit__1:
       DEC      EAX
@@exit:
       POP      EDX
       POP      EDI
       POP      ESI
       POP      EBX
end;


 
Jon ©   (2008-01-20 15:32) [5]


> PAS_VERSION works perfectly. Here is a fix for asm-version.
>  When you test it, I"ll release an update.


Yes, it works. Thank you and well done!



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: -0.991 c
15-1237468819
Мастак
2009-03-19 16:20
2009.05.24
Как выяснить чего XML-парсеру не хватает?


2-1239395171
Johnnnnn
2009-04-11 00:26
2009.05.24
Строка или текст через clipboard , незнаю как правильно.


15-1237897102
Я
2009-03-24 15:18
2009.05.24
Выключение компа


15-1237385822
Альф
2009-03-18 17:17
2009.05.24
Как выравнять размер exe кратным 4K


2-1239003940
dreamse
2009-04-06 11:45
2009.05.24
Отследить подключение устройства в без оконом приложении




   Наверх