Unit PasDoc_Utils

Description

Utility functions.

Source: source/component/PasDoc_Utils.pas (line 29).

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;
procedure SkipBOM(const InputStream: TStream);
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; const ReplacementChar: Char): string; overload;
function SCharsReplace(const S: String; const SearchChar: Char; const ReplacementChar: Char): string; overload;
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;
function IsCharInSet(C: WideChar; const CharSet: TCharSet): Boolean; overload;
function IsUtf8LeadByte(const B: Byte): Boolean;
function IsUtf8TrailByte(const B: Byte): Boolean;
function Utf8Size(const LeadByte: Byte): Integer;
function IsLeadChar(Ch: WideChar): Boolean; overload;
function StripHtml(const S: string): string;
function SAppendPart(const s, PartSeparator, NextPart: String): String;
function CharsPos(const Chars: TCharSet; const S: String): Integer;
function SRemoveChars(const S: string; const Chars: TCharSet): 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

Source: source/component/PasDoc_Utils.pas (line 67).

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

count occurences of AChar in AString

Source: source/component/PasDoc_Utils.pas (line 69).

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

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

Source: source/component/PasDoc_Utils.pas (line 71).

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

creates a "method pointer"

Source: source/component/PasDoc_Utils.pas (line 73).

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

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

Source: source/component/PasDoc_Utils.pas (line 99).

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

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

Source: source/component/PasDoc_Utils.pas (line 103).

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

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

Source: source/component/PasDoc_Utils.pas (line 105).

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.

Source: source/component/PasDoc_Utils.pas (line 118).

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.

Source: source/component/PasDoc_Utils.pas (line 127).

procedure SkipBOM(const InputStream: TStream);

Interpret and skip the BOM in the InputStream. Assumes that initial position is at the beginning of the InputStream, and will change the position to the one immediately after BOM (or 0, if no BOM was detected).

Exceptions raised
EPasDoc
When BOM indicates UTF encoding that we cannot handle (UTF-32, UTF-16 now).

Source: source/component/PasDoc_Utils.pas (line 152).

function FileToString(const FileName: string): string;

Read the given FileName contents into a String. Use this only with text files – it does automatic UTF BOM skipping, so it assumes it is a text file, not a binary file with random contents.

Source: source/component/PasDoc_Utils.pas (line 158).

procedure StringToFile(const FileName, S: string);

Save the String content into a file. Overwrites the FileName, if it already exists.

Source: source/component/PasDoc_Utils.pas (line 162).

procedure DataToFile(const FileName: string; const Data: array of Byte);

Save the binary Data into a file. Overwrites the FileName, if it already exists.

Source: source/component/PasDoc_Utils.pas (line 166).

function SCharsReplace(const S: String; const Chars: TCharSet; const ReplacementChar: Char): string; overload;

Returns S with all Chars replaced by ReplacementChar

Source: source/component/PasDoc_Utils.pas (line 169).

function SCharsReplace(const S: String; const SearchChar: Char; const ReplacementChar: Char): string; overload;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 171).

procedure CopyFile(const SourceFileName, DestinationFileName: string);

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 174).

function IsPrefix(const Prefix, S: string): boolean;

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

Source: source/component/PasDoc_Utils.pas (line 190).

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

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

Source: source/component/PasDoc_Utils.pas (line 193).

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).

Source: source/component/PasDoc_Utils.pas (line 206).

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.

Source: source/component/PasDoc_Utils.pas (line 221).

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.

Source: source/component/PasDoc_Utils.pas (line 227).

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.

Source: source/component/PasDoc_Utils.pas (line 235).

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.

Source: source/component/PasDoc_Utils.pas (line 241).

function RemoveIndentation(const Code: string): string;

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

Source: source/component/PasDoc_Utils.pas (line 244).

procedure Swap16Buf(Src, Dst: PWord; WordCount: Integer);

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 246).

function IsCharInSet(C: AnsiChar; const CharSet: TCharSet): Boolean; overload;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 247).

function IsCharInSet(C: WideChar; const CharSet: TCharSet): Boolean; overload;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 249).

function IsUtf8LeadByte(const B: Byte): Boolean;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 251).

function IsUtf8TrailByte(const B: Byte): Boolean;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 252).

function Utf8Size(const LeadByte: Byte): Integer;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 253).

function IsLeadChar(Ch: WideChar): Boolean; overload;

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 255).

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.

Source: source/component/PasDoc_Utils.pas (line 284).

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

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

Source: source/component/PasDoc_Utils.pas (line 293).

function CharsPos(const Chars: TCharSet; const S: String): Integer;

Find first occurrence of any character in Chars in string S. This is quite like FirstDelimiter but it takes parameter as TSetOfChars and has more sensible name. Returns 0 if not found.

Source: source/component/PasDoc_Utils.pas (line 299).

function SRemoveChars(const S: string; const Chars: TCharSet): string;

Remove all instances of a character in Chars from a string.

Source: source/component/PasDoc_Utils.pas (line 302).

Constants

AllChars = [Low(AnsiChar)..High(AnsiChar)];

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 131).

WhiteSpaceNotNL = [' ', #9];

Whitespace that is not any part of newline.

Source: source/component/PasDoc_Utils.pas (line 134).

WhiteSpaceNL = [#10, #13];

Whitespace that is some part of newline.

Source: source/component/PasDoc_Utils.pas (line 136).

WhiteSpace = WhiteSpaceNotNL + WhiteSpaceNL;

Any whitespace (that may indicate newline or not)

Source: source/component/PasDoc_Utils.pas (line 138).

FlagStartSigns = ['['];

Flag Start- and Endsigns for parameters (Feature request "direction of parameter": pasdoc issue 8)

Source: source/component/PasDoc_Utils.pas (line 142).

FlagEndSigns = [']'];

This item has no description.

Source: source/component/PasDoc_Utils.pas (line 143).

Authors


Generated by PasDoc 0.17.0.snapshot.