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

📄 hutil32.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      if Count <= srclen then
      begin
        ch := str[Count];
        for I := 0 to ArrCount - 1 do
          if ch = Divider[I] then
            goto CATCH_DIV;
      end;
      if (Count > srclen) then
      begin
        CATCH_DIV:
        if (BufCount > 0) or (ch <> ' ') then
        begin
          if BufCount <= 0 then
          begin
            buf[0] := ch;
            buf[1] := #0;
            ch := ' ';
          end
          else
            buf[BufCount] := #0;
          dest := string(buf);
          if ch <> ' ' then
            Result := Copy(str, Count, srclen - Count + 1)
              //remain divider in rest-string,
          else
            Result := Copy(str, Count + 1, srclen - Count); //exclude whitespace
          break;
        end
        else
        begin
          if (Count > srclen) then
          begin
            dest := '';
            Result := Copy(str, Count + 2, srclen - 1);
            break;
          end;
        end;
      end
      else
      begin
        if BufCount < BUF_SIZE - 1 then
        begin
          buf[BufCount] := ch;
          Inc(BufCount);
        end
        else
          ShowMessage('BUF_SIZE overflow !');
      end;
      Inc(Count);
    end;
  finally
    //LeaveCriticalSection (CSUtilLock);
  end;
end;


function GetValidStrVal(str: string; var dest: string; const Divider: array of
  Char): string;
//箭磊甫 盒府秦晨 ex) 12.30mV
const
  BUF_SIZE                              = 15600;
var
  buf                                   : array[0..BUF_SIZE] of Char;
  BufCount, Count, srclen, I, ArrCount  : Longint;
  ch                                    : Char;
  currentNumeric                        : Boolean;
  hexmode                               : Boolean;
label
  CATCH_DIV;
begin
  ch := #0;                                                 //Jacky
  try
    //EnterCriticalSection (CSUtilLock);
    hexmode := False;
    srclen := length(str);
    BufCount := 0;
    Count := 1;
    currentNumeric := False;

    if str = '' then
    begin
      dest := '';
      Result := str;
      exit;
    end;
    ArrCount := SizeOf(Divider) div SizeOf(Char);

    while true do
    begin
      if Count <= srclen then
      begin
        ch := str[Count];
        for I := 0 to ArrCount - 1 do
          if ch = Divider[I] then
            goto CATCH_DIV;
      end;
      if not currentNumeric then
      begin
        if (Count + 1) < srclen then
        begin
          if (str[Count] = '0') and (UpCase(str[Count + 1]) = 'X') then
          begin
            buf[BufCount] := str[Count];
            buf[BufCount + 1] := str[Count + 1];
            Inc(BufCount, 2);
            Inc(Count, 2);
            hexmode := true;
            currentNumeric := true;
            Continue;
          end;
          if (ch = '-') and (str[Count + 1] >= '0') and (str[Count + 1] <= '9')
            then
          begin
            currentNumeric := true;
          end;
        end;
        if (ch >= '0') and (ch <= '9') then
        begin
          currentNumeric := true;
        end;
      end
      else
      begin
        if hexmode then
        begin
          if not (((ch >= '0') and (ch <= '9')) or
            ((ch >= 'A') and (ch <= 'F')) or
            ((ch >= 'a') and (ch <= 'f'))) then
          begin
            Dec(Count);
            goto CATCH_DIV;
          end;
        end
        else if ((ch < '0') or (ch > '9')) and (ch <> '.') then
        begin
          Dec(Count);
          goto CATCH_DIV;
        end;
      end;
      if (Count > srclen) then
      begin
        CATCH_DIV:
        if (BufCount > 0) then
        begin
          buf[BufCount] := #0;
          dest := string(buf);
          Result := Copy(str, Count + 1, srclen - Count);
          break;
        end
        else
        begin
          if (Count > srclen) then
          begin
            dest := '';
            Result := Copy(str, Count + 2, srclen - 1);
            break;
          end;
        end;
      end
      else
      begin
        if BufCount < BUF_SIZE - 1 then
        begin
          buf[BufCount] := ch;
          Inc(BufCount);
        end
        else
          ShowMessage('BUF_SIZE overflow !');
      end;
      Inc(Count);
    end;
  finally
    //LeaveCriticalSection (CSUtilLock);
  end;
end;

{" " capture => CaptureString (source: string; var rdstr: string): string;
 ** 贸澜俊 " 绰 亲惑 盖 贸澜俊 乐促绊 啊沥
}

function GetValidStrCap(str: string; var dest: string; const Divider: array of
  Char): string;
begin
  str := TrimLeft(str);
  if str <> '' then
  begin
    if str[1] = '"' then
      Result := CaptureString(str, dest)
    else
    begin
      Result := GetValidStr3(str, dest, Divider);
    end;
  end
  else
  begin
    Result := '';
    dest := '';
  end;
end;


function IntToStrFill(num, len: Integer; fill: Char): string;
var
  I                                     : Integer;
  str                                   : string;
begin
  Result := '';
  str := IntToStr(num);
  for I := 1 to len - length(str) do
    Result := Result + fill;
  Result := Result + str;
end;

function IntToStr2(INT: Integer): string;
begin
  if INT < 10 then
  begin
    Result := '0' + IntToStr(INT);
  end
  else
  begin
    Result := IntToStr(INT);
  end;
end;

function IsInB(src: string; Pos: Integer; targ: string): Boolean;
var
  tLen, I                               : Integer;
begin
  Result := False;
  tLen := length(targ);
  if length(src) < Pos + tLen then
    exit;
  for I := 0 to tLen - 1 do
    if UpCase(src[Pos + I]) <> UpCase(targ[I + 1]) then
      exit;

  Result := true;
end;

function IsInRect(X, Y: Integer; Rect: TRect): Boolean;
begin
  if (X >= Rect.Left) and (X <= Rect.Right) and (Y >= Rect.Top) and (Y <=
    Rect.Bottom) then
    Result := true
  else
    Result := False;
end;

function IsStringNumber(str: string): Boolean;
var
  I                                     : Integer;
begin
  Result := true;
  for I := 1 to length(str) do
    if (Byte(str[I]) < Byte('0')) or (Byte(str[I]) > Byte('9')) then
    begin
      Result := False;
      break;
    end;
end;


{Return : remain string}

function ArrestString(Source, SearchAfter, ArrestBefore: string;
  const DropTags: array of string; var RsltStr: string): string;
const
  BUF_SIZE                              = $7FFF;
var
  buf                                   : array[0..BUF_SIZE] of Char;
  BufCount, SrcCount, srclen, {AfterLen, BeforeLen,} DropCount, I: Integer;
  ArrestNow                             : Boolean;
begin
  try
    //EnterCriticalSection (CSUtilLock);
    RsltStr := '';                                          {result string}
    srclen := length(Source);

    if srclen > BUF_SIZE then
    begin
      Result := '';
      exit;
    end;

    BufCount := 0;
    SrcCount := 1;
    ArrestNow := False;
    DropCount := SizeOf(DropTags) div SizeOf(string);

    if (SearchAfter = '') then
      ArrestNow := true;

    //GetMem (Buf, BUF_SIZE);

    while true do
    begin
      if SrcCount > srclen then
        break;

      if not ArrestNow then
      begin
        if IsInB(Source, SrcCount, SearchAfter) then
          ArrestNow := true;
      end
      else
      begin
        buf[BufCount] := Source[SrcCount];
        if IsInB(Source, SrcCount, ArrestBefore) or (BufCount >= BUF_SIZE - 2)
          then
        begin
          BufCount := BufCount - length(ArrestBefore);
          buf[BufCount + 1] := #0;
          RsltStr := string(buf);
          BufCount := 0;
          break;
        end;

        for I := 0 to DropCount - 1 do
        begin
          if IsInB(Source, SrcCount, DropTags[I]) then
          begin
            BufCount := BufCount - length(DropTags[I]);
            break;
          end;
        end;

        Inc(BufCount);
      end;
      Inc(SrcCount);
    end;

    if (ArrestNow) and (BufCount <> 0) then
    begin
      buf[BufCount] := #0;
      RsltStr := string(buf);
    end;

    Result := Copy(Source, SrcCount + 1, srclen - SrcCount);
    {result is remain string}
  finally
    //LeaveCriticalSection (CSUtilLock);
  end;
end;


function ArrestStringEx(Source, SearchAfter, ArrestBefore: string; var
  ArrestStr: string): string;
var
  BufCount, SrcCount, srclen            : Integer;
  GoodData, Fin                         : Boolean;
  I, n                                  : Integer;
begin
  ArrestStr := '';                                          {result string}
  if Source = '' then
  begin
    Result := '';
    exit;
  end;

  try
    srclen := length(Source);
    GoodData := False;
    if srclen >= 2 then
      if Source[1] = SearchAfter then
      begin
        Source := Copy(Source, 2, srclen - 1);
        srclen := length(Source);
        GoodData := true;
      end
      else
      begin
        n := Pos(SearchAfter, Source);
        if n > 0 then
        begin
          Source := Copy(Source, n + 1, srclen - (n));
          srclen := length(Source);
          GoodData := true;
        end;
      end;
    Fin := False;
    if GoodData then
    begin
      n := Pos(ArrestBefore, Source);
      if n > 0 then
      begin
        ArrestStr := Copy(Source, 1, n - 1);
        Result := Copy(Source, n + 1, srclen - n);
      end
      else
      begin
        Result := SearchAfter + Source;
      end;
    end
    else
    begin
      for I := 1 to srclen do
      begin
        if Source[I] = SearchAfter then
        begin
          Result := Copy(Source, I, srclen - I + 1);
          break;
        end;
      end;
    end;
  except
    ArrestStr := '';
    Result := '';
  end;
end;

function SkipStr(src: string; const Skips: array of Char): string;
var
  I, len, C                             : Integer;
  NowSkip                               : Boolean;
begin
  len := length(src);
  //   Count := sizeof(Skips) div sizeof (Char);

  for I := 1 to len do
  begin
    NowSkip := False;
    for C := Low(Skips) to High(Skips) do
      if src[I] = Skips[C] then
      begin
        NowSkip := true;
        break;
      end;
    if not NowSkip then
      break;
  end;

  Result := Copy(src, I, len - I + 1);

end;


function GetStrToCoords(str: string): TRect;
var
  Temp                                  : string;
begin

  str := GetValidStr3(str, Temp, [',', ' ']);
  Result.Left := Str_ToInt(Temp, 0);
  str := GetValidStr3(str, Temp, [',', ' ']);
  Result.Top := Str_ToInt(Temp, 0);
  str := GetValidStr3(str, Temp, [',', ' ']);
  Result.Right := Str_ToInt(Temp, 0);
  GetValidStr3(str, Temp, [',', ' ']);
  Result.Bottom := Str_ToInt(Temp, 0);

end;

function CombineDirFile(SrcDir, TargName: string): string;
begin
  if (SrcDir = '') or (TargName = '') then
  begin
    Result := SrcDir + TargName;
    exit;
  end;
  if SrcDir[length(SrcDir)] = '\' then
    Result := SrcDir + TargName
  else
    Result := SrcDir + '\' + TargName;
end;

function CompareLStr(src, targ: string; compn: Integer): Boolean;
var
  I                                     : Integer;
begin
  Result := False;
  if compn <= 0 then
    exit;
  if length(src) < compn then
    exit;
  if length(targ) < compn then
    exit;
  Result := true;
  for I := 1 to compn do
    if UpCase(src[I]) <> UpCase(targ[I]) then
    begin
      Result := False;
      break;
    end;
end;

function CompareBuffer(p1, p2: Pbyte; len: Integer): Boolean;
var
  I                                     : Integer;
begin
  Result := true;
  for I := 0 to len - 1 do
    if Pbyte(Integer(p1) + I)^ <> Pbyte(Integer(p2) + I)^ then
    begin
      Result := False;

⌨️ 快捷键说明

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