Unit PasDoc_Utils

Description

Utility functions.

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TCharReplacement  

Functions and Procedures

function IsStrEmptyA(const AString: string): boolean;
function StrCountCharA(const AString: string; const AChar: Char): Integer;
function StrPosIA(const ASub, AString: string): Integer;
function MakeMethod(const AObject: Pointer; AMethod: Pointer): TMethod;
function StringReplaceChars(const S: string; const ReplacementArray: array of TCharReplacement): string;
function SCharIs(const S: string; Index: integer; C: char): boolean; overload;
function SCharIs(const S: string; Index: integer; const Chars: TCharSet): boolean; overload;
function ExtractFirstWord(var s: string): string; overload;
procedure ExtractFirstWord(const S: string; out FirstWord, Rest: string); overload;
function FileToString(const FileName: string): string;
procedure StringToFile(const FileName, S: string);
procedure DataToFile(const FileName: string; const Data: array of Byte);
function SCharsReplace(const S: string; const Chars: TCharSet; ReplacementChar: char): string;
procedure CopyFile(const SourceFileName, DestinationFileName: string);
function IsPrefix(const Prefix, S: string): boolean;
function RemovePrefix(const Prefix, S: string): string;
function SEnding(const s: string; P: integer): string;
function IsPathAbsolute(const Path: string): boolean;
function IsPathAbsoluteOnDrive(const Path: string): boolean;
function CombinePaths(BasePath, RelPath: string): string;
function DeleteFileExt(const FileName: string): string;
function RemoveIndentation(const Code: string): string;
procedure Swap16Buf(Src, Dst: PWord; WordCount: Integer);
function IsCharInSet(C: AnsiChar; const CharSet: TCharSet): Boolean; overload; inline;
function IsCharInSet(C: WideChar; const CharSet: TCharSet): Boolean; overload; inline;
function IsUtf8LeadByte(const B: Byte): Boolean; inline;
function IsUtf8TrailByte(const B: Byte): Boolean; inline;
function Utf8Size(const LeadByte: Byte): Integer; inline;
function IsLeadChar(Ch: WideChar): Boolean; overload; inline;
function StripHtml(const S: string): string;
function SAppendPart(const s, PartSeparator, NextPart: String): String;

Constants

AllChars = [Low(AnsiChar)..High(AnsiChar)];
WhiteSpaceNotNL = [' ', #9];
WhiteSpaceNL = [#10, #13];
WhiteSpace = WhiteSpaceNotNL + WhiteSpaceNL;
FlagStartSigns = ['['];
FlagEndSigns = [']'];

Description

Functions and Procedures

function IsStrEmptyA(const AString: string): boolean;

string empty means it contains only whitespace

function StrCountCharA(const AString: string; const AChar: Char): Integer;

count occurences of AChar in AString

function StrPosIA(const ASub, AString: string): Integer;

Position of the ASub in AString. Return 0 if not found

function MakeMethod(const AObject: Pointer; AMethod: Pointer): TMethod;

creates a "method pointer"

function StringReplaceChars(const S: string; const ReplacementArray: array of TCharReplacement): string;

Returns S with each char from ReplacementArray[].cChar replaced with ReplacementArray[].sSpec.

function SCharIs(const S: string; Index: integer; C: char): boolean; overload;

Comfortable shortcut for Index <= Length(S) and S[Index] = C.

function SCharIs(const S: string; Index: integer; const Chars: TCharSet): boolean; overload;

Comfortable shortcut for Index <= Length(S) and S[Index] in Chars.

function ExtractFirstWord(var s: string): string; overload;

Extracts all characters up to the first white-space encountered (ignoring white-space at the very beginning of the string) from the string specified by S.

If there is no white-space in S (or there is white-space only at the beginning of S, in which case it is ignored) then the whole S is regarded as it's first word.

Both S and result are trimmed, i.e. they don't have any excessive white-space at the beginning or end.

procedure ExtractFirstWord(const S: string; out FirstWord, Rest: string); overload;

Another version of ExtractFirstWord.

Splits S by it's first white-space (ignoring white-space at the very beginning of the string). No such white-space means that whole S is regarded as the FirstWord.

Both FirstWord and Rest are trimmed.

function FileToString(const FileName: string): string;
 
procedure StringToFile(const FileName, S: string);
 
procedure DataToFile(const FileName: string; const Data: array of Byte);
 
function SCharsReplace(const S: string; const Chars: TCharSet; ReplacementChar: char): string;

Returns S with all Chars replaced by ReplacementChar

procedure CopyFile(const SourceFileName, DestinationFileName: string);
 
function IsPrefix(const Prefix, S: string): boolean;

Checks is Prefix a prefix of S. Not case-sensitive.

function RemovePrefix(const Prefix, S: string): string;

If IsPrefix(Prefix, S), then remove the prefix, otherwise return unmodifed S.

function SEnding(const s: string; P: integer): string;

SEnding returns S contents starting from position P. Returns '' if P > length(S). Yes, this is simply equivalent to Copy(S, P, MaxInt).

function IsPathAbsolute(const Path: string): boolean;

Check is the given Path absolute.

Path may point to directory or normal file, it doesn't matter. Also it doesn't matter whether Path ends with PathDelim or not.

Note for Windows: while it's obvious that 'c:\autoexec.bat' is an absolute path, and 'autoexec.bat' is not, there's a question whether path like '\autoexec.bat' is absolute? It doesn't specify drive letter, but it does specify full directory hierarchy on some drive. This function treats this as not absolute, on the reasoning that "not all information is contained in Path".

See also
IsPathAbsoluteOnDrive
Just like IsPathAbsolute, but on Windows accepts also paths that specify full directory tree without drive letter.
function IsPathAbsoluteOnDrive(const Path: string): boolean;

Just like IsPathAbsolute, but on Windows accepts also paths that specify full directory tree without drive letter.

See also
IsPathAbsolute
Check is the given Path absolute.
function CombinePaths(BasePath, RelPath: string): string;

Combines BasePath with RelPath. BasePath MUST be an absolute path, on Windows it must contain at least drive specifier (like 'c:'), on Unix it must begin with "/". RelPath can be relative and can be absolute. If RelPath is absolute, result is RelPath. Else the result is an absolute path calculated by combining RelPath with BasePath.

function DeleteFileExt(const FileName: string): string;

Remove from the FileName the last extension (including the dot). Note that if the FileName had a couple of extensions (e.g. blah.x3d.gz) this will remove only the last one. Will remove nothing if filename has no extension.

function RemoveIndentation(const Code: string): string;

Remove common indentation (whitespace prefix) from a multiline string.

procedure Swap16Buf(Src, Dst: PWord; WordCount: Integer);
 
function IsCharInSet(C: AnsiChar; const CharSet: TCharSet): Boolean; overload; inline;
 
function IsCharInSet(C: WideChar; const CharSet: TCharSet): Boolean; overload; inline;
 
function IsUtf8LeadByte(const B: Byte): Boolean; inline;
 
function IsUtf8TrailByte(const B: Byte): Boolean; inline;
 
function Utf8Size(const LeadByte: Byte): Integer; inline;
 
function IsLeadChar(Ch: WideChar): Boolean; overload; inline;
 
function StripHtml(const S: string): string;

Strip HTML elements from the string.

Assumes that the HTML content is correct (all elements are nicely closed, all < > inside attributes are escaped to &lt; &gt;, all < > outside elements are escaped to &lt; &gt;). It doesn't try very hard to deal with incorrect HTML context (it will not crash, but results are undefined). It's designed to strip HTML from PasDoc-generated HTML, which should always be correct.

function SAppendPart(const s, PartSeparator, NextPart: String): String;

If S = '' then returns NextPart, else returns S + PartSeparator + NextPart.

Constants

AllChars = [Low(AnsiChar)..High(AnsiChar)];
 
WhiteSpaceNotNL = [' ', #9];

Whitespace that is not any part of newline.

WhiteSpaceNL = [#10, #13];

Whitespace that is some part of newline.

WhiteSpace = WhiteSpaceNotNL + WhiteSpaceNL;

Any whitespace (that may indicate newline or not)

FlagStartSigns = ['['];

Flag Start- and Endsigns for parameters (Feature request "direction of parameter": https://github.com/pasdoc/pasdoc/issues/8)

FlagEndSigns = [']'];
 

Authors


Generated by PasDoc 0.16.0.