How to change WideString Pos to PosEx?


2008-01-21 01:18:48 PM
delphi3
Hi All,
Below code is extracted from Delphi system unit.
I want to change it to Pos(const substr, str: WideString; Start:Integer):
Integer
How to do this? I could not understand the ASM well.
P.S. where does FastCode do not support WideString?
Thanks!
Bear
function Pos(const substr, str: WideString): Integer; overload;
asm
{ ->EAX Pointer to substr }
{ EDX Pointer to string }
{ <-EAX Position of substr in str or 0 }
TEST EAX,EAX
JE @@noWork
TEST EDX,EDX
JE @@stringEmpty
PUSH EBX
PUSH ESI
PUSH EDI
MOV ESI,EAX { Point ESI to
}
MOV EDI,EDX { Point EDI to
}
MOV ECX,[EDI-4] { ECX =
}
SHR ECX,1
PUSH EDI { remember s position to
calculate index }
MOV EDX,[ESI-4] { EDX =
bstr) }
SHR EDX,1
DEC EDX { EDX = Length(substr) -
}
JS @@fail { < 0 ? return
}
MOV AX,[ESI] { AL = first char of
}
ADD ESI,2 { Point ESI to 2'nd char of
substr }
SUB ECX,EDX { #positions in s to look
}
{ = Length(s) -
Length(substr) + 1 }
JLE @@fail
@@loop:
REPNE SCASW
JNE @@fail
MOV EBX,ECX { save outer loop
}
PUSH ESI { save outer loop substr
pointer }
PUSH EDI { save outer loop s
}
MOV ECX,EDX
REPE CMPSW
POP EDI { restore outer loop s
pointer }
POP ESI { restore outer loop substr
pointer }
JE @@found
MOV ECX,EBX { restore outer loop
nter }
JMP @@loop
@@fail:
POP EDX { get rid of saved s
nter }
XOR EAX,EAX
JMP @@exit
@@stringEmpty:
XOR EAX,EAX
JMP @@noWork
@@found:
POP EDX { restore pointer to first
char of s }
MOV EAX,EDI { EDI points of char after
match }
SUB EAX,EDX { the difference is the
correct index }
SHR EAX,1
@@exit:
POP EDI
POP ESI
POP EBX
@@noWork:
end;