D
DreamTiger
Unregistered / Unconfirmed
GUEST, unregistred user!
因为是从网上下载的一个快速替换的函数,里面用的是Object Pascal和汇编,
所以就贴到这里了。
我的问题是:下面这段程序号称是世界上最快的字符替换函数中的一段查找函
数(的确,它的替换速度比Delphi自带的快10000倍,呵呵)。但是,它对于
中文的支持很不好,主要是因为它在把大写字符变成小写字符的时候,对于中
文字符也进行了改动,这样就导致中文匹配的时候出错。我本想在大小写转换
之前先进行判断该字符是否大于128,是的话,就忽略,不替换。但是它这里
的EAX,EBX,ECX,EDX都用掉了,我对汇编也不熟,不知道应该怎么改动了,哪
位大侠出手救我出水火?(要求不能在这个函数之外先做Lowercase,否则就
没意义了)
//This routine is an identical copy of FastPOS except where commented! The ide
//a is that when grabbing bytes, it ANDs them with $df, effectively making the
//m lowercase before comparing. Maybe this would be quicker if aFindString was
// made lowercase in one fell swoop at the beginning of the function, saving a
//n AND instruction each time.
function FastPosNoCase(
const aSourceString, aFindString : String;
const aSourceLen, aFindLen, StartPos : integer
) : integer;
var
SourceLen : integer;
begin
SourceLen := aSourceLen;
SourceLen := SourceLen - aFindLen;
if (StartPos-1) > SourceLen then begin
Result := 0;
Exit;
end;
SourceLen := SourceLen - StartPos;
SourceLen := SourceLen +2;
asm
push ESI
push EDI
push EBX
mov EDI, aSourceString
add EDI, StartPos
Dec EDI
mov ESI, aFindString
mov ECX, SourceLen
Mov Al, [ESI]
// Make Al lowercase.
and Al, $df
@ScaSB:
Mov Ah, [EDI]
// Make Ah lowercase.
and Ah, $df
cmp Ah,Al
jne @NextChar
@CompareStrings:
mov EBX, aFindLen
dec EBX
//add by ShengQuanhu
Jz @EndOfMatch
//add end
@CompareNext:
mov Al, [ESI+EBX]
mov Ah, [EDI+EBX]
// Make Al and Ah lowercase.
and Al, $df
and Ah, $df
cmp Al, Ah
Jz @Matches
Mov Al, [ESI]
// Make Al lowercase.
and Al, $df
Jmp @NextChar
@Matches:
Dec EBX
Jnz @CompareNext
//add by Shengquanhu
@EndOfMatch:
//add end
mov EAX, EDI
sub EAX, aSourceString
inc EAX
mov Result, EAX
jmp @TheEnd
@NextChar:
Inc EDI
dec ECX
jnz @ScaSB
mov Result,0
@TheEnd:
pop EBX
pop EDI
pop ESI
end;
end;
所以就贴到这里了。
我的问题是:下面这段程序号称是世界上最快的字符替换函数中的一段查找函
数(的确,它的替换速度比Delphi自带的快10000倍,呵呵)。但是,它对于
中文的支持很不好,主要是因为它在把大写字符变成小写字符的时候,对于中
文字符也进行了改动,这样就导致中文匹配的时候出错。我本想在大小写转换
之前先进行判断该字符是否大于128,是的话,就忽略,不替换。但是它这里
的EAX,EBX,ECX,EDX都用掉了,我对汇编也不熟,不知道应该怎么改动了,哪
位大侠出手救我出水火?(要求不能在这个函数之外先做Lowercase,否则就
没意义了)
//This routine is an identical copy of FastPOS except where commented! The ide
//a is that when grabbing bytes, it ANDs them with $df, effectively making the
//m lowercase before comparing. Maybe this would be quicker if aFindString was
// made lowercase in one fell swoop at the beginning of the function, saving a
//n AND instruction each time.
function FastPosNoCase(
const aSourceString, aFindString : String;
const aSourceLen, aFindLen, StartPos : integer
) : integer;
var
SourceLen : integer;
begin
SourceLen := aSourceLen;
SourceLen := SourceLen - aFindLen;
if (StartPos-1) > SourceLen then begin
Result := 0;
Exit;
end;
SourceLen := SourceLen - StartPos;
SourceLen := SourceLen +2;
asm
push ESI
push EDI
push EBX
mov EDI, aSourceString
add EDI, StartPos
Dec EDI
mov ESI, aFindString
mov ECX, SourceLen
Mov Al, [ESI]
// Make Al lowercase.
and Al, $df
@ScaSB:
Mov Ah, [EDI]
// Make Ah lowercase.
and Ah, $df
cmp Ah,Al
jne @NextChar
@CompareStrings:
mov EBX, aFindLen
dec EBX
//add by ShengQuanhu
Jz @EndOfMatch
//add end
@CompareNext:
mov Al, [ESI+EBX]
mov Ah, [EDI+EBX]
// Make Al and Ah lowercase.
and Al, $df
and Ah, $df
cmp Al, Ah
Jz @Matches
Mov Al, [ESI]
// Make Al lowercase.
and Al, $df
Jmp @NextChar
@Matches:
Dec EBX
Jnz @CompareNext
//add by Shengquanhu
@EndOfMatch:
//add end
mov EAX, EDI
sub EAX, aSourceString
inc EAX
mov Result, EAX
jmp @TheEnd
@NextChar:
Inc EDI
dec ECX
jnz @ScaSB
mov Result,0
@TheEnd:
pop EBX
pop EDI
pop ESI
end;
end;