⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hyperstr.pas

📁 String hanlding library. Functions for crypto, token etc
💻 PAS
📖 第 1 页 / 共 5 页
字号:
@Exit:

    Pop   EBP              //restore the world
    Pop   EDI
    Pop   ESI
    Pop   EBX

    Mov   Result,EAX       //output length
  end;


function DeleteT(var Source:AnsiString;const Table:AnsiString):Integer;

  {Convert any Table char. into right justified space which can be
   deleted if necessary using RTrim or SetLength.

   Returns: Valid char. count (length minus chars. converted to spaces); zero on error.}

begin
  Result:=DeleteI(Source,Table,1);
end;


function DeleteTQ(var Source:AnsiString;const Table:AnsiString):Integer;

  {Convert Table chars. into right justified spaces which can be deleted if
   necessary using RTrim or SetLength. Characters inside dbl quotes are ignored.

   Returns: Valid char. count; length minus chars. converted to spaces.}

  asm

    Push  EBX              //save the important stuff
    Push  ESI
    Push  EDI
    Push  EBP

    Or    EAX,EAX
    Jz    @Exit
    Push  EAX
    Push  EDX
    Push  ECX
    Call  UniqueString
    Pop   ECX
    Pop   EDX
    Pop   EAX
    Mov   EAX,[EAX]
    Mov   ECX,1
    Call  _TableScanIni
    Jecxz @Abort
    Push  ECX              //save length
    Sub   ECX,EAX          //adjust for Start
    Mov   EBX,ESI          //use EBX as write pointer
    Xor   EAX,EAX
    Xor   EDX,EDX

@Next:
    Lodsb                  //get the byte
    Mov   DL,AL            //save it in DL
    Mov   DH,DL            //and in DH
    Cmp   AL,34            //dbl quote ?
    Jnz   @Skip2           //no, then skip
    Xor   EDX,$40000000    //set flag
//    Jmp   @Skip2
//@Skip1:
//    Cmp   AL,39            //single quote ?
//    Jnz   @Skip2           //no, then skip
//    Xor   EDX,$20000000    //set flag
@Skip2:
    Test  EDX,$60000000    //quotes clear ?
    Jnz   @Write           //no, then write it out
    And   DL,31            //bit index
    Shr   EAX,5            //dbl-word index
    Shl   EAX,2
    Mov   EBP,[EDI+EAX]    //get the dbl-word
    Bt    EBP,EDX
//*    Bt    EBP,DL           //test the bit
    Jc    @Skip            //skip write if in Table
@Write:
    Mov   [EBX],DH
    Inc   EBX
@Skip:
    Dec   ECX
    Jnz   @Next
@Done:
    Pop   EAX              //original source length
    Mov   DH,32            //prepare to space fill
@L3:
    Cmp   EBX,ESI          //read = write ?
    Jz    @Exit            //yes, then we're done
    Mov   [EBX],DH         //no, then space fill
    Inc   EBX
    Dec   EAX              //adjust output length
    Jmp   @L3              //and do it again

@Abort:
    Xor   EAX,EAX
@Exit:

    Pop   EBP              //restore the world
    Pop   EDI
    Pop   ESI
    Pop   EBX

    Mov   Result,EAX       //output length
  end;


function DeleteNT(var Source:AnsiString;const Table:AnsiString):Integer;

  {Convert any non-Table character into right justified space
   which can be deleted if necessary using RTrim or SetLength.

   Returns: Valid char. count (length minus chars. converted to spaces); zero on error.}

begin
  Result:=DeleteNI(Source,Table,1);
end;


function DeleteNI(var Source:AnsiString;const Table:AnsiString; const Index:Integer):Integer;

  {Convert any non-Table character from Index forward into right justified space
   which can be deleted if necessary using RTrim or SetLength.

   Returns: Valid char. count; length minus chars. converted to spaces.

   Example: One application might be to filter keystroke errors from user
            input after the fact.

            Source:='$123X4.56  ';
            I:=DeleteNT(Source,'$+-0123456789.');

            On return, I=8, Source='$1234.56   '

   Same as MakeTable() but faster for longer strings (30+ characters).}

  asm

    Push  EBX              //save the important stuff
    Push  ESI
    Push  EDI
    Push  EBP

    Or    EAX,EAX
    Jz    @Exit
    Push  EAX
    Push  EDX
    Push  ECX
    Call  UniqueString
    Pop   ECX
    Pop   EDX
    Pop   EAX
    Mov   EAX,[EAX]
    Call  _TableScanIni
    Jecxz @Abort
    Push  ECX              //save length
    Sub   ECX,EAX          //adjust for Start
    Mov   EBX,ESI          //use EBX as write pointer
    Xor   EAX,EAX

