Вниз
Скачать: 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.007 c
2-1239116506
CodeMaster
2009-04-07 19:01
2009.05.24
Помогите перевести с С++ на Delphi


2-1239259328
worldmen
2009-04-09 10:42
2009.05.24
Ошибки при добавление картинок в БД Interbase


4-1209885111
angel095
2008-05-04 11:11
2009.05.24
Файловая система фотоаппарата


15-1237993387
Showmessage
2009-03-25 18:03
2009.05.24
Матрица


2-1239266420
Андрей_1
2009-04-09 12:40
2009.05.24
Выловить окончание работы плеера




   Наверх