![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Binary search
Jon © (2008-01-19 05:21:00)How can I search within a binary string for a substring?
Both Pos and IndexOfStr fail when a #$00 is encountered.
Jon (2008-01-20 15:32:00) [1]
> 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!
Vladimir Kladov (2008-01-20 11:27:00) [2]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 06:16:00) [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.
Jon (2008-01-19 19:42:00) [4]Works perfectly in v2.86 - many thanks!
Vladimir Kladov (2008-01-19 10:53:00) [5]I'll fix IndexOfStr (IndexOfChar) in the update (soon).