@Next:
    Lodsb                  //get the byte
    Mov   DL,AL            //save it in DL
    Mov   DH,DL            //and in DH
    And   DL,31            //bit index
    Shr   EAX,5            //dbl-word index
    Shl   EAX,2
    Mov   EBP,[EDI+EAX]    //get the dbl-word
    Bt    EBP,EDX
//*    Bt    EBP,DL           //test the bit
    Jnc   @Skip            //skip write if not in Table
    Mov   [EBX],DH
    Inc   EBX
@Skip:
    Dec   ECX
    Jnz   @Next

    Pop   EAX              //original source length
    Mov   DH,32            //prepare to space fill
@L3:
    Cmp   EBX,ESI          //read = write ?
    Jz    @Exit            //yes, then we're done
    Mov   [EBX],DH         //no, then space fill
    Inc   EBX
    Dec   EAX              //adjust output length
    Jmp   @L3              //and do it again

@Abort:
    Xor   EAX,EAX
@Exit:

    Pop   EBP              //restore the world
    Pop   EDI
    Pop   ESI
    Pop   EBX

    Mov   Result,EAX       //output length
  end;


function  IsFloat(const Source:AnsiString):Boolean;

  {Determine if a string contains characters,0-9,space,E,+,-,DecimalSeparator}
asm
  Push  ESI             //save the important stuff

  Mov   EAX,Source
  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,DecSep
  Jz    @OK             //Decimal is OK
  Cmp   AL,32
  Jz    @OK             //space is OK
  Cmp   AL,43
  Jz    @OK             //+ is OK
  Cmp   AL,45
  Jz    @OK             //- is OK
  Cmp   AL,69
  Jz    @OK             //'E' is OK
  Cmp   AL,101
  Jz    @OK             //'e' is OK
  Cmp   AL,48
  Jb    @NG             //less than 0 is NG
  Cmp   AL,57
  Ja    @NG             //greater than 9 is NG
@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
  Mov   Result,AL
end;                    //and we're outta here


function  IsDateTime(const Source:AnsiString):Boolean;

  {Determine if a string contains only char. 0-9,space,-,DateSeperator,TimeSeparator}
asm
  Push  ESI             //save the important stuff

  Mov   EAX,Source
  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
  Jz    @OK             //space is OK
  Cmp   AL,TimeSep
  Jz    @OK             //Time is OK
  Cmp   AL,DateSep
  Jz    @OK             //Date is OK
  Cmp   AL,45
  Jz    @OK             //- is OK
  Cmp   AL,65
  Jz    @OK
  Cmp   AL,77
  Jz    @OK
  Cmp   AL,80
  Jz    @OK
  Cmp   AL,48
  Jb    @NG             //less than 0 is NG
  Cmp   AL,57
  Ja    @NG             //greater than 9 is NG
@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
  Mov   Result,AL
end;                    //and we're outta here


function  IsTable(const Source,Table:AnsiString):Boolean;

  {Determine if string is composed solely of table characters.}

begin
  Result:=CountT(Source,Table,1)=Length(Source);
end;


function  IsField(const Source,Table:AnsiString;const Index,Cnt:Integer):Boolean;

  {Determine if a fielded portion of a string is composed solely of table characters.
   Field begins at Index position and is Cnt characters in length.}

begin
  Result:=CountM(Source,Table,Index)>=Cnt;
end;


function  IsSet(const Source:AnsiString;Multiple,Single:TCharSet):Boolean;
  {Determine if string is composed solely of characters from given sets. Only a
   single instance of characters in Single set is allowed}
var
  S:TCharSet;
  I:Integer;
begin
  Result:=False;
  I:=Length(Source);
  if I=0 then Exit;
  S:=Single;
  repeat
    if not (Source[I] in Multiple) then begin
      if not (Source[I] in S) then break else Exclude(S,Source[I]);
    end;
    Dec(I);
  until I=0;
  Result:=I=0;
end;


function  _IsTMask(const Source:AnsiString):Boolean;

  {Determine if a string contains only table characters. Table address = EDX}

  asm
    Push  ESI             //save the important stuff
    Push  EDI

    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
    Mov   EDI,EDX      //initialize scan array
    Xor   EDX,EDX
@Start:
    Lodsb                 //get a byte

    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
    Jnc   @NG             //abort if NG

    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   EDI
    Pop   ESI             //restore the important stuff
  end;                    //and we're outta here


function  IsNum(const Source:AnsiString):Boolean;

  {Determine if a string contains only digits (0-9) and spaces.}

  asm
    Lea   EDX,NumT      //initialize scan array
    Jmp   _ISTMask
  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -