2 Star 10 Fork 0

唯尔默.序 / nginx-tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LbUtils.pas 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
wilmerxu 提交于 2020-11-21 15:46 . add nginx tool code
{$I LockBox.inc}
unit LbUtils;
{- odds-n-ends }
interface
uses
SysUtils;
function BufferToHex(const Buf; BufSize : Cardinal) : string;
function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;
function Min(A, B : LongInt) : LongInt;
function Max(A, B : LongInt) : LongInt;
function CompareBuffers(const Buf1, Buf2; BufSize : Cardinal) : Boolean;
{$IFDEF Debugging}
procedure DebugStr(const AStr : string);
procedure DebugLogFile(const AFileName : string);
{$ENDIF}
implementation
{$IFDEF Debugging}
var
DebugLogFileName : string = 'LbDebug.txt';
procedure DebugStr(const AStr : string);
var
F : TextFile;
begin
try
AssignFile(F, DebugLogFileName);
Append(F);
except
on E : EInOutError do
if (E.ErrorCode = 2) or (E.ErrorCode = 32) then
Rewrite(F)
else
raise;
end;
WriteLn(F, AStr);
Close(F);
if IOResult <> 0 then ;
end;
procedure DebugLogFile(const AFileName : string);
begin
if FileExists(AFileName) then
DeleteFile(AFileName);
DebugLogFileName := AFileName;
end;
{$ENDIF}
{ -------------------------------------------------------------------------- }
function BufferToHex(const Buf; BufSize : Cardinal) : string;
var
I : LongInt;
begin
Result := '';
for I := 0 to BufSize - 1 do
Result := Result + IntToHex(TByteArray(Buf)[I], 2); {!!.01}
end;
{ -------------------------------------------------------------------------- }
function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;
var
i, C : Integer;
Str : string;
Count : Integer;
begin
Result := False;
Str := '';
for i := 1 to Length(Hex) do
if Upcase(Hex[i]) in ['0'..'9', 'A'..'F'] then
Str := Str + Hex[i];
FillChar(Buf, BufSize, #0);
Count := Min(Length(Hex), BufSize);
for i := 0 to Count - 1 do begin
Val('$' + Copy(Str, (i shl 1) + 1, 2), TByteArray(Buf)[i], C); {!!.01}
if (C <> 0) then
Exit;
end;
Result := True;
end;
{ -------------------------------------------------------------------------- }
function Min(A, B : LongInt) : LongInt;
begin
if A < B then
Result := A
else
Result := B;
end;
{ -------------------------------------------------------------------------- }
function Max(A, B : LongInt) : LongInt;
begin
if A > B then
Result := A
else
Result := B;
end;
{ -------------------------------------------------------------------------- }
function CompareBuffers(const Buf1, Buf2; BufSize : Cardinal) : Boolean;
{ return true if buffers are the same }
var
i : Integer;
begin
Result := False;
for i := 0 to Pred(BufSize) do begin
Result := TByteArray(Buf1)[i] = TByteArray(Buf2)[i];
if not Result then
Break;
end;
end;
end.
Delphi
1
https://gitee.com/wilmerxu/nginx-tool.git
git@gitee.com:wilmerxu/nginx-tool.git
wilmerxu
nginx-tool
nginx-tool
master

搜索帮助