const
MaxGrepTokens = 64;
WordSeps : set of char = [#00,' ','-',#13, #10,'.',',','/','\', '#', '"', '''',
':','+','%','*','(',')',';','=','{','}','[',']', '{', '}', '<', '>'];
{$IFDEF PAIDVERS}
SDLVersionInfo = 'stringl_r900_full';
IsLightEd = false;
{$ELSE}
SDLVersionInfo = 'stringl_r900_lighted';
IsLightEd = true;
{$ENDIF}
Release = 900;
type
ESDLStringlError = class(ESDLError); { exception type to indicate errors }
TCharArr256 = array[0..255] of char;
TOpenStringArray = array of ShortString;
TQuotedStrState = (vsStart, vs1stQuote, vsQuote, vsNormal, vsEnd);
TGrepTokenAct = (taNormal, { normal character to be matched }
taAnyByte, { '.' - skip this character }
taEol, { '$' - end of line }
taBol, { '^' - beginning of line }
taSet, { '[]' - set of characters }
taMult0, { '*' - multiplier, including 0: any number
of this character allowed }
taMult1, { '+' - multiplier, excluding 0: at least 1
occurrence of this character required }
taOpti); { '?' - this character can occur optionally }
TGrepToken = record
Action : TGrepTokenAct;
NumChars : integer;
Params : TCharArr256;
ValidFrom: integer;
end;
{
List of actions and their parameters:
Action NumChars Params
----------------------------------------------------
taNormal #chars list of NumChars characters
taAnybyte -- --
taEol -- --
taBol -- --
taSet -- set of characters (boolean array: TRUE for members of set)
taMult0 #chars #chars > 0: list of NumChars to be matched
#chars = 0: anychar to be matched
#chars < 0: set to be matched
taMult1 #chars #chars > 0: list of NumChars to be matched
#chars = 0: anychar to be matched
#chars < 0: set to be matched
taOpti #chars #chars > 0: list of NumChars to be matched
#chars = 0: anychar to be matched
#chars < 0: set to be matched
}
TRegExp = array[1..MaxGrepTokens] of TGrepToken;
TGrep = class (TComponent)
private
FLengRegExp : integer; { no. of tokens in reg. expr. }
FStopOnError : boolean; { TRUE: raise exception on error }
FregExp : TRegExp; { regular expression tokens }
FRegExpStr : string; { original reg.exp. string }
FIgnoreCase : boolean; { TRUE: ignore case during search }
FError : integer; { error number - see SetRegExp }
FMatchEndPos : integer; { last matched position in search string }
FMatchStartPos: integer; { first matched position in search string }
FSrcStartPos : integer; { starting pos. where to start matching }
function CompileRegExp (regexp: string): integer;
procedure SetRegExp (regexp: string);
procedure SetIgnoreCase (ic: boolean);
function GetRegExpToken (regix: integer): TGrepToken;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure PrintRegExp (FName: string);
function MatchString (Instring: string; var MatchPos: integer): boolean;
property RegExpToken [regix: integer]: TGrepToken read GetRegExpToken;
property MatchEndPos: integer read FMatchEndPos;
property MatchStartPos: integer read FMatchStartPos;
property NrOfRegExpTokens: integer read FLengRegExp;
property LastError: integer read FError;
published
property IgnoreCase: boolean read FIgnoreCase write SetIgnoreCase;
property RegExp: string read FRegExpStr write SetRegExp;
property SearchStartPos: integer read FSrcStartPos write FSrcStartPos;
property StopOnError: boolean read FStopOnError write FStopOnError;
end;
{procedures and functions}
function AbbrevString
(Instring : string; { string to be abbreviated }
width : integer) { maximum width }
: string; { abbreviated string }
function BoolToStr
(ABool : boolean; { input variable }
Format : integer) { format of output }
: string; { formatted string }
function CapitalizeString
(Instring : string) { string to be capitalized }
: string; { capitalized string }
function ChangeCase
(const InString : string) { string to be converted }
: string; { string with switched cases }
function CenterString
(Instring : string; { string to center }
Width : byte) { width of result }
: string; { centered string }
function CountCharInString
(cc : char; { character to be counted }
Instring : string; { string to be analyzed }
CaseSensitive : boolean) { TRUE: search is case sensitive }
: integer; { count of cc in InString }
function CountWords
(InString : string) { string to be analyzed }
: integer; { word count of string }
function DeScramble
(Instring : string) { string to be scrambled }
: string;
function DetectNextTagInString
(const InString : string; { string to be analysed }
var StartIdx, { index of first character of tag }
StopIdx : integer; { index of last character of tag }
const TagList : array of string; { list of XML tags }
var Attrib : string; { associated attributes }
var IsClosingTag : boolean) { TRUE if tag is a closing tag }
: integer; { index of tag }
function EnsureTrailingBkSlash
(instring : string) { string to be processed }
: string;
function EnsureTrailingChar
(cc : char; { character to be forced }
instring : string) { string to be processed }
: string;
{$IFNDEF DOTNET}
function EqualAnsiStrings
(const String1, { string to compare }
String2 : string) { string to compare }
: boolean; { TRUE if strings are equal }
{$ENDIF}
function ExpandDiphthongs
(line : string) { any string }
: string; { diphthongs --> vowels }
function ExtractParam
(ParamId : string; { name of parameter to be extracted }
StartPos : integer; { position where to start the search }
AssignChar : char; { assignment character }
Terminator : char; { terminating character }
InString : string) { string to be analyzed }
: string; { value of the parameter }
{$IFNDEF DOTNET}
function ExtractSubString
(const Instring : string; { source string }
const occ : integer; { occurrence counter }
const Separator : string) { separating string }
: string; { extracted substring }
function ExtractWordFromString
(const InString : string;
const Pos : integer;
var FirstIdx,
LastIdx : integer)
: string; overload;
function ExtractWordFromString
(const InString : string;
const Pos : integer)
: string; overload;
{$ENDIF}
function FindFirstNonBlank
(const InString : string) { string to be searched }
: integer; { position of first non blank char }
function FormatData
(data : double; { data to be formatted }
NumWidth : integer; { width of resulting string }
NDecP : integer) { number of decimal places }
: string; { resulting string }
procedure InitScramble
(Key : longint); { key for scrambling }
function IsAbbreviation
(InString : string) { word to be tested }
: boolean; { TRUE if Instring is an abbreviation}
function IsDigit
(c : char)
: boolean;
function IsDigitLetter
(c : char)
: boolean;
function IsHexChar
(c : char)
: boolean;
function IsLetter
(c : char)
: boolean;
function LeftString
(Instring : string; { input string }
Width : byte) { width of result }
: string; { left adjusted string }
function MultiChar
(cc : char; { character }
RepCnt : integer) { number of repetitions }
: string; { string with RepCnt chars }
function NumberedPos
(SubStr, { sub string to be searched for }
MainStr : string; { string to be searched in }
StartIx, { index of MainStr where to start search }
Count : integer; { count of occurrence when to stop search }
IgnoreCase : boolean) { TRUE: ignore case of SubStr and MainStr }
: integer;
{$IFNDEF DOTNET}
{$IFDEF MSWINDOWS}
function OEMString
(Instring : ShortString) { input string with ANSI character set }
: ShortString; { output string with IBM character set }
{$ENDIF}
{$ENDIF}
function ParseQuotedName
(cc : char; { next character to be parsed }
QuoteChar : char; { character to be used as quote }
var CurrentName : string; { name built up so far }
var State : TQuotedStrState) { state of finite state machine }
: boolean; { TRUE if CurrentName is completed }
function PosLast
(SubStr : string; { substring to be searched for }
Instring : string) { string to be searched in }
: integer; { index where substring starts }
function ProcessHexChars
(InString : string) { string to be processed }
: string; { all \#xx replaced by actual characters }
function ReadLnString
(Instring : string; { string to be read }
var StartPos : integer; { starting/ending position }
var eos : boolean; { TRUE: end of string encountered }
EOLMode : integer) { mode of end-of-line recognition }
: string; { partial string read from Instring }
function ReadNextTagInString
(const InString : string; { string to be scanned }
var StartAt : integer; { position to start scanning }
const TagList : array of string; { list of XML tags }
var Attrib, { associated attributes }
Contents : string) { contents of tag }
: integer; { index of tag }
function ReduceStringToFN83CompliantChars
(InString : string) { string to be processed }
: string;{ string containing only Win 8.3 compliant chars }
function ReduceStringToAZ09
(InString : string) { string to be processed }
: string; { string containing only a..z and 0..9 }
function RemoveCharInString
(Instring : string; { string to be processed }
CharToRemove : char) { character to be removed from string }
: string; { resulting string }
function RemoveControlChars
(Instring : string) { input string }
: string; { no control characters }
function ReplaceCharInString
(Instring : string; { string to be processed }
OldChar : char; { old character }
NewChar : char) { new character }
: string; { resulting string }
function ReplaceStringInString
(Instring : string; { string to be processed }
OldStr : string; { substring to be replaced }
NewStr : string; { new substring }
IgnoreCase : boolean) { ignore case in search if TRUE }
: string; { resulting string }
function ReverseString
(InString : string) { string to be processed }
: string; { string with reversed order of characters }
function RightString
(Instring : string; { input string }
Width : byte) { width of result }
: string; { right aligned string }
function Scramble
(Instring : string) { string to be scrambled }
: string; { scrambled string }
function StringIx
(InString : string; { string to matched }
SArray : array of string) { string array of valid keywords }
: integer; { index of matched keyword }
function StripLeadingBlanks
(Instring : string) { input string }
: string; { string without leading blanks }
function StripLeadingChars
(cc : char; { character to be stripped off }
Instring : string) { input string }
: string; { string without leading cc(s) }
function StripLTBlanks
(Instring : string) { input string }
: string; { string without leading/trailing blanks }
function StripTrailingBlanks
(Instring : string) { input string }
: string; { string without trailing blanks }
function StripTrailingChars
(cc : char; { character to be stripped off }
Instring : string) { input string }
: string; { string without trailing cc(s) }
function strff
(r : extended; { number to convert }
FieldWidth : integer; { width of output field }
DecP : integer) { number of dec. places }
: string; { formatted string }
function strffForcePlus
(r : extended; { number to convert }
FieldWidth : integer; { width of output field }
DecP : integer) { number of dec. places }
: string; { formatted string }
function TestAllChar
(Instr : string; { string to be tested }
cc : char) { character to be searched }
: boolean; { TRUE, if string=all cc }
procedure TextLineCoords
(const InString : string; { string to be analyzed }
const Pos : integer; { string position }
var X, Y : integer); { column and row in text }
function TimeString
(Time : double; { time in sec }
Fmt : byte) { format specification }
: string; { time string }
function Tokenize
(Instring : string; { string to be analyzed }
const Separator : string; { separating string }
var Tokens : TOpenStringArray) { token found }
: integer; { number of tokens found }
function UUDecodeStr
(Instring : string) { string to be UU decoded }
: string; { UU encoded string }
function UUEncodeStr
(Instring : string) { string to be UU encoded }
: string; { UU encoded string }
{$IFNDEF DOTNET}
{$IFDEF MSWINDOWS}
function WinAnsiString
(Instring : ShortString) { input string with IBM character set }
: ShortString; { output string with ANSI character set }
{$ENDIF}
{$ENDIF}
|