Unit BrookUtils

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Brook framework, Utilities Unit

Copyright (C) 2014 Silvio Clecio

See the file LICENSE.txt, included in this distribution, for details about the copyright.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
record TBrookSettings Stores the Brook configurations.

Functions and Procedures

function BrookStartsChar(const Ch: Char; const S: string): Boolean;
function BrookEndsChar(const Ch: Char; const S: string): Boolean;
procedure BrookExtractPathLevels(S: string; var R: string; out ALvl: string; out AEndDelim: Boolean; const ADelimiter: Char = US);
function BrookGetPathLevel(const APath: string; const AIndex: SizeInt = 0; const ADelimiter: Char = US): string;
function BrookGetPathLevels(const APath: string; const AIndex: SizeInt = 0; const ADelimiter: Char = US): string;
function BrookMatchMethod(const ABrookMethod: TBrookRequestMethod; const AMethod: string): Boolean;
function BrookFileDate(const AFileName: TFileName): TDateTime;
function BrookDumpStack(const AEOL: ShortString = BR): string;
function BrookDumpStackTrace(const AEOL: ShortString = BR): string;
function BrookExcludeTrailingUrlDelimiter(const AUrl: string): string;
function BrookIncludeTrailingUrlDelimiter(const AUrl: string): string;
function BrookExists(const S: string; const AParts: array of string): Boolean; overload;
function BrookExists(const S: string; const AParts: array of string; const AIgnoreCase: Boolean): Boolean; overload;
procedure BrookStringToObject(AObject: TObject; APropInfo: PPropInfo; const AValue: string); overload;
procedure BrookStringToObject(AObject: TObject; const AName, AValue: string); overload;
procedure BrookSafeStringToObject(AObject: TObject; const AName, AValue: string);
procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings); overload;
procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;
procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;
procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings); overload;
procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;
procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;
procedure BrookObjectToString(AObject: TObject; APropInfo: PPropInfo; out AValue: string); overload;
procedure BrookObjectToString(AObject: TObject; const AName: string; out AValue: string); overload;
procedure BrookSafeObjectToString(AObject: TObject; const AName: string; out AValue: string);
procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings); overload;
procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;
procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;
procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings); overload;
procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;
procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;
procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject); overload;
procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;
procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;
procedure BrookCopyObject(AFrom, ATo: TObject); overload;
procedure BrookCopyObject(AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;
procedure BrookCopyObject(AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;
procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject); overload;
procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;
procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;
procedure BrookSafeCopyObject(AFrom, ATo: TObject); overload;
procedure BrookSafeCopyObject(AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;
procedure BrookSafeCopyObject(AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;

Types

TBrookArrayOfString = array of string;
TBrookRequestMethod = (...);

Variables

BrookSettings: TBrookSettings = ( Mapped: False; Charset: BROOK_HTTP_CHARSET_UTF_8; ContentType: BROOK_HTTP_CONTENT_TYPE_TEXT_HTML; Page404: BROOK_HTTP_RESPONSE_TEMPLATE_NOT_FOUND; Page404File: ES; Page500: BROOK_HTTP_RESPONSE_TEMPLATE_INTERNAL_SERVER_ERROR; Page500File: ES; DirectoryForUploads: ES; DeleteUploadedFiles: False; KeepUploadedNames: True; AcceptsJSONContent: False; Configuration: ES; RootUrl: ES; Port: 0; OnError: nil; );

Description

Functions and Procedures

function BrookStartsChar(const Ch: Char; const S: string): Boolean;

Check whether a string starts with a given character.

function BrookEndsChar(const Ch: Char; const S: string): Boolean;

Check whether a string ends with a given character.

procedure BrookExtractPathLevels(S: string; var R: string; out ALvl: string; out AEndDelim: Boolean; const ADelimiter: Char = US);

Get the next pathinfo level.

function BrookGetPathLevel(const APath: string; const AIndex: SizeInt = 0; const ADelimiter: Char = US): string;

Get the path level passing the respective index. Exemple:

BrookGetPathLavel('/a/b/c/', 1) = b.

function BrookGetPathLevels(const APath: string; const AIndex: SizeInt = 0; const ADelimiter: Char = US): string;

Get the path from the level correspondent to the index to the last level. Exemple:

BrookGetPathLevels('/a/b/c/', 1) = b/c/.

function BrookMatchMethod(const ABrookMethod: TBrookRequestMethod; const AMethod: string): Boolean;

Checks if a string is equivalent an enumerator representing a HTTP request method.

function BrookFileDate(const AFileName: TFileName): TDateTime;

Get the datetime of a file.

function BrookDumpStack(const AEOL: ShortString = BR): string;

Writes a backtrace of the current exception.

function BrookDumpStackTrace(const AEOL: ShortString = BR): string;

Writes a stack trace of the current exception.

function BrookExcludeTrailingUrlDelimiter(const AUrl: string): string;

Ensures Url ends without delimiter.

function BrookIncludeTrailingUrlDelimiter(const AUrl: string): string;

Ensures Url ends with delimiter.

function BrookExists(const S: string; const AParts: array of string): Boolean; overload;

Checks if a string exists in an array of strings.

function BrookExists(const S: string; const AParts: array of string; const AIgnoreCase: Boolean): Boolean; overload;

Checks (ignoring case) if a string exists in an array of strings.

procedure BrookStringToObject(AObject: TObject; APropInfo: PPropInfo; const AValue: string); overload;

Fills a published property of an object passing the property as PPropInfo and value as string.

procedure BrookStringToObject(AObject: TObject; const AName, AValue: string); overload;

Fills a published property of an object passing the name and value as string.

procedure BrookSafeStringToObject(AObject: TObject; const AName, AValue: string);

Fills a published property of an object passing the name and value as string and checking the params.

procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings); overload;

Fills the published properties of an object passing the names and values as a list of strings.

procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;

Fills the published properties of an object passing the names and values as a list of strings. Allows to ignore properties via an array of strings.

procedure BrookStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;

Fills the published properties of an object passing the names and values as a list of strings. Allows to ignore properties via a list of strings.

procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings); overload;

Fills the published properties of an object passing the names and values as a list of strings and checking the params.

procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;

Fills the published properties of an object passing the names and values as a list of strings and checking the params. Allows to ignore properties via an array of strings.

procedure BrookSafeStringsToObject(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;

Fills the published properties of an object passing the names and values as a list of strings and checking the params. Allows to ignore properties via a list of strings.

procedure BrookObjectToString(AObject: TObject; APropInfo: PPropInfo; out AValue: string); overload;

Reads a published property of an object passing the property as PPropInfo and getting the value as string.

procedure BrookObjectToString(AObject: TObject; const AName: string; out AValue: string); overload;

Reads a published property of an object passing the name as string and getting the value as string.

procedure BrookSafeObjectToString(AObject: TObject; const AName: string; out AValue: string);

Reads a published property of an object passing the name, getting the value as string and checking the params.

procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings); overload;

Reads the published properties of an object getting the names and values as a list of strings.

procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;

Reads the published properties of an object getting the names and values as a list of strings. Allows to ignore properties via an array of strings.

procedure BrookObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;

Reads the published properties of an object getting the names and values as a list of strings. Allows to ignore properties via a list of strings.

procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings); overload;

Reads the published properties of an object getting the names and values as a list of strings and checking the params.

procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: array of string); overload;

Reads the published properties of an object getting the names and values as a list of strings and checking the params. Allows to ignore properties via an array of strings.

procedure BrookSafeObjectToStrings(AObject: TObject; AStrings: TStrings; const AIgnoredProps: TStrings); overload;

Reads the published properties of an object getting the names and values as a list of strings and checking the params.

procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count.

procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count. Allows to ignore properties via an array of strings.

procedure BrookCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count. Allows to ignore properties via a list of strings.

procedure BrookCopyObject(AFrom, ATo: TObject); overload;

Copies the value of all properties from one object to another.

procedure BrookCopyObject(AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;

Copies the value of all properties from one object to another. Allows to ignore properties via an array of strings.

procedure BrookCopyObject(AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;

Copies the value of all properties from one object to another. Allows to ignore properties via a list of strings.

procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count and checking the params.

procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count and checking the params. Allows to ignore properties via an array of strings.

procedure BrookSafeCopyObject(APropList: PPropList; const APropCount: Integer; AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;

Copies the value of all properties from one object to another passing the prop. list and prop. count and checking the params. Allows to ignore properties via a list of strings.

procedure BrookSafeCopyObject(AFrom, ATo: TObject); overload;

Copies the value of all properties from one object to another and checking the params.

procedure BrookSafeCopyObject(AFrom, ATo: TObject; const AIgnoredProps: array of string); overload;

Copies the value of all properties from one object to another and checking the params. Allows to ignore properties via an array of strings.

procedure BrookSafeCopyObject(AFrom, ATo: TObject; const AIgnoredProps: TStrings); overload;

Copies the value of all properties from one object to another and checking the params. Allows to ignore properties via a list of strings.

Types

TBrookArrayOfString = array of string;

Defines an array of strings.

TBrookRequestMethod = (...);

Defines an enumerator to represent the HTTP request methods.

Values
  • rmUnknown:  
  • rmAll:  
  • rmGet:  
  • rmPost:  
  • rmPut:  
  • rmDelete:  
  • rmHead:  
  • rmOptions:  
  • rmTrace:  

Variables

BrookSettings: TBrookSettings = ( Mapped: False; Charset: BROOK_HTTP_CHARSET_UTF_8; ContentType: BROOK_HTTP_CONTENT_TYPE_TEXT_HTML; Page404: BROOK_HTTP_RESPONSE_TEMPLATE_NOT_FOUND; Page404File: ES; Page500: BROOK_HTTP_RESPONSE_TEMPLATE_INTERNAL_SERVER_ERROR; Page500File: ES; DirectoryForUploads: ES; DeleteUploadedFiles: False; KeepUploadedNames: True; AcceptsJSONContent: False; Configuration: ES; RootUrl: ES; Port: 0; OnError: nil; );

Global variable to store Brook settings.