Unit HUtil32;
Provides a large number of auxiliary functions
{$WARNINGS OFF}
Interface
Uses
Classes, Sysutils, Wintypes, Winprocs, Graphics, Messages, Dialogs;
Type
Str4096 = array [0..4096] of Ansichar;
Str256 = array [0..256] of Ansichar;
Name, value comparison table
Tynametable = Record
name:string;
Varl:longint;
End
Tlrect = Record
Left, Top, right, bottom:longint;
End
Take Searchafter, arrestbefore between the strings
function Arreststringex (Source, Searchafter, arrestbefore:ansistring; var arreststr:ansistring): ansistring;
Gets a substring in the specified string that ends with the specified delimiter
function GetValidStr3 (str:ansistring; var dest:ansistring; const Divider:array of Ansichar): ansistring;
Implementation
function Arreststringex (Source, Searchafter, arrestbefore:ansistring; var arreststr:ansistring): ansistring;
Var
Srclen:integer;
Gooddata: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
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
Gets a substring in the specified string that ends with the specified delimiter
function GetValidStr3 (str:ansistring; var dest:ansistring; const Divider:array of Ansichar): ansistring;
Const
Buf_size = 20480; $7FFF;
Var
Buf:array[0..buf_size] of Ansichar;
Bufcount, Count, Srclen, I, Arrcount:longint;
Ch:ansichar;
Label
Catch_div;
Begin
Try
Srclen: = Length (STR);
Bufcount: = 0;
Count: = 1;
If Srclen >= buf_size-1 then BEGIN
Result: = ';
Dest: = ";
Exit
End
If Str = "THEN BEGIN"
Dest: = ";
Result: = STR;
Exit
End
Arrcount: = sizeof (Divider) div sizeof (Ansichar);
While TRUE does 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 (Count > Srclen) THEN BEGIN
Catch_div:
if (Bufcount > 0) THEN BEGIN
If Bufcount < buf_size-1 then BEGIN
Buf[bufcount]: = #0;
Dest: = string (BUF);
Result: = Copy (Str, count+1, Srclen-count);
End
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
End
INC (Count);
End
Except
Dest: = ";
Result: = ';
End
End
End.
String Communication protocol parsing function