📄 ststrz.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: StStrZ.pas 4.03 *}
{*********************************************************}
{* SysTools: Null terminated string routines *}
{*********************************************************}
{$I StDefine.inc}
unit StStrZ;
interface
uses
Windows,
Classes, SysUtils, StConst, StBase;
{-------- Numeric conversion -----------}
function HexBZ(Dest : PAnsiChar; B : Byte) : PAnsiChar;
{-Return the hex string for a byte.}
function HexWZ(Dest : PAnsiChar; W : Word) : PAnsiChar;
{-Return the hex string for a word.}
function HexLZ(Dest : PAnsiChar; L : LongInt) : PAnsiChar;
{-Return the hex string for a long integer.}
function HexPtrZ(Dest : PAnsiChar; P : Pointer) : PAnsiChar;
{-Return the hex string for a pointer.}
function BinaryBZ(Dest : PAnsiChar; B : Byte) : PAnsiChar;
{-Return a binary string for a byte.}
function BinaryWZ(Dest : PAnsiChar; W : Word) : PAnsiChar;
{-Return the binary string for a word.}
function BinaryLZ(Dest : PAnsiChar; L : LongInt) : PAnsiChar;
{-Return the binary string for a long integer.}
function OctalBZ(Dest : PAnsiChar; B : Byte) : PAnsiChar;
{-Return an octal string for a byte.}
function OctalWZ(Dest : PAnsiChar; W : Word) : PAnsiChar;
{-Return an octal string for a word.}
function OctalLZ(Dest : PAnsiChar; L : LongInt) : PAnsiChar;
{-Return an octal string for a long integer.}
function Str2Int16Z(S : PAnsiChar; var I : SmallInt) : Boolean;
{-Convert a string to an SmallInt.}
function Str2WordZ(S : PAnsiChar; var I : Word) : Boolean;
{-Convert a string to a word.}
function Str2LongZ(S : PAnsiChar; var I : LongInt) : Boolean;
{-Convert a string to a long integer.}
{$IFDEF VER93}
function Str2RealZ(S : PAnsiChar; var R : Double) : Boolean;
{$ELSE}
function Str2RealZ(S : PAnsiChar; var R : Real) : Boolean;
{$ENDIF}
{-Convert a string to a real.}
function Str2ExtZ(S : PAnsiChar; var R : Extended) : Boolean;
{-Convert a string to an extended.}
function Long2StrZ(Dest : PAnsiChar; L : LongInt) : PAnsiChar;
{-Convert an integer type to a string.}
function Real2StrZ(Dest : PAnsiChar; R : Double; Width : Byte;
Places : ShortInt) : PAnsiChar;
{-Convert a real to a string.}
function Ext2StrZ(Dest : PAnsiChar; R : Extended; Width : Byte;
Places : ShortInt) : PAnsiChar;
{-Convert an extended to a string.}
function ValPrepZ(S : PAnsiChar) : PAnsiChar;
{-Prepares a string for calling Val.}
{-------- General purpose string manipulation --------}
function CharStrZ(Dest : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Return a string filled with the specified character.}
function PadChZ(Dest, S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the right with a specified character.}
function PadZ(Dest, S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the right with spaces.}
function LeftPadChZ(Dest, S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left with a specified character.}
function LeftPadZ(Dest, S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left with spaces.}
function PadChPrimZ(S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the right with a specified character.
This primitive version modifies the source string directly.}
function PadPrimZ(S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the right with spaces. This primitive version modifies the
source string directly.}
function LeftPadChPrimZ(S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left with a specified character. This primitive
version modifies the source string directly.}
function LeftPadPrimZ(S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left with spaces. This primitive version modifies the
source string directly.}
function TrimLeadZ(Dest, S : PAnsiChar) : PAnsiChar;
{-Return a string with leading white space removed.}
function TrimTrailZ(Dest, S : PAnsiChar) : PAnsiChar;
{-Return a string with trailing white space removed.}
function TrimZ(Dest, S : PAnsiChar) : PAnsiChar;
{-Return a string with leading and trailing white space removed.}
function TrimSpacesZ(Dest, S : PAnsiChar) : PAnsiChar;
{-Return a string with leading and trailing spaces removed.}
function TrimLeadPrimZ(S : PAnsiChar) : PAnsiChar;
{-Return a string with leading white space removed. This primitive version
modifies the source string directly.}
function TrimTrailPrimZ(S : PAnsiChar) : PAnsiChar;
{-Return a string with trailing white space removed. This primitive version
modifies the source string directly.}
function TrimPrimZ(S : PAnsiChar) : PAnsiChar;
{-Return a string with leading and trailing white space removed. This
primitive version modifies the source string directly.}
function TrimSpacesPrimZ(S : PAnsiChar) : PAnsiChar;
{-Return a string with leading and trailing spaces removed. This primitive
version modifies the source string directly.}
function CenterChPrimZ(S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left and right with a specified character. This
primitive version modifies the source string directly.}
function CenterPrimZ(S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left and right with spaces. This primitive version
modifies the source string directly.}
function CenterChZ(Dest, S : PAnsiChar; C : AnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left and right with a specified character.}
function CenterZ(Dest, S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Pad a string on the left and right with spaces.}
function EntabZ(Dest, Src : PAnsiChar; TabSize : Byte) : PAnsiChar;
{-Convert blanks in a string to tabs.}
function DetabZ(Dest, Src : PAnsiChar; TabSize : Byte) : PAnsiChar;
{-Expand tabs in a string to blanks.}
function ScramblePrimZ(S, Key : PAnsiChar) : PAnsiChar;
{-Encrypt / Decrypt string with enhanced XOR encryption. This
primitive version modifies the source string directly.}
function ScrambleZ(Dest, S, Key : PAnsiChar) : PAnsiChar;
{-Encrypt / Decrypt string with enhanced XOR encryption.}
function SubstituteZ(Dest, Src, FromStr, ToStr : PAnsiChar) : PAnsiChar;
{-Map the characters found in FromStr to the corresponding ones in ToStr.}
function FilterZ(Dest, Src, Filters : PAnsiChar) : PAnsiChar;
{-Remove characters from a string. The characters to remove are specified in
ChSet.}
{--------------- Word / Char manipulation -------------------------}
function CharExistsZ(S : PAnsiChar; C : AnsiChar) : Boolean;
{-Determine whether the given character exists in a string. }
function CharCountZ(S : PAnsiChar; C : AnsiChar) : Cardinal;
{-Count the number of a given character in a string. }
function WordCountZ(S : PAnsiChar; WordDelims : PAnsiChar) : Cardinal;
{-Given an array of word delimiters, return the number of words in a string.}
function WordPositionZ(N : Cardinal; S : PAnsiChar; WordDelims : PAnsiChar;
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 ExtractWordZ(Dest : PAnsiChar; N : Cardinal; Src : PAnsiChar;
WordDelims : PAnsiChar) : PAnsiChar;
{-Given an array of word delimiters, return the N'th word in a string.}
function AsciiCountZ(S : PAnsiChar; WordDelims : PAnsiChar; Quote : AnsiChar) : Cardinal;
{-Return the number of words in a string.}
function AsciiPositionZ(N : Cardinal; S : PAnsiChar; WordDelims : PAnsiChar;
Quote : AnsiChar; var Pos : Cardinal) : Boolean;
{-Return the position of the N'th word in a string.}
function ExtractAsciiZ(Dest : PAnsiChar; N : Cardinal; Src : PAnsiChar;
WordDelims : PAnsiChar; Quote : AnsiChar) : PAnsiChar;
{-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 WordWrapZ(Dest : PAnsiChar; InSt, Overlap : PAnsiChar;
Margin : Cardinal;
PadToMargin : Boolean);
{-Wrap a text string at a specified margin.}
{--------------- String comparison and searching -----------------}
function CompStringZ(S1, S2 : PAnsiChar) : Integer;
{-Compare two strings.}
function CompUCStringZ(S1, S2 : PAnsiChar) : Integer;
{-Compare two strings. This compare is not case sensitive.}
function SoundexZ(Dest : PAnsiChar; S : PAnsiChar) : PAnsiChar;
{-Return 4 character soundex of an input string}
function MakeLetterSetZ(S : PAnsiChar) : Longint;
{-Return a bit-mapped long storing the individual letters contained in S.}
procedure BMMakeTableZ(MatchString : PAnsiChar; var BT : BTable);
{-Build a Boyer-Moore link table}
function BMSearchZ(var Buffer; BufLength : Cardinal; var BT : BTable;
MatchString : PAnsiChar ; var Pos : Cardinal) : Boolean;
{-Use the Boyer-Moore search method to search a buffer for a string.}
function BMSearchUCZ(var Buffer; BufLength : Cardinal; var BT : BTable;
MatchString : PAnsiChar ; 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 DefaultExtensionZ(Dest : PAnsiChar; Name, Ext : PAnsiChar) : PAnsiChar;
{-Return a file name with a default extension attached.}
function ForceExtensionZ(Dest : PAnsiChar; Name, Ext : PAnsiChar) : PAnsiChar;
{-Force the specified extension onto the file name.}
function JustFilenameZ(Dest : PAnsiChar; PathName : PAnsiChar) : PAnsiChar;
{-Return just the filename and extension of a pathname.}
function JustNameZ(Dest : PAnsiChar; PathName : PAnsiChar) : PAnsiChar;
{-Return just the filename (no extension, path, or drive) of a pathname.}
function JustExtensionZ(Dest : PAnsiChar; Name : PAnsiChar) : PAnsiChar;
{-Return just the extension of a pathname.}
function JustPathnameZ(Dest : PAnsiChar; PathName : PAnsiChar) : PAnsiChar;
{-Return just the drive and directory portion of a pathname.}
function AddBackSlashZ(Dest : PAnsiChar; DirName : PAnsiChar) : PAnsiChar;
{-Add a default backslash to a directory name.}
function CleanPathNameZ(Dest : PAnsiChar; PathName : PAnsiChar) : PAnsiChar;
{-Return a pathname cleaned up as DOS does it.}
function HasExtensionZ(Name : PAnsiChar; 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 CommaizeZ(Dest : PAnsiChar; L : LongInt) : PAnsiChar;
{-Convert a long integer to a string with commas.}
function CommaizeChZ(Dest : PAnsiChar; L : Longint; Ch : AnsiChar) : PAnsiChar;
{-Convert a long integer to a string with Ch in comma positions.}
function FloatFormZ(Dest, Mask : PAnsiChar ; R : TstFloat ; LtCurr,
RtCurr : PAnsiChar ; Sep, DecPt : AnsiChar) : PAnsiChar;
{-Return a formatted string with digits from R merged into mask.}
function LongIntFormZ(Dest, Mask : PAnsiChar ; L : LongInt ; LtCurr,
RtCurr : PAnsiChar ; Sep : AnsiChar) : PAnsiChar;
{-Return a formatted string with digits from L merged into mask.}
function StrChPosZ(P : PAnsiChar; C : AnsiChar; var Pos : Cardinal) : Boolean;
{-Return the position of a specified character within a string.}
function StrStPosZ(P, S : PAnsiChar; var Pos : Cardinal) : Boolean;
{-Return the position of a specified substring within a string.}
function StrStCopyZ(Dest, S : PAnsiChar; Pos, Count : Cardinal) : PAnsiChar;
{-Copy characters at a specified position in a string.}
function StrChInsertZ(Dest, S : PAnsiChar; C : AnsiChar; Pos : Cardinal) : PAnsiChar;
{-Insert a character into a string at a specified position.}
function StrStInsertZ(Dest, S1, S2 : PAnsiChar; Pos : Cardinal) : PAnsiChar;
{-Insert a string into another string at a specified position.}
function StrChDeleteZ(Dest, S : PAnsiChar; Pos : Cardinal) : PAnsiChar;
{-Delete the character at a specified position in a string.}
function StrStDeleteZ(Dest, S : PAnsiChar; Pos, Count : Cardinal) : PAnsiChar;
{-Delete characters at a specified position in a string.}
function StrChInsertPrimZ(Dest : PAnsiChar; C : AnsiChar; Pos : Cardinal) : PAnsiChar;
{-Insert a character into a string at a specified position. This primitive
version modifies the source string directly.}
function StrStInsertPrimZ(Dest, S : PAnsiChar; Pos : Cardinal) : PAnsiChar;
{-Insert a string into another string at a specified position. This
primitive version modifies the source string directly.}
function StrChDeletePrimZ(P : PAnsiChar; Pos : Cardinal) : PAnsiChar;
{-Delete the character at a specified position in a string. This primitive
version modifies the source string directly.}
function StrStDeletePrimZ(P : PAnsiChar; Pos, Count : Cardinal) : PAnsiChar;
{-Delete characters at a specified position in a string. This primitive
version modifies the source string directly.}
{-------------------------- New Functions -----------------------------------}
function ContainsOnlyZ(const S, Chars : PAnsiChar;
var BadPos : Cardinal) : Boolean;
function ContainsOtherThanZ(const S, Chars : PAnsiChar;
var BadPos : Cardinal) : Boolean;
function CopyFromNthWordZ(Dest, S, WordDelims, AWord : PAnsiChar;
N : Cardinal) : Boolean;
function CopyFromToWordZ(Dest, S, WordDelims, Word1, Word2 : PAnsiChar;
N1, N2 : Cardinal) : Boolean;
function CopyLeftZ(Dest, S : PAnsiChar; Len : Cardinal) : PAnsiChar;
{-Return the left Len characters of a string}
function CopyMidZ(Dest, S : PAnsiChar; First, Len : Cardinal) : PAnsiChar;
{-Return the mid part of a string}
function CopyRightZ(Dest, S : PAnsiChar; First : Cardinal) : PAnsiChar;
{-Return the right Len characters of a string}
function CopyRightAbsZ(Dest, S : PAnsiChar; NumChars : Cardinal) : PAnsiChar;
{-Return the right Len characters of a string}
function CopyWithinZ(Dest, S, Delimiter : PAnsiChar;
Strip : Boolean) : PAnsiChar;
function DeleteFromNthWordZ(Dest, S, WordDelims, AWord : PAnsiChar;
N : Cardinal) : Boolean;
function DeleteFromToWordZ(Dest, S, WordDelims, Word1, Word2 : PAnsiChar;
N1, N2 : Cardinal) : Boolean;
function DeleteWithinZ(Dest, S, Delimiter : PAnsiChar) : PAnsiChar;
function ExtractTokensZ(S, Delims : PAnsiChar;
QuoteChar : AnsiChar;
AllowNulls : Boolean;
Tokens : TStrings) : Cardinal;
function IsChAlphaZ(C : AnsiChar) : Boolean;
{-Returns true if Ch is an alpha}
function IsChNumericZ(C : AnsiChar; Numbers : PAnsiChar) : Boolean;
{-Returns true if Ch in numeric set}
function IsChAlphaNumericZ(C : AnsiChar; Numbers : PAnsiChar) : Boolean;
{-Returns true if Ch is an alpha or numeric}
function IsStrAlphaZ(S : PAnsiChar) : Boolean;
{-Returns true if all characters in string are an alpha}
function IsStrNumericZ(S, Numbers : PAnsiChar) : Boolean;
{-Returns true if all characters in string are in numeric set}
function IsStrAlphaNumericZ(S, Numbers : PAnsiChar) : Boolean;
{-Returns true if all characters in string are alpha or numeric}
function KeepCharsZ(Dest, S, Chars : PAnsiChar) : PAnsiChar;
function LastStringZ(S, AString : PAnsiChar;
var Position : Cardinal) : Boolean;
function LastWordZ(S, WordDelims, AWord : PAnsiChar;
var Position : Cardinal) : Boolean;
function LastWordAbsZ(S, WordDelims : PAnsiChar;
var Position : Cardinal) : Boolean;
function LeftTrimCharsZ(Dest, S, Chars : PAnsiChar) : PAnsiChar;
function RepeatStringZ(Dest, RepeatString : PAnsiChar;
var Repetitions : Cardinal;
MaxLen : Cardinal) : PAnsiChar;
function ReplaceWordZ(Dest, S, WordDelims, OldWord, NewWord : PAnsiChar;
N : Cardinal;
var Replacements : Cardinal) : PAnsiChar;
function ReplaceWordAllZ(Dest, S, WordDelims, OldWord, NewWord : PAnsiChar;
var Replacements : Cardinal) : PAnsiChar;
function ReplaceStringZ(Dest, S, OldString, NewString : PAnsiChar;
N : Cardinal;
var Replacements : Cardinal) : PAnsiChar;
function ReplaceStringAllZ(Dest, S, OldString, NewString : PAnsiChar;
var Replacements : Cardinal) : PAnsiChar;
function RightTrimCharsZ(Dest, S, Chars : PAnsiChar) : PAnsiChar;
function StrWithinZ(S, SearchStr : PAnsiChar;
Start : Cardinal;
var Position : Cardinal) : Boolean;
function TrimCharsZ(Dest, S, Chars : PAnsiChar) : PAnsiChar;
function WordPosZ(S, WordDelims, AWord : PAnsiChar;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -