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 IsSuffix(const Suffix, S: string): boolean;
function RemoveSuffix(const Suffix, 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;
function CheckGetFileDate(const AFileName: string): TDateTime;
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 41).

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

count occurences of AChar in AString

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

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

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

creates a "method pointer"

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

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

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

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

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

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

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

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

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

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

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

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

procedure CopyFile(const SourceFileName, DestinationFileName: string);

This item has no description.

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

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

Is given Prefix a prefix of S. Not case-sensitive.

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

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

function IsSuffix(const Suffix, S: string): boolean;

Is given Suffix a suffix of S. Not case-sensitive.

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

function RemoveSuffix(const Suffix, S: string): string;

If IsSuffix(Suffix, S), then remove the suffix, otherwise return unmodifed S.

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

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

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

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

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

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

function RemoveIndentation(const Code: string): string;

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

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

function CheckGetFileDate(const AFileName: string): TDateTime;

This item has no description.

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

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

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

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

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

Constants

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

This item has no description.

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

WhiteSpaceNotNL = [' ', #9];

Whitespace that is not any part of newline.

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

WhiteSpaceNL = [#10, #13];

Whitespace that is some part of newline.

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

WhiteSpace = WhiteSpaceNotNL + WhiteSpaceNL;

Any whitespace (that may indicate newline or not)

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

FlagStartSigns = ['['];

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

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

FlagEndSigns = [']'];

This item has no description.

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

Authors


Generated by PasDoc 0.17.0.snapshot.