📄 ststrl.pas
字号:
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower SysTools
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* SysTools: StStrL.pas 4.03 *}
{*********************************************************}
{* SysTools: Long string routines *}
{*********************************************************}
{$I StDefine.inc}
unit StStrL;
interface
uses
Windows,
Classes,
SysUtils,
StConst,
StBase;
{.Z+}
type
LStrRec = record
AllocSize : Longint;
RefCount : Longint;
Length : Longint;
end;
const
StrOffset = SizeOf(LStrRec);
{.Z-}
{-------- Numeric conversion -----------}
function HexBL(B : Byte) : AnsiString;
{-Return the hex string for a byte.}
function HexWL(W : Word) : AnsiString;
{-Return the hex string for a word.}
function HexLL(L : LongInt) : AnsiString;
{-Return the hex string for a long integer.}
function HexPtrL(P : Pointer) : AnsiString;
{-Return the hex string for a pointer.}
function BinaryBL(B : Byte) : AnsiString;
{-Return a binary string for a byte.}
function BinaryWL(W : Word) : AnsiString;
{-Return the binary string for a word.}
function BinaryLL(L : LongInt) : AnsiString;
{-Return the binary string for a long integer.}
function OctalBL(B : Byte) : AnsiString;
{-Return an octal string for a byte.}
function OctalWL(W : Word) : AnsiString;
{-Return an octal string for a word.}
function OctalLL(L : LongInt) : AnsiString;
{-Return an octal string for a long integer.}
function Str2Int16L(const S : AnsiString; var I : SmallInt) : Boolean;
{-Convert a string to an SmallInt.}
function Str2WordL(const S : AnsiString; var I : Word) : Boolean;
{-Convert a string to a word.}
function Str2LongL(const S : AnsiString; var I : LongInt) : Boolean;
{-Convert a string to a long integer.}
{$IFDEF VER93}
function Str2RealL(const S : AnsiString; var R : Double) : Boolean;
{$ELSE}
function Str2RealL(const S : AnsiString; var R : Real) : Boolean;
{-Convert a string to a real.}
{$ENDIF}
function Str2ExtL(const S : AnsiString; var R : Extended) : Boolean;
{-Convert a string to an extended.}
function Long2StrL(L : LongInt) : AnsiString;
{-Convert an integer type to a string.}
function Real2StrL(R : Double; Width : Byte; Places : ShortInt) : AnsiString;
{-Convert a real to a string.}
function Ext2StrL(R : Extended; Width : Byte; Places : ShortInt) : AnsiString;
{-Convert an extended to a string.}
function ValPrepL(const S : AnsiString) : AnsiString;
{-Prepares a string for calling Val.}
{-------- General purpose string manipulation --------}
function CharStrL(C : AnsiChar; Len : Cardinal) : AnsiString;
{-Return a string filled with the specified character.}
function PadChL(const S : AnsiString; C : AnsiChar; Len : Cardinal) : AnsiString;
{-Pad a string on the right with a specified character.}
function PadL(const S : AnsiString; Len : Cardinal) : AnsiString;
{-Pad a string on the right with spaces.}
function LeftPadChL(const S : AnsiString; C : AnsiChar; Len : Cardinal) : AnsiString;
{-Pad a string on the left with a specified character.}
function LeftPadL(const S : AnsiString; Len : Cardinal) : AnsiString;
{-Pad a string on the left with spaces.}
function TrimLeadL(const S : AnsiString) : AnsiString;
{-Return a string with leading white space removed.}
function TrimTrailL(const S : AnsiString) : AnsiString;
{-Return a string with trailing white space removed.}
function TrimL(const S : AnsiString) : AnsiString;
{-Return a string with leading and trailing white space removed.}
function TrimSpacesL(const S : AnsiString) : AnsiString;
{-Return a string with leading and trailing spaces removed.}
function CenterChL(const S : AnsiString; C : AnsiChar; Len : Cardinal) : AnsiString;
{-Pad a string on the left and right with a specified character.}
function CenterL(const S : AnsiString; Len : Cardinal) : AnsiString;
{-Pad a string on the left and right with spaces.}
function EntabL(const S : AnsiString; TabSize : Byte) : AnsiString;
{-Convert blanks in a string to tabs.}
function DetabL(const S : AnsiString; TabSize : Byte) : AnsiString;
{-Expand tabs in a string to blanks.}
function ScrambleL(const S, Key : AnsiString) : AnsiString;
{-Encrypt / Decrypt string with enhanced XOR encryption.}
function SubstituteL(const S, FromStr, ToStr : AnsiString) : AnsiString;
{-Map the characters found in FromStr to the corresponding ones in ToStr.}
function FilterL(const S, Filters : AnsiString) : AnsiString;
{-Remove characters from a string. The characters to remove are specified in
ChSet.}
{--------------- Word / Char manipulation -------------------------}
function CharExistsL(const S : AnsiString; C : AnsiChar) : Boolean;
{-Determine whether a given character exists in a string. }
function CharCountL(const S : AnsiString; C : AnsiChar) : Cardinal;
{-Count the number of a given character in a string. }
function WordCountL(const S, WordDelims : AnsiString) : Cardinal;
{-Given an array of word delimiters, return the number of words in a string.}
function WordPositionL(N : Cardinal; const S, WordDelims : AnsiString;
var Pos : Cardinal) : Boolean;
{-Given an array of word delimiters, set Pos to the start position of the
N'th word in a string. Result indicates success/failure.}
function ExtractWordL(N : Cardinal; const S, WordDelims : AnsiString) : AnsiString;
{-Given an array of word delimiters, return the N'th word in a string.}
function AsciiCountL(const S, WordDelims : AnsiString; Quote : AnsiChar) : Cardinal;
{-Return the number of words in a string.}
function AsciiPositionL(N : Cardinal; const S, WordDelims : AnsiString;
Quote : AnsiChar; var Pos : Cardinal) : Boolean;
{-Return the position of the N'th word in a string.}
function ExtractAsciiL(N : Cardinal; const S, WordDelims : AnsiString;
Quote : AnsiChar) : AnsiString;
{-Given an array of word delimiters, return the N'th word in a string. Any
text within Quote characters is counted as one word.}
procedure WordWrapL(const InSt : AnsiString; var OutSt, Overlap : AnsiString;
Margin : Cardinal; PadToMargin : Boolean);
{-Wrap a text string at a specified margin.}
{--------------- String comparison and searching -----------------}
function CompStringL(const S1, S2 : AnsiString) : Integer;
{-Compare two strings.}
function CompUCStringL(const S1, S2 : AnsiString) : Integer;
{-Compare two strings. This compare is not case sensitive.}
function SoundexL(const S : AnsiString) : AnsiString;
{-Return 4 character soundex of an input string.}
function MakeLetterSetL(const S : AnsiString) : Longint;
{-Return a bit-mapped long storing the individual letters contained in S.}
procedure BMMakeTableL(const MatchString : AnsiString; var BT : BTable);
{-Build a Boyer-Moore link table}
function BMSearchL(var Buffer; BufLength : Cardinal; var BT : BTable;
const MatchString : AnsiString ; var Pos : Cardinal) : Boolean;
{-Use the Boyer-Moore search method to search a buffer for a string.}
function BMSearchUCL(var Buffer; BufLength : Cardinal; var BT : BTable;
const MatchString : AnsiString ; var Pos : Cardinal) : Boolean;
{-Use the Boyer-Moore search method to search a buffer for a string. This
search is not case sensitive.}
{--------------- DOS pathname parsing -----------------}
function DefaultExtensionL(const Name, Ext : AnsiString) : AnsiString;
{-Return a file name with a default extension attached.}
function ForceExtensionL(const Name, Ext : AnsiString) : AnsiString;
{-Force the specified extension onto the file name.}
function JustFilenameL(const PathName : AnsiString) : AnsiString;
{-Return just the filename and extension of a pathname.}
function JustNameL(const PathName : AnsiString) : AnsiString;
{-Return just the filename (no extension, path, or drive) of a pathname.}
function JustExtensionL(const Name : AnsiString) : AnsiString;
{-Return just the extension of a pathname.}
function JustPathnameL(const PathName : AnsiString) : AnsiString;
{-Return just the drive and directory portion of a pathname.}
function AddBackSlashL(const DirName : AnsiString) : AnsiString;
{-Add a default backslash to a directory name.}
function CleanPathNameL(const PathName : AnsiString) : AnsiString;
{-Return a pathname cleaned up as DOS does it.}
function HasExtensionL(const Name : AnsiString; var DotPos : Cardinal) : Boolean;
{-Determine if a pathname contains an extension and, if so, return the
position of the dot in front of the extension.}
{------------------ Formatting routines --------------------}
function CommaizeL(L : LongInt) : AnsiString;
{-Convert a long integer to a string with commas.}
function CommaizeChL(L : Longint; Ch : AnsiChar) : AnsiString;
{-Convert a long integer to a string with Ch in comma positions.}
function FloatFormL(const Mask : AnsiString ; R : TstFloat ; const LtCurr,
RtCurr : AnsiString ; Sep, DecPt : AnsiChar) : AnsiString;
{-Return a formatted string with digits from R merged into mask.}
function LongIntFormL(const Mask : AnsiString ; L : LongInt ; const LtCurr,
RtCurr : AnsiString ; Sep : AnsiChar) : AnsiString;
{-Return a formatted string with digits from L merged into mask.}
function StrChPosL(const P : AnsiString; C : AnsiChar; var Pos : Cardinal) : Boolean;
{-Return the position of a specified character within a string.}
function StrStPosL(const P, S : AnsiString; var Pos : Cardinal) : Boolean;
{-Return the position of a specified substring within a string.}
function StrStCopyL(const S : AnsiString; Pos, Count : Cardinal) : AnsiString;
{-Copy characters at a specified position in a string.}
function StrChInsertL(const S : AnsiString; C : AnsiChar; Pos : Cardinal) : AnsiString;
{-Insert a character into a string at a specified position.}
function StrStInsertL(const S1, S2 : AnsiString; Pos : Cardinal) : AnsiString;
{-Insert a string into another string at a specified position.}
function StrChDeleteL(const S : AnsiString; Pos : Cardinal) : AnsiString;
{-Delete the character at a specified position in a string.}
function StrStDeleteL(const S : AnsiString; Pos, Count : Cardinal) : AnsiString;
{-Delete characters at a specified position in a string.}
{-------------------------- New Functions -----------------------------------}
function ContainsOnlyL(const S, Chars : AnsiString;
var BadPos : Cardinal) : Boolean;
function ContainsOtherThanL(const S, Chars : AnsiString;
var BadPos : Cardinal) : Boolean;
function CopyLeftL(const S : AnsiString; Len : Cardinal) : AnsiString;
{-Return the left Len characters of a string}
function CopyMidL(const S : AnsiString; First, Len : Cardinal) : AnsiString;
{-Return the mid part of a string}
function CopyRightL(const S : AnsiString; First : Cardinal) : AnsiString;
{-Return the right Len characters of a string}
function CopyRightAbsL(const S : AnsiString; NumChars : Cardinal) : AnsiString;
{-Return NumChar characters starting from end}
function CopyFromNthWordL(const S, WordDelims : AnsiString;
const AWord : AnsiString; N : Cardinal; {!!.02}
var SubString : AnsiString) : Boolean;
function CopyFromToWordL(const S, WordDelims, Word1, Word2 : AnsiString;
N1, N2 : Cardinal;
var SubString : AnsiString) : Boolean;
function CopyWithinL(const S, Delimiter : AnsiString;
Strip : Boolean) : AnsiString;
function DeleteFromNthWordL(const S, WordDelims : AnsiString;
const AWord : AnsiString; N : Cardinal; {!!.02}
var SubString : AnsiString) : Boolean;
function DeleteFromToWordL(const S, WordDelims, Word1, Word2 : AnsiString;
N1, N2 : Cardinal;
var SubString : AnsiString) : Boolean;
function DeleteWithinL(const S, Delimiter : AnsiString) : AnsiString;
function ExtractTokensL(const S, Delims: AnsiString;
QuoteChar : AnsiChar;
AllowNulls : Boolean;
Tokens : TStrings) : Cardinal;
function IsChAlphaL(C : AnsiChar) : Boolean;
{-Returns true if Ch is an alpha}
function IsChNumericL(C : AnsiChar; const Numbers : AnsiString) : Boolean; {!!.02}
{-Returns true if Ch in numeric set}
function IsChAlphaNumericL(C : AnsiChar; const Numbers : AnsiString) : Boolean; {!!.02}
{-Returns true if Ch is an alpha or numeric}
function IsStrAlphaL(const S : AnsiString) : Boolean;
{-Returns true if all characters in string are an alpha}
function IsStrNumericL(const S, Numbers : AnsiString) : Boolean;
{-Returns true if all characters in string are in numeric set}
function IsStrAlphaNumericL(const S, Numbers : AnsiString) : Boolean;
{-Returns true if all characters in string are alpha or numeric}
function KeepCharsL(const S, Chars : AnsiString) : AnsiString;
function LastWordL(const S, WordDelims, AWord : AnsiString;
var Position : Cardinal) : Boolean;
function LastWordAbsL(const S, WordDelims : AnsiString;
var Position : Cardinal) : Boolean;
function LastStringL(const S, AString : AnsiString;
var Position : Cardinal) : Boolean;
function LeftTrimCharsL(const S, Chars : AnsiString) : AnsiString;
function ReplaceWordL(const S, WordDelims, OldWord, NewWord : AnsiString;
N : Cardinal;
var Replacements : Cardinal) : AnsiString;
function ReplaceWordAllL(const S, WordDelims, OldWord, NewWord : AnsiString;
var Replacements : Cardinal) : AnsiString;
function ReplaceStringL(const S, OldString, NewString : AnsiString;
N : Cardinal;
var Replacements : Cardinal) : AnsiString;
function ReplaceStringAllL(const S, OldString, NewString : AnsiString;
var Replacements : Cardinal) : AnsiString;
function RepeatStringL(const RepeatString : AnsiString;
var Repetitions : Cardinal;
MaxLen : Cardinal) : AnsiString;
function RightTrimCharsL(const S, Chars : AnsiString) : AnsiString;
function StrWithinL(const S, SearchStr : string;
Start : Cardinal;
var Position : Cardinal) : boolean;
{-finds the position of a substring within a string starting at a given point}
function TrimCharsL(const S, Chars : AnsiString) : AnsiString;
function WordPosL(const S, WordDelims, AWord : AnsiString;
N : Cardinal; var Position : Cardinal) : Boolean;
{-returns the Occurrence instance of a word within a string}
implementation
{-------- Numeric conversion -----------}
function HexBL(B : Byte) : AnsiString;
{-Return the hex string for a byte.}
begin
SetLength(Result, 2);
Result[1] := StHexDigits[B shr 4];
Result[2] := StHexDigits[B and $F];
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -