Unit bbutils

DescriptionusesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

This unit contains some basic functions missing in fpc


It uses the following naming convention:

All functions starting with str are related to strings and work on ansistring or pchar, so you can use them for latin1 and utf-8.
The prefix strl means the string length is given, str?i means the function is case insensitive


The prefix array means the function works with dynamical arrays.
If the suffix Fast is given, the length of the array is different of the count of contained elements i.e. the standard length is actually a capacity so you can resize it without reallocating the array.
Some array functions have two optional slice parameters: if you give none of them the function will affect the whole array; if you give one of them, the function will affect elements in the inclusive interval [0, slice] and if you give both, it will affect elements in the inclusive interval [slice1, slice2].

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EDateTimeParsingException  

Functions and Procedures

function arrayAdd(var a: TStringArray; const e: string):longint; overload;
function arrayAdd(var a: TStringArray; const a2: TStringArray):longint; overload;
function arrayDelete(var a: TStringArray; const i: longint):string; overload;
procedure arrayReserveFast(var a: TStringArray; const len: longint; const reserveLength: longint);
function arrayAddFast(var a: TStringArray; var len: longint; const e: string): longint;
function arrayDeleteFast(var a: TStringArray; var len: longint; const i: longint):string; overload;
function arrayIndexOf(const a: array of string; const e: string; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfSmallest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfLargest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer;
procedure arrayInvert(a: TStringArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of string; slice1: integer = -1;slice2: integer = -1): TStringArray;
function arrayGet(a: array of string; const i: integer): string;
function arrayLast(a: array of string): string;
function arrayLast(a: array of string; const default: string): string;
function arrayCompare(a, b: array of string; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;
function arrayEqual(a, b: array of string; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;
function arrayAdd(var a: TLongintArray; const e: longint):longint; overload;
function arrayAdd(var a: TLongintArray; const a2: TLongintArray):longint; overload;
function arrayDelete(var a: TLongintArray; const i: longint):longint; overload;
procedure arrayReserveFast(var a: TLongintArray; const len: longint; const reserveLength: longint);
function arrayAddFast(var a: TLongintArray; var len: longint; const e: longint): longint;
function arrayDeleteFast(var a: TLongintArray; var len: longint; const i: longint):longint; overload;
function arrayIndexOf(const a: array of longint; const e: longint; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfSmallest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfLargest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer;
procedure arrayInvert(a: TLongintArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of longint; slice1: integer = -1;slice2: integer = -1): TLongintArray;
function arrayGet(a: array of longint; const i: integer): longint;
function arrayLast(a: array of longint): longint;
function arrayLast(a: array of longint; const default: longint): longint;
function arrayCompare(a, b: array of longint; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;
function arrayEqual(a, b: array of longint; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;
function arrayAdd(var a: TLongwordArray; const e: longword):longint; overload;
function arrayAdd(var a: TLongwordArray; const a2: TLongwordArray):longint; overload;
function arrayDelete(var a: TLongwordArray; const i: longint):longword; overload;
procedure arrayReserveFast(var a: TLongwordArray; const len: longint; const reserveLength: longint);
function arrayAddFast(var a: TLongwordArray; var len: longint; const e: longword): longint;
function arrayDeleteFast(var a: TLongwordArray; var len: longint; const i: longint):longword; overload;
function arrayIndexOf(const a: array of longword; const e: longword; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfSmallest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfLargest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer;
procedure arrayInvert(a: TLongwordArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of longword; slice1: integer = -1;slice2: integer = -1): TLongwordArray;
function arrayGet(a: array of longword; const i: integer): longword;
function arrayLast(a: array of longword): longword;
function arrayLast(a: array of longword; const default: longword): longword;
function arrayCompare(a, b: array of longword; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;
function arrayEqual(a, b: array of longword; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;
function arrayAdd(var a: TInt64Array; const e: int64):longint; overload;
function arrayAdd(var a: TInt64Array; const a2: TInt64Array):longint; overload;
function arrayDelete(var a: TInt64Array; const i: longint):int64; overload;
procedure arrayReserveFast(var a: TInt64Array; const len: longint; const reserveLength: longint);
function arrayAddFast(var a: TInt64Array; var len: longint; const e: int64): longint;
function arrayDeleteFast(var a: TInt64Array; var len: longint; const i: longint):int64; overload;
function arrayIndexOf(const a: array of int64; const e: int64; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfSmallest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfLargest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer;
procedure arrayInvert(a: TInt64Array; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of int64; slice1: integer = -1;slice2: integer = -1): TInt64Array;
function arrayGet(a: array of int64; const i: integer): int64;
function arrayLast(a: array of int64): int64;
function arrayLast(a: array of int64; const default: int64): int64;
function arrayCompare(a, b: array of int64; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;
function arrayEqual(a, b: array of int64; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;
function arrayAdd(var a: TFloatArray; const e: float):longint; overload;
function arrayAdd(var a: TFloatArray; const a2: TFloatArray):longint; overload;
function arrayDelete(var a: TFloatArray; const i: longint):float; overload;
procedure arrayReserveFast(var a: TFloatArray; const len: longint; const reserveLength: longint);
function arrayAddFast(var a: TFloatArray; var len: longint; const e: float): longint;
function arrayDeleteFast(var a: TFloatArray; var len: longint; const i: longint):float; overload;
function arrayIndexOf(const a: array of float; const e: float; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfSmallest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer;
function arrayIndexOfLargest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer;
procedure arrayInvert(a: TFloatArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of float; slice1: integer = -1;slice2: integer = -1): TFloatArray;
function arrayGet(a: array of float; const i: integer): float;
function arrayLast(a: array of float): float;
function arrayLast(a: array of float; const default: float): float;
function arrayCompare(a, b: array of float; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;
function arrayEqual(a, b: array of float; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;
function unequal(const a, b: integer): boolean;
function unequal(const a, b, c: integer): boolean;
function unequal(const a: array of integer): boolean;
function unequal(const a, b: cardinal): boolean;
function unequal(const a, b, c: cardinal): boolean;
function unequal(const a: array of cardinal): boolean;
function unequal(const a, b: string): boolean;
function unequal(const a, b, c: string): boolean;
function unequal(const a: array of string): boolean;
function unequal(const a, b: int64): boolean;
function unequal(const a, b, c: int64): boolean;
function unequal(const a: array of int64): boolean;
function procedureToMethod(proc: TProcedure): TMethod;
procedure threadedCall(proc: TProcedureOfObject; finished: TNotifyEvent); overload;
procedure threadedCall(proc: TProcedureOfObject; finished: TProcedureOfObject); overload;
procedure threadedCall(proc: TProcedure; finished: TProcedureOfObject); overload;
function strlmove(dest,source:pchar;destLen,sourceLen: longint):pchar;
function widestrlmove(dest,source:pwidechar;destLen,sourceLen: longint):pwidechar;
function strCopyFrom(const s:string; start:longint):string; inline;
function strSlice(const first,last:pchar):string;
function strSlice(const s:string; start,last:longint):string;
function strlEqual(p1,p2:pchar;l1,l2: longint):boolean;
function strliEqual(p1,p2:pchar;l1,l2: longint):boolean;
function strlsEqual(p1,p2:pchar;l1,l2: longint):boolean;
function strlsiEqual(p1,p2:pchar;l1,l2: longint):boolean;
function strlEqual(p:pchar;const s:string; l: longint):boolean;
function strliEqual(p:pchar;const s:string;l: longint):boolean;
function strlBeginsWith(const p:pchar; l:longint; const expectedStart:string):boolean;
function strliBeginsWith(const p:pchar;l: longint;const expectedStart:string):boolean; inline;
function strEqual(const s1,s2:string):boolean; inline;
function striEqual(const s1,s2:string):boolean; inline;
function strBeginsWith(const strToBeExaminated,expectedStart:string):boolean;
function striBeginsWith(const strToBeExaminated,expectedStart:string):boolean;
function strBeginsWith(const p:pchar; const expectedStart:string):boolean; inline;
function striBeginsWith(const p:pchar; const expectedStart:string):boolean; inline;
function strEndsWith(const strToBeExaminated,expectedEnd:string):boolean;
function striEndsWith(const strToBeExaminated,expectedEnd:string):boolean;
function strCompareClever(const s1, s2: string): integer;
function striCompareClever(const s1, s2: string): integer; inline;
function strRpos(c:char;s:string):longint;
function strlCount(const search:char; const searchIn:pchar; const len: longint): longint;
function strlsIndexOf(str,searched:pchar; l1, l2: longint): longint;
function strlsiIndexOf(str,searched:pchar; l1, l2: longint): longint;
function strIndexOf(const str,searched:string):longint; inline;
function striIndexOf(const str,searched:string):longint; inline;
function strIndexOf(const str,searched:string; from: longint):longint; inline;
function striIndexOf(const str,searched:string; from: longint):longint; inline;
function strContains(const str,searched:string):boolean; inline;
function striContains(const str,searched:string):boolean; inline;
function strContains(const str,searched:string; from: longint):boolean; inline;
function striContains(const str,searched:string; from: longint):boolean; inline;
procedure strlTrimLeft(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
procedure strlTrimRight(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
procedure strlTrim(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
function strTrimLeft(const s:string; const trimCharacters: TCharSet = [#0..' ']):string; inline;
function strTrimRight(const s:string; const trimCharacters: TCharSet = [#0..' ']):string; inline;
function strTrim(const s: string; const trimCharacters: TCharSet = [#0..' ']):string; inline;
function strTrimAndNormalize(const s: string; const trimCharacters: TCharSet = [#0..' ']):string;
function strSplitGet(const separator: string; var remainingPart: string):string; overload;
procedure strSplit(out firstPart: string; const separator: string; var remainingPart: string); overload;
procedure strSplit(out splitted: TStringArray;s:string;sep:string=',';includeEmpty:boolean=true); overload;
function strSplit(s:string;sep:string=',';includeEmpty:boolean=true):TStringArray; overload;
function strWrapSplit(const Line: string; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): TStringArray;
function strWrap(const Line: string; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): string;
function strSplitGetUntilBracketClosing(var text: string; const openBracket, closingBracket: string; updateText: boolean): string;
function strSplitGetBetweenBrackets(var text: string; const openBracket, closingBracket: string; updateText: boolean): string;
function strJoin(const sl: TStrings; const sep: string = ', '; limit: Integer=0; const limitStr: string='...'): string; overload;
function strJoin(const sl: TStringArray; const sep: string = ', '; limit: Integer=0; const limitStr: string='...'): string; overload;
function StrToBoolDef(const S: string;const Def:Boolean): Boolean;
function strLoadFromFile(filename:string):string;
procedure strSaveToFile(filename: string;str:string);
function strLoadFromFileUTF8(filename:string):string;
procedure strSaveToFileUTF8(filename: string;str:string);
function strFromSIze(size: int64):string;
function strLengthUtf8(str: string): longint;
function strConvertToUtf8(str: string; from: TEncoding): string;
function strConvertFromUtf8(const str: string; toe: TEncoding): string;
function strChangeEncoding(const str: string; from,toe: TEncoding):string;
function strGetUnicodeCharacter(const character: integer; encoding: TEncoding = eUTF8): string;
function strDecodeUTF8Character(const str: string; var curpos: integer): integer;
function strEncodingFromName(str:string):TEncoding;
function strDecodeHTMLEntities(p:pchar;l:longint;encoding:TEncoding; strict: boolean = false):string;
function strDecodeHTMLEntities(s:string;encoding:TEncoding; strict: boolean = false):string;
function strEscape(const s:string; const toEscape: TCharSet; escapeChar: char = '\'): string;
function strEscapeRegex(const s:string): string;
function strDecodeHex(const s:string):string;
function strEncodeHex(const s:string; const code: string = '0123456789ABCDEF'):string;
function strFromPchar(p:pchar;l:longint):string;
function strFromPtr(p: pointer): string;
function strFromInt(i: int64; displayLength: longint): string;
function strDup(const rep: string; const count: integer): string;
function intLog10(i:longint):longint; overload;
function intLog(n,b: longint): longint; overload;
procedure intFactor(n,p: longint; out e, r:longint);
function gcd(a,b: cardinal): cardinal;
function coprime(a,b:cardinal): boolean;
function modPow(i, e, m: longint): longint;
function intBound(min, i, max: longint): longint;
function modPow(i, e, m: int64): int64;
function intBound(min, i, max: int64): int64;
function factorial(i:longint):float;
function binomial(n,k: longint): float;
function binomialExpectation(n:longint;p:float):float;
function binomialVariance(n:longint;p:float):float;
function binomialDeviation(n:longint;p:float):float;
function binomialProbability(n:longint;p:float;k:longint):float;
function binomialProbabilityGE(n:longint;p:float;k:longint):float;
function binomialProbabilityLE(n:longint;p:float;k:longint):float;
function binomialProbabilityDeviationOf(n:longint;p:float;dif:float):float;
function binomialProbabilityApprox(n:longint;p:float;k:longint):float;
function binomialZScore(n:longint;p:float;k:longint):float;
procedure intSieveEulerPhi(n: integer; var totient: TLongintArray);
procedure intSieveDivisorCount(n: integer; var divcount: TLongintArray);
function dateWeekOfYear(const date:TDateTime):word;
function dateIsLeapYear(const year: integer): boolean; inline;
function dateTimeParsePartsTry(const input,mask:string; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil): boolean;
procedure dateTimeParseParts(const input,mask:string; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
function dateTimeFormat(const mask: string; y, m,d, h, n, s: Integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): string;
function dateTimeFormat(const mask: string; const dateTime: TDateTime): string;
function dateTimeEncode(const y,m,d,h,n,s:integer; const secondFraction: double = 0): TDateTime;
procedure timeParseParts(const input,mask:string; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
function timeParse(const input,mask:string): TTime;
function timeFormat(const mask: string; const h, n, s: integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): string;
procedure dateParseParts(const input,mask:string; outYear, outMonth, outDay: PInteger; outtimezone: PDateTime = nil);
function dateParse(const input,mask:string): longint;
function dateFormat(const mask: string; const y, m, d: integer; const timezone: TDateTime = nan): string;
function dateEncodeTry(year, month, day: integer; out dt: TDateTime): boolean;
function dateEncode(year, month, day: integer): TDateTime;
procedure dateDecode(date: TDateTime; year, month, day: PInteger);
procedure stableSort(a,b: pointer; size: longint; compareFunction: TPointerCompareFunction = nil; compareFunctionData: TObject=nil);
procedure stableSort(intArray: TLongintArray; compareFunction: TPointerCompareFunction; compareFunctionData: TObject=nil);

Types

TStringArray=array of string;
TLongintArray =array of longint;
TLongwordArray =array of longword;
TInt64Array =array of int64;
TFloatArray =array of float;
TProcedureOfObject = procedure () of object;
TEncoding = (...);
TCharSet = set of char;
TPointerCompareFunction = function (data: TObject; a, b: pointer): longint;

Constants

powersOf10: array[0..10] of longint = (1,10,100,1000,10000,100000,1000000,1000000,10000000,100000000,1000000000);
DateMonthDaysCumSum: array[false..true,0..12] of Cardinal = ((00, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365), (00, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366));
WHITE_SPACE=[#9,#10,#13,' '];

Description

Functions and Procedures

function arrayAdd(var a: TStringArray; const e: string):longint; overload;

Adds element e to array a. Returns i with a[i]=e

function arrayAdd(var a: TStringArray; const a2: TStringArray):longint; overload;

Adds elements from a2 e to array a. Returns the OLD length of a

function arrayDelete(var a: TStringArray; const i: longint):string; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

procedure arrayReserveFast(var a: TStringArray; const len: longint; const reserveLength: longint);

Ensures that a has at least reserveLength elements

function arrayAddFast(var a: TStringArray; var len: longint; const e: string): longint;

returns i with a[i]=e

function arrayDeleteFast(var a: TStringArray; var len: longint; const i: longint):string; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

function arrayIndexOf(const a: array of string; const e: string; slice1: integer = -1; slice2: integer = -1): integer;

Find element e in the array/slice (see above)

function arrayIndexOfSmallest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer;

Find the smallest element, in the array/slice (see above)

function arrayIndexOfLargest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer;

Find the largest element in the array/slice (see above)

procedure arrayInvert(a: TStringArray; slice1: integer = -1;slice2: integer = -1); overload;

Inverts the order of the elements in the array/slice (see above)

function arraySlice(a: array of string; slice1: integer = -1;slice2: integer = -1): TStringArray;

Extracts a array slice

function arrayGet(a: array of string; const i: integer): string;

Returns the i-th element of the array. If i < 0, the indices are taken from the end of the array. (which is actually the only use case)

function arrayLast(a: array of string): string;

Returns the last element of the array, raises exception, iff the array is empty

function arrayLast(a: array of string; const default: string): string;

Returns the last element of the array, returns default, iff the array is empty

function arrayCompare(a, b: array of string; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;

Compares two array/slices (interleaved slice parameters, so arrayEqual(a,b,3,3) compares the first 3 elements)

function arrayEqual(a, b: array of string; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;

Tests if two array/slices are equal (interleaved slice parameters, so arrayEqual(a,b,3,3) tests the first 3 elements)

function arrayAdd(var a: TLongintArray; const e: longint):longint; overload;

Adds element e to array a. Returns i with a[i]=e

function arrayAdd(var a: TLongintArray; const a2: TLongintArray):longint; overload;

Adds elements from a2 e to array a. Returns the OLD length of a

function arrayDelete(var a: TLongintArray; const i: longint):longint; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

procedure arrayReserveFast(var a: TLongintArray; const len: longint; const reserveLength: longint);

Ensures that a has at least reserveLength elements

function arrayAddFast(var a: TLongintArray; var len: longint; const e: longint): longint;

returns i with a[i]=e

function arrayDeleteFast(var a: TLongintArray; var len: longint; const i: longint):longint; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

function arrayIndexOf(const a: array of longint; const e: longint; slice1: integer = -1; slice2: integer = -1): integer;

Find element e in the array/slice (see above)

function arrayIndexOfSmallest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer;

Find the smallest element, in the array/slice (see above)

function arrayIndexOfLargest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer;

Find the largest element in the array/slice (see above)

procedure arrayInvert(a: TLongintArray; slice1: integer = -1;slice2: integer = -1); overload;

Inverts the order of the elements in the array/slice (see above)

function arraySlice(a: array of longint; slice1: integer = -1;slice2: integer = -1): TLongintArray;

Extracts a array slice

function arrayGet(a: array of longint; const i: integer): longint;

Returns the i-th element of the array. If i < 0, the indices are taken from the end of the array. (which is actually the only use case)

function arrayLast(a: array of longint): longint;

Returns the last element of the array, raises exception, iff the array is empty

function arrayLast(a: array of longint; const default: longint): longint;

Returns the last element of the array, returns default, iff the array is empty

function arrayCompare(a, b: array of longint; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;

Compares two array/slices (interleaved slice parameters, so arrayEqual(a,b,3,3) compares the first 3 elements)

function arrayEqual(a, b: array of longint; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;

Tests if two array/slices are equal (interleaved slice parameters, so arrayEqual(a,b,3,3) tests the first 3 elements)

function arrayAdd(var a: TLongwordArray; const e: longword):longint; overload;

Adds element e to array a. Returns i with a[i]=e

function arrayAdd(var a: TLongwordArray; const a2: TLongwordArray):longint; overload;

Adds elements from a2 e to array a. Returns the OLD length of a

function arrayDelete(var a: TLongwordArray; const i: longint):longword; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

procedure arrayReserveFast(var a: TLongwordArray; const len: longint; const reserveLength: longint);

Ensures that a has at least reserveLength elements

function arrayAddFast(var a: TLongwordArray; var len: longint; const e: longword): longint;

returns i with a[i]=e

function arrayDeleteFast(var a: TLongwordArray; var len: longint; const i: longint):longword; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

function arrayIndexOf(const a: array of longword; const e: longword; slice1: integer = -1; slice2: integer = -1): integer;

Find element e in the array/slice (see above)

function arrayIndexOfSmallest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer;

Find the smallest element, in the array/slice (see above)

function arrayIndexOfLargest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer;

Find the largest element in the array/slice (see above)

procedure arrayInvert(a: TLongwordArray; slice1: integer = -1;slice2: integer = -1); overload;

Inverts the order of the elements in the array/slice (see above)

function arraySlice(a: array of longword; slice1: integer = -1;slice2: integer = -1): TLongwordArray;

Extracts a array slice

function arrayGet(a: array of longword; const i: integer): longword;

Returns the i-th element of the array. If i < 0, the indices are taken from the end of the array. (which is actually the only use case)

function arrayLast(a: array of longword): longword;

Returns the last element of the array, raises exception, iff the array is empty

function arrayLast(a: array of longword; const default: longword): longword;

Returns the last element of the array, returns default, iff the array is empty

function arrayCompare(a, b: array of longword; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;

Compares two array/slices (interleaved slice parameters, so arrayEqual(a,b,3,3) compares the first 3 elements)

function arrayEqual(a, b: array of longword; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;

Tests if two array/slices are equal (interleaved slice parameters, so arrayEqual(a,b,3,3) tests the first 3 elements)

function arrayAdd(var a: TInt64Array; const e: int64):longint; overload;

Adds element e to array a. Returns i with a[i]=e

function arrayAdd(var a: TInt64Array; const a2: TInt64Array):longint; overload;

Adds elements from a2 e to array a. Returns the OLD length of a

function arrayDelete(var a: TInt64Array; const i: longint):int64; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

procedure arrayReserveFast(var a: TInt64Array; const len: longint; const reserveLength: longint);

Ensures that a has at least reserveLength elements

function arrayAddFast(var a: TInt64Array; var len: longint; const e: int64): longint;

returns i with a[i]=e

function arrayDeleteFast(var a: TInt64Array; var len: longint; const i: longint):int64; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

function arrayIndexOf(const a: array of int64; const e: int64; slice1: integer = -1; slice2: integer = -1): integer;

Find element e in the array/slice (see above)

function arrayIndexOfSmallest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer;

Find the smallest element, in the array/slice (see above)

function arrayIndexOfLargest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer;

Find the largest element in the array/slice (see above)

procedure arrayInvert(a: TInt64Array; slice1: integer = -1;slice2: integer = -1); overload;

Inverts the order of the elements in the array/slice (see above)

function arraySlice(a: array of int64; slice1: integer = -1;slice2: integer = -1): TInt64Array;

Extracts a array slice

function arrayGet(a: array of int64; const i: integer): int64;

Returns the i-th element of the array. If i < 0, the indices are taken from the end of the array. (which is actually the only use case)

function arrayLast(a: array of int64): int64;

Returns the last element of the array, raises exception, iff the array is empty

function arrayLast(a: array of int64; const default: int64): int64;

Returns the last element of the array, returns default, iff the array is empty

function arrayCompare(a, b: array of int64; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;

Compares two array/slices (interleaved slice parameters, so arrayEqual(a,b,3,3) compares the first 3 elements)

function arrayEqual(a, b: array of int64; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;

Tests if two array/slices are equal (interleaved slice parameters, so arrayEqual(a,b,3,3) tests the first 3 elements)

function arrayAdd(var a: TFloatArray; const e: float):longint; overload;

Adds element e to array a. Returns i with a[i]=e

function arrayAdd(var a: TFloatArray; const a2: TFloatArray):longint; overload;

Adds elements from a2 e to array a. Returns the OLD length of a

function arrayDelete(var a: TFloatArray; const i: longint):float; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

procedure arrayReserveFast(var a: TFloatArray; const len: longint; const reserveLength: longint);

Ensures that a has at least reserveLength elements

function arrayAddFast(var a: TFloatArray; var len: longint; const e: float): longint;

returns i with a[i]=e

function arrayDeleteFast(var a: TFloatArray; var len: longint; const i: longint):float; overload;

Removes element at position i from a (destroying the order of the elements)
Returns e=a[i]

function arrayIndexOf(const a: array of float; const e: float; slice1: integer = -1; slice2: integer = -1): integer;

Find element e in the array/slice (see above)

function arrayIndexOfSmallest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer;

Find the smallest element, in the array/slice (see above)

function arrayIndexOfLargest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer;

Find the largest element in the array/slice (see above)

procedure arrayInvert(a: TFloatArray; slice1: integer = -1;slice2: integer = -1); overload;

Inverts the order of the elements in the array/slice (see above)

function arraySlice(a: array of float; slice1: integer = -1;slice2: integer = -1): TFloatArray;

Extracts a array slice

function arrayGet(a: array of float; const i: integer): float;

Returns the i-th element of the array. If i < 0, the indices are taken from the end of the array. (which is actually the only use case)

function arrayLast(a: array of float): float;

Returns the last element of the array, raises exception, iff the array is empty

function arrayLast(a: array of float; const default: float): float;

Returns the last element of the array, returns default, iff the array is empty

function arrayCompare(a, b: array of float; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): longint; overload;

Compares two array/slices (interleaved slice parameters, so arrayEqual(a,b,3,3) compares the first 3 elements)

function arrayEqual(a, b: array of float; slice1a: integer = -1; slice1b: integer = -1; slice2a: integer = -1; slice2b: integer = -1): boolean; overload;

Tests if two array/slices are equal (interleaved slice parameters, so arrayEqual(a,b,3,3) tests the first 3 elements)

function unequal(const a, b: integer): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b, c: integer): boolean;

Checks if all elements are pairwise unequal

function unequal(const a: array of integer): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b: cardinal): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b, c: cardinal): boolean;

Checks if all elements are pairwise unequal

function unequal(const a: array of cardinal): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b: string): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b, c: string): boolean;

Checks if all elements are pairwise unequal

function unequal(const a: array of string): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b: int64): boolean;

Checks if all elements are pairwise unequal

function unequal(const a, b, c: int64): boolean;

Checks if all elements are pairwise unequal

function unequal(const a: array of int64): boolean;

Checks if all elements are pairwise unequal

function procedureToMethod(proc: TProcedure): TMethod;
 
procedure threadedCall(proc: TProcedureOfObject; finished: TNotifyEvent); overload;

Calls proc in an new thread

procedure threadedCall(proc: TProcedureOfObject; finished: TProcedureOfObject); overload;

Calls proc in an new thread

procedure threadedCall(proc: TProcedure; finished: TProcedureOfObject); overload;

Calls proc in an new thread

function strlmove(dest,source:pchar;destLen,sourceLen: longint):pchar;

Copies min(sourceLen, destLen) characters from source to dest and returns dest

function widestrlmove(dest,source:pwidechar;destLen,sourceLen: longint):pwidechar;

Copies min(sourceLen, destLen) characters from source to dest and returns dest

function strCopyFrom(const s:string; start:longint):string; inline;

Returns the substring of s containing all characters after start (including s[start]

function strSlice(const first,last:pchar):string;

Returns a string with all characters between first and last (including first, last)

function strSlice(const s:string; start,last:longint):string;

Returns a string with all characters between start and last (including start, last)

function strlEqual(p1,p2:pchar;l1,l2: longint):boolean;

Tests if the strings are case-sensitive equal (same length and same characters) (null-terminated, stops comparison when meeting #0 )

function strliEqual(p1,p2:pchar;l1,l2: longint):boolean;

Tests if the strings are case-insensitive equal (same length and same characters) (null-terminated, stops comparison when meeting #0 )

function strlsEqual(p1,p2:pchar;l1,l2: longint):boolean;

Tests if the strings are case-sensitive equal (same length and same characters) (strict-length, can continue comparison after #0)

function strlsiEqual(p1,p2:pchar;l1,l2: longint):boolean;

Tests if the strings are case-insensitive equal (same length and same characters) (strict-length, can continue comparison after #0)

function strlEqual(p:pchar;const s:string; l: longint):boolean;

Tests if the strings are case-sensitive equal (same length and same characters)

function strliEqual(p:pchar;const s:string;l: longint):boolean;

Tests if the strings are case-insensitive equal (same length and same characters)

function strlBeginsWith(const p:pchar; l:longint; const expectedStart:string):boolean;

Test if p begins with expectedStart (__STRICT_HELP__, case-sensitive)

function strliBeginsWith(const p:pchar;l: longint;const expectedStart:string):boolean; inline;

Test if p begins with expectedStart (__STRICT_HELP__, case-insensitive)

function strEqual(const s1,s2:string):boolean; inline;

Tests if the strings are case-insensitive equal (same length and same characters)

function striEqual(const s1,s2:string):boolean; inline;

Tests if the strings are case-insensitive equal (same length and same characters)

function strBeginsWith(const strToBeExaminated,expectedStart:string):boolean;

Tests if the strToBeExaminated starts with expectedStart

function striBeginsWith(const strToBeExaminated,expectedStart:string):boolean;

Tests if the strToBeExaminated starts with expectedStart

function strBeginsWith(const p:pchar; const expectedStart:string):boolean; inline;

Tests if the p starts with expectedStart (p is null-terminated)

function striBeginsWith(const p:pchar; const expectedStart:string):boolean; inline;

Tests if the p starts with expectedStart (p is null-terminated)

function strEndsWith(const strToBeExaminated,expectedEnd:string):boolean;

Tests if the strToBeExaminated ends with expectedEnd

function striEndsWith(const strToBeExaminated,expectedEnd:string):boolean;

Tests if the strToBeExaminated ends with expectedEnd

function strCompareClever(const s1, s2: string): integer;

Case sensitive, clever comparison, that basically splits the string into lexicographical and numerical parts and compares them accordingly

function striCompareClever(const s1, s2: string): integer; inline;

Case insensitive, clever comparison, that basically splits the string into lexicographical and numerical parts and compares them accordingly

function strRpos(c:char;s:string):longint;

Searchs the last index of c in s

function strlCount(const search:char; const searchIn:pchar; const len: longint): longint;

Counts all occurrences of search in searchIn (case sensitive, stops at #0)

function strlsIndexOf(str,searched:pchar; l1, l2: longint): longint;

Searchs searched in str case-sensitive (Attention: opposite parameter to pos) (strict length, this function can find #0-bytes)

function strlsiIndexOf(str,searched:pchar; l1, l2: longint): longint;

Searchs searched in str case-insensitive (Attention: opposite parameter to pos) (strict length, this function can find #0-bytes)

function strIndexOf(const str,searched:string):longint; inline;

Searchs searched in str case-sensitive (Attention: opposite parameter to pos)

function striIndexOf(const str,searched:string):longint; inline;

Searchs searched in str case-insensitive (Attention: opposite parameter to pos)

function strIndexOf(const str,searched:string; from: longint):longint; inline;

Searchs searched in str case-sensitive (Attention: opposite parameter to pos)

function striIndexOf(const str,searched:string; from: longint):longint; inline;

Searchs searched in str case-insensitive (Attention: opposite parameter to pos)

function strContains(const str,searched:string):boolean; inline;

Tests if searched exists in str case-sensitive (Attention: opposite parameter to pos)

function striContains(const str,searched:string):boolean; inline;

Tests if searched exists in str case-insensitive (Attention: opposite parameter to pos)

function strContains(const str,searched:string; from: longint):boolean; inline;

Tests if searched exists in str case-sensitive (Attention: opposite parameter to pos)

function striContains(const str,searched:string; from: longint):boolean; inline;

Tests if searched exists in str case-insensitive (Attention: opposite parameter to pos)

procedure strlTrimLeft(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);

Removes all occurrences of trimCharacter from the left/right side of the string
It will move the pointer and change length, not modifying the memory pointed to

procedure strlTrimRight(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);

Removes all occurrences of trimCharacter from the left/right side of the string
It will move the pointer and change length, not modifying the memory pointed to

procedure strlTrim(var p: pchar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);

Removes all occurrences of trimCharacter from the left/right side of the string
It will move the pointer and change length, not modifying the memory pointed to

function strTrimLeft(const s:string; const trimCharacters: TCharSet = [#0..' ']):string; inline;

Removes all occurrences of trimCharacter from the left/right side of the string

function strTrimRight(const s:string; const trimCharacters: TCharSet = [#0..' ']):string; inline;
 
function strTrim(const s: string; const trimCharacters: TCharSet = [#0..' ']):string; inline;
 
function strTrimAndNormalize(const s: string; const trimCharacters: TCharSet = [#0..' ']):string;
 
function strSplitGet(const separator: string; var remainingPart: string):string; overload;

Splits the string remainingPart into two parts at the first position of separator, the first part is returned as function result, the second one is again assign to remainingPart (If remainingPart does not contain separator, it returns remainingPart and sets remainingPart := '')

procedure strSplit(out firstPart: string; const separator: string; var remainingPart: string); overload;

Splits the string remainingPart into two parts at the first position of separator, the first is assign to firstPart, the second one is again assign to remainingPart

procedure strSplit(out splitted: TStringArray;s:string;sep:string=',';includeEmpty:boolean=true); overload;

Splits the string s into the array splitted at every occurrence of sep

function strSplit(s:string;sep:string=',';includeEmpty:boolean=true):TStringArray; overload;

Splits the string s into the array splitted at every occurrence of sep

function strWrapSplit(const Line: string; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): TStringArray;
 
function strWrap(const Line: string; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): string;
 
function strSplitGetUntilBracketClosing(var text: string; const openBracket, closingBracket: string; updateText: boolean): string;
 
function strSplitGetBetweenBrackets(var text: string; const openBracket, closingBracket: string; updateText: boolean): string;
 
function strJoin(const sl: TStrings; const sep: string = ', '; limit: Integer=0; const limitStr: string='...'): string; overload;

Joins all string list items to a single string separated by sep.
If limit is set, the string is limited to abs(limit) items. if limit is positive, limitStr is appended; if limitStr is negative, limitStr is inserted in the middle

function strJoin(const sl: TStringArray; const sep: string = ', '; limit: Integer=0; const limitStr: string='...'): string; overload;

Joins all string list items to a single string separated by sep.
If limit is set, the string is limited to abs(limit) items. if limit is positive, limitStr is appended; if limitStr is negative, limitStr is inserted in the middle

function StrToBoolDef(const S: string;const Def:Boolean): Boolean;

Converts a str to a bool (for fpc versions previous 2.2)

function strLoadFromFile(filename:string):string;

loads a file as string. The filename is directly passed to the fpc rtl and uses the system encoding

See also
strLoadFromFileUTF8
procedure strSaveToFile(filename: string;str:string);

saves a string as file. The filename is directly passed to the fpc rtl and uses the system encoding

See also
strSaveToFileUTF8
function strLoadFromFileUTF8(filename:string):string;

loads a file as string. The filename should be encoded in utf-8

See also
strLoadFromFile
procedure strSaveToFileUTF8(filename: string;str:string);

saves a string as file. The filename should be encoded in utf-8

See also
strSaveToFile
function strFromSIze(size: int64):string;

converts a size (measured in bytes) to a string (e.g. 1025 -> 1 KiB)

function strLengthUtf8(str: string): longint;

length of an utf8 string
A similar function exists in lclproc, but this unit should be independent of the lcl to make it easier to compile with fpc on the command line
Currently this function also calculates the length of invalid utf8-sequences, in violation of rfc3629

function strConvertToUtf8(str: string; from: TEncoding): string;

Returns a utf-8 string from the string in encoding from

function strConvertFromUtf8(const str: string; toe: TEncoding): string;

Converts a utf-8 string to the encoding from

function strChangeEncoding(const str: string; from,toe: TEncoding):string;

Changes the string encoding from from to toe

function strGetUnicodeCharacter(const character: integer; encoding: TEncoding = eUTF8): string;

Get unicode character character in a certain encoding

function strDecodeUTF8Character(const str: string; var curpos: integer): integer;

Returns the unicode code point of the utf-8 character starting at str[curpos] and increments curpos to the next utf-8 character. Returns a negative value if the character is invalid.

function strEncodingFromName(str:string):TEncoding;

Gets the encoding from an encoding name (e.g. from http-equiv)

function strDecodeHTMLEntities(p:pchar;l:longint;encoding:TEncoding; strict: boolean = false):string;

This decodes all html entities to the given encoding. If strict is not set it will ignore wrong entities (so e.g. X&Y will remain X&Y and you can call the function even if it contains rogue &).

function strDecodeHTMLEntities(s:string;encoding:TEncoding; strict: boolean = false):string;

This decodes all html entities to the given encoding. If strict is not set it will ignore wrong entities (so e.g. X&Y will remain X&Y and you can call the function even if it contains rogue &).

function strEscape(const s:string; const toEscape: TCharSet; escapeChar: char = '\'): string;

Replace all occurences of x \in toEscape with escapeChar + x

function strEscapeRegex(const s:string): string;

Returns a regex matching s

function strDecodeHex(const s:string):string;
 
function strEncodeHex(const s:string; const code: string = '0123456789ABCDEF'):string;
 
function strFromPchar(p:pchar;l:longint):string;

Returns the first l bytes of p (copies them so O(n))

function strFromPtr(p: pointer): string;

Creates a string to display the value of a pointer (e.g. 0xDEADBEEF)

function strFromInt(i: int64; displayLength: longint): string;

Creates a string to display an integer. The result will have at least displayLength digits (digits, not characters, so -1 with length 2, will become -02).

function strDup(const rep: string; const count: integer): string;

Creates count copies of rep

function intLog10(i:longint):longint; overload;

log 10 rounded down (= number of digits in base 10 - 1)

function intLog(n,b: longint): longint; overload;

log_b n rounded down (= number of digits of n in base b - 1)

procedure intFactor(n,p: longint; out e, r:longint);

Given a number n, this procedure calculates the maximal integer e, so that n = pˆe * r

function gcd(a,b: cardinal): cardinal;

Calculates the greatest common denominator

function coprime(a,b:cardinal): boolean;

Checks if two numbers are coprime

function modPow(i, e, m: longint): longint;

Calculates iˆe mod m in O(log(e)) and never exceeding m

function intBound(min, i, max: longint): longint;
 
function modPow(i, e, m: int64): int64;

Calculates iˆe mod m in O(log(e)) and never exceeding m

function intBound(min, i, max: int64): int64;
 
function factorial(i:longint):float;

Calculates i!

function binomial(n,k: longint): float;

Calculates n|k = n!/k!(n-k)!

function binomialExpectation(n:longint;p:float):float;

expectated value of a binomial distribution

function binomialVariance(n:longint;p:float):float;

variance of a binomial distribution

function binomialDeviation(n:longint;p:float):float;

deviation(=sqrt(variance)) of a binomial distribution

function binomialProbability(n:longint;p:float;k:longint):float;

probability: P(X = k) where X is binomial distributed with n possible values (exact value calculated with binomial coefficients, )

See also
binomialProbabilityApprox
function binomialProbabilityGE(n:longint;p:float;k:longint):float;

probability: P(X >= k) where X is binomial distributed with n possible values

function binomialProbabilityLE(n:longint;p:float;k:longint):float;

probability: P(X <= k) where X is binomial distributed with n possible values

function binomialProbabilityDeviationOf(n:longint;p:float;dif:float):float;

probability: P(X >= mu + d or X <= mu - d) where X is binomial distributed with n possible values

function binomialProbabilityApprox(n:longint;p:float;k:longint):float;

expectated value of a binomial distribution (approximates the value with either Poisson or Moivre and Laplace, depending on the variance of the distribution) )

See also
binomialProbability
function binomialZScore(n:longint;p:float;k:longint):float;

Z-Score of the value k in a distribution with n outcomes

procedure intSieveEulerPhi(n: integer; var totient: TLongintArray);

This calculates the euler phi function totient[i] := phi(i) = |{1 <= j <= i | gcd(i,j) = 0}| for all i <= n.
It uses a sieve approach and is quite fast (10ˆ7 in 3s)
You can also use it to calculate all primes (i is prime iff phi(i) = i - 1)

procedure intSieveDivisorCount(n: integer; var divcount: TLongintArray);

This calculates the number of divisors: divcount[i] := |{1 <= j <= i | i mod j = 0}| for all i <= n.
Speed: 10ˆ7 in 5s

function dateWeekOfYear(const date:TDateTime):word;

Week of year

function dateIsLeapYear(const year: integer): boolean; inline;
 
Returns

if year is a leap year (supports negative years, i think)

function dateTimeParsePartsTry(const input,mask:string; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil): boolean;

Reads a date time string given a certain mask (mask is case-sensitive)
The uses the same mask types as FormatDate:
s or ss for a second
n or nn for a minute
h or hh for a hour
d or dd for a numerical day
m or mm for a numerical month, mmm for a short month name, mmmm for a long month name
am/pm or a/p match am/pm or a/p yy, yyyy or [yy]yy for the year. (if the year is < 90, it will become 20yy, else if it is < 100, it will become 19yy, unless you use uppercase Y instead of y)
YY, YYYY or [YY]YY for the year
z, zz, zzz, zzzz for milliseconds (e.g. use [.zzzzzz] for optional ms with exactly 6 digit precision, use [.z[z[z[z[z[z]]]]]] for optional ms with up to 6 digit precision) Z for the ISO time zone (written as regular expressions, it matches 'Z | [+-]hh(:?mm)?'. Z is the only format char (except mmm) matching several characters) The letter formats d/y/h/n/s matches one or two digits, the dd/mm/yy formats require exactly two.
yyyy requires exactly 4 digits, and [yy]yy works with 2 or 4 (there is also [y]yyy for 3 to 4). The year always matches an optional - (e.g. yyyy also matches -0012, but not -012)
Generally [x] marks the part x as optional (it tries all possible combinations, so you shouldn't have more than 10 optional parts)
x+ will match any additional amount of x. (e.g. yy -> 2 digit year, yy+ -> at least 2 digit year, yyyy -> 4 digit year, [yy]yy -> 2 or 4 digit year) "something" can be used to match the input verbatim
whitespace is matched against whitespace (i.e. [ #9#10#13]+ matches [ #9#10#13]+) The function works if the string is latin-1 or utf-8, and it also supports German month names
If a part is not found, it returns high(integer), except for outSecondFraction which will be 0 at not found, and outtimezone which will be NaN

Returns

If input could be matched with mask. It does not check, if the returned values are valid (e.g. month = 13 is allowed, in case you have to match durations)

procedure dateTimeParseParts(const input,mask:string; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);

Reads date/time parts from a input matching a given mask (@see dateTimeParsePartsTry)

function dateTimeFormat(const mask: string; y, m,d, h, n, s: Integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): string;

Converts a dateTime to a string corresponding to the given mask (same mask as dateTimeParsePartsTry)

function dateTimeFormat(const mask: string; const dateTime: TDateTime): string;

Converts a dateTime to a string corresponding to the given mask (same mask as dateTimeParsePartsTry)

function dateTimeEncode(const y,m,d,h,n,s:integer; const secondFraction: double = 0): TDateTime;

Encodes a date time

procedure timeParseParts(const input,mask:string; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);

Reads a time string given a certain mask (@see dateTimeParsePartsTry)

function timeParse(const input,mask:string): TTime;

Reads a time string given a certain mask (@see dateTimeParsePartsTry).
This function checks, if the time is valid.

function timeFormat(const mask: string; const h, n, s: integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): string;

Converts a dateTime to a string corresponding to the given mask (same mask as dateTimeParsePartsTry)

procedure dateParseParts(const input,mask:string; outYear, outMonth, outDay: PInteger; outtimezone: PDateTime = nil);

Reads a date string given a certain mask (@see dateTimeParsePartsTry)

function dateParse(const input,mask:string): longint;

Reads a date string given a certain mask (@see dateTimeParsePartsTry)
This function checks, if the date is valid.

function dateFormat(const mask: string; const y, m, d: integer; const timezone: TDateTime = nan): string;

Converts a dateTime to a string corresponding to the given mask (same mask as dateTimeParsePartsTry)

function dateEncodeTry(year, month, day: integer; out dt: TDateTime): boolean;

Encodes a date as datetime (supports negative years)

function dateEncode(year, month, day: integer): TDateTime;

Encodes a date as datetime (supports negative years)

procedure dateDecode(date: TDateTime; year, month, day: PInteger);

Encodes a date as datetime (supports negative years)

procedure stableSort(a,b: pointer; size: longint; compareFunction: TPointerCompareFunction = nil; compareFunctionData: TObject=nil);

General stable sort function
a is the first element in the array to sort, and b is the last. size is the size of every element
compareFunction is a function which compares two pointer to elements of the array, if it is nil, it will compare the raw bytes (which will correspond to an ascending sorting of positive integers).
Currently it uses a combination of merge and insert sort. Merge requires the allocation of additional memory.

procedure stableSort(intArray: TLongintArray; compareFunction: TPointerCompareFunction; compareFunctionData: TObject=nil);

general stable sort function (using merge + insert sort in the moment)

Types

TStringArray=array of string;
 
TLongintArray =array of longint;
 
TLongwordArray =array of longword;
 
TInt64Array =array of int64;
 
TFloatArray =array of float;
 
TProcedureOfObject = procedure () of object;
 
TEncoding = (...);
 
Values
  • eUnknown:  
  • eWindows1252:  
  • eUTF8:  
TCharSet = set of char;
 
TPointerCompareFunction = function (data: TObject; a, b: pointer): longint;

Compare function to compare the two values where a and b points to, return -1 for aˆ<bˆ The data is an TObject to prevent confusing it with a and b. It is the first parameter, so the function use the same call convention like a method

Constants

powersOf10: array[0..10] of longint = (1,10,100,1000,10000,100000,1000000,1000000,10000000,100000000,1000000000);
 
DateMonthDaysCumSum: array[false..true,0..12] of Cardinal = ((00, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365), (00, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366));

cumulative sum of month days (so. days in month i = dmdcs[i] - dmdcs[i-1])

WHITE_SPACE=[#9,#10,#13,' '];
 

Author


Generated by PasDoc 0.11.0 on 2012-05-03 23:42:58