?? hyperstr.pas
字號:
function IsNumChar(const C:Char):Boolean;
{Determine if a character is an ASCII digit(0-9).}
asm
Or EAX,EAX
Jz @Done //abort if nil address
Cmp AL,48
Jb @NG //less than 0 is NG
Cmp AL,57
Ja @NG //greater than 9 is NG
Mov EAX,True //OK
Jmp @Done
@NG:
Xor EAX,EAX
@Done:
end; //and we're outta here
function IsAlphaChar(const C:Char):Boolean;
{Determine if a character is in [A..Z,a..z].}
asm
Or EAX,EAX
Jz @Done //abort if nil address
Push EDI
Lea EDI,AlphaT
And EAX,255
Mov EDX,EAX
And EDX,7 //bit index
Shr EAX,3 //byte index
Mov AL,[EDI+EAX] //get byte
Bt EAX,EDX //test the bit
Pop EDI
Jnc @NG //abort if NG
Mov EAX,True //OK
Jmp @Done
@NG:
Xor EAX,EAX
@Done:
end; //and we're outta here
function IsAlphaNumChar(const C:Char):Boolean;
{Determine if a character is in [0..9,A..Z,a..z].}
asm
Or EAX,EAX
Jz @Done //abort if nil address
Push EDI
Lea EDI,AlphaNumT
And EAX,255
Mov EDX,EAX
And EDX,7 //bit index
Shr EAX,3 //byte index
Mov AL,[EDI+EAX] //get byte
Bt EAX,EDX //test the bit
Pop EDI
Jnc @NG //abort if NG
Mov EAX,True //OK
Jmp @Done
@NG:
Xor EAX,EAX
@Done:
end; //and we're outta here
function IsHex(const Source:AnsiString):Boolean;
{Determine if a string contains only digits (0-9,A-F) and spaces.}
asm
Lea EDX,HexT //initialize scan array
Jmp _IsTMask
end;
function IsAlpha(const Source:AnsiString):Boolean;
{Determine if a string contains only ASCII alpha characters and spaces.}
asm
Lea EDX,AlphaT //initialize scan array
Jmp _IsTMask
end;
function IsAlphaNum(const Source:AnsiString):Boolean;
{Determine if a string contains only alphabetic characters,digits,space.}
asm
Lea EDX,AlphaNumT //initialize scan array
Jmp _IsTMask
end;
function IsMask(const Source,Mask:AnsiString;Index:Integer):Boolean;
{Validate Source from start to Index (-1 = Full) for conformance to a
'picture mask' (similar to Delphi's EditMask) composed from the
following special character set.
A - Alphanumeric required (a..z,A..Z,0..9)
a - Alphanumeric permitted
C - Alphabetic character required (a..z,A..Z)
c - Alphabetic character permitted
0 - Numeric required (0..9)
9 - Numeric permitted
# - +/- permitted
? - Any character required (#0..#255)
@ - Any character permitted
| - Literal next, required
\ - Literal next, permitted
NOTE: Trailing spaces are allowed, leading spaces are not.
Index provides support for partial, incremental validation. If
Index<>-1, validation is only performed on the characters present.
In other words, Source is allowed to be incomplete compared to Mask.
To FULLY validate the entire Mask, you MUST use Index = -1.}
var
I,J:Integer;
begin
Result:=False;
R1:=Length(Source);
R2:=Length(Mask);
if (R2=0) OR (R1=0) then Exit;
if (Index>0) and (Index<R1) then R1:=Index;
J:=1; //initialize Mask pointer
I:=1; //initialize Source pointer
bI:=False;
bJ:=False;
while I<=R1 do begin
bX:=False; //assume invalid character
case Mask[J] of
'#':if (Source[I]<>#45) AND (Source[I]<>#43) then
bJ:=True
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'0':if (Source[I]<#48) OR (Source[I]>#57) then
break
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'9':if (Source[I]<#48) OR (Source[I]>#57) then begin
bJ:=True;
end else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'?','@':begin
bX:=True;
bI:=True;
bJ:=True;
end;
'A':if (Source[I]=#32) OR (IsAlphaNumChar(Source[I])=False) then
//(Source[I]<#48) OR (Source[I]>#122) OR ((Source[I]>#57) AND (Source[I]<#65)) OR ((Source[I]>#90) AND (Source[I]<#97)) then
break
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'C':if (Source[I]=#32) OR (IsAlphaChar(Source[I])=False) then
//(Source[I]<#65) OR (Source[I]>#122) OR ((Source[I]>#90) AND (Source[I]<#97)) then
break
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'a':if (Source[I]=#32) OR (IsAlphaNumChar(Source[I])=False) then
//(Source[I]<#48) OR (Source[I]>#122) OR ((Source[I]>#57) AND (Source[I]<#65)) OR ((Source[I]>#90) AND (Source[I]<#97)) then
bJ:=True
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'c':if (Source[I]=#32) OR (IsAlphaChar(Source[I])=False) then
//(Source[I]<#65) OR (Source[I]>#122) OR ((Source[I]>#90) AND (Source[I]<#97)) then
bJ:=True
else begin
bX:=True;
bI:=True;
bJ:=True;
end;
'\':begin
if J=R2 then break;
J:=J+1;
if Source[I]=Mask[J] then begin
bX:=True;
bI:=True;
bJ:=True;
end else bJ:=True;
end;
'|':begin
if J=R2 then break;
J:=J+1;
if Source[I]<>Mask[J] then break;
bX:=True;
bI:=True;
bJ:=True;
end;
else
break;
end;
if bJ then begin //increment Mask pointer
if J=R2 then break;
J:=J+1;
bJ:=False;
end;
if bI then begin //increment Source pointer
if I=R1 then break;
I:=I+1;
bI:=False;
end;
end;
if bX then begin //last character matched
if bJ then begin //end of Mask
Result:=True;
if I<R1 then begin //not end of Source
for I:=I TO R1 do begin
if Source[I]<>#32 then begin //not a space
Result:=False; //invalid
break;
end;
end;
end;
end else if Index<>-1 then //partial validation
Result:=True
else //full validation
Result:=CountT(Mask,'AC0?|',J)=0;
end;
end;
function IsNull(const Source:AnsiString):Boolean;
{Determine if a string contains only char. 0-32 and 255.}
asm
Push ESI //save the important stuff
Or EAX,EAX
Jz @Done //abort if nil address
Mov ESI,EAX //put address into write register
Mov ECX,[EAX-4] //put length into count register
Xor EAX,EAX
Jecxz @Done //bail out if zero length
Cld
@Start:
Lodsb //get a byte
Cmp AL,32
Jbe @OK //less than or equal to space is OK
Cmp AL,255
Jnz @NG //255 is OK
@OK:
Dec ECX
Jnz @Start
Mov EAX,True //if we make it here, we've got a good one
Jmp @Done
@NG:
Xor EAX,EAX
@Done:
Pop ESI //restore the important stuff
end; //and we're outta here
function IsFound(const Source,Search:AnsiString;Start:Integer):Boolean;
{Returns True if Search is found within Source from Start location forward.
Search may contain any number of different tokens by using '&' (ASCII 38)
as a kind of logical AND operator. Supports case insensitive using negative Start.
Example: IsFound(S,'who&what&when',I);}
var
I,J:Integer;
Token:AnsiString;
begin
Result:=False;
if Length(Source)=0 then Exit;
I:=1;
J:=Length(Search);
repeat
Token:=ParseWord(Search,'&',I);
if Length(Token)>0 then
if ScanF(Source,Token,Start)>0 then begin
Result:=True;
Break;
end;
until (I<1) OR (I>J);
end;
function UChar(const Source:Char):Char;
{Upper case a single character; similar to the built-in UpperCase
function but with a Char compatible resultant using user-defined table.}
begin
Result := UprCase[Ord(Source)];
end;
function LChar(const Source:Char):Char;
{Lower case a single character; similar to the built-in LowerCase
function but with a Char compatible resultant using user-defined table.}
begin
Result:=LowCase[Ord(Source)];
end;
function RChar(const Source:Char):Char;
{Reverse the case (lower to upper or upper to lower) of a single character
using user-defined table.}
begin
Result:=RevCase[Ord(Source)];
end;
procedure _TstBit;
asm
Push EDX
Push EAX
And EAX,255
Mov EDX,EAX
And EDX,7 //bit index
Shr EAX,3 //byte index
Mov AL,[EBX+EAX] //get byte
Bt EAX,EDX //test the bit
Pop EAX
Pop EDX
end;
function IsMatch(const Source,Pattern:AnsiString; CaseFlg:Boolean):Boolean;
{Returns True if Source contains a match for a pattern string containing
wildcards:
'*' = match any string (including null string)
'?' = match any single character
'#' = match any numeric character (0..9)
'@' = match any alpha character (a..z, A..Z)
'$' = match any alphanumeric character
'~' = match any non-alpahumeric, non-space char.
else = match given character only
Case insensitive if CaseFlg = True.}
asm
Push ESI
Push EDI
Push EBX
Push EBP
Or EAX,EAX //zero source ?
Jz @NotFound
Or EDX,EDX //zero search ?
Jz @NotFound
Mov ESI,EAX //source address
Mov EDI,EDX //search address
Xor EAX,EAX //clear for case flag
Jecxz @L0 //skip if case sensitive
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -