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 procedureToMethod(proc: TProcedure): TMethod;
function makeMethod(code, data: pointer): TMethod;
procedure threadedCall(proc: TProcedureOfObject; isfinished: TNotifyEvent); overload;
procedure threadedCall(proc: TProcedureOfObject; isfinished: TProcedureOfObject); overload;
procedure threadedCall(proc: TProcedure; isfinished: TProcedureOfObject); overload;
function charDecodeDigit(c: char): integer;
function charDecodeHexDigit(c: char): integer;
function strlmove(dest,source:pansichar;destLen,sourceLen: longint):pansichar;
function widestrlmove(dest,source:pwidechar;destLen,sourceLen: longint):pwidechar;
function strCopyFrom(const s:RawByteString; start:longint):RawByteString;
function strSlice(const first,last:pansichar):RawByteString; overload;
function strSlice(const s:RawByteString; start,last:longint):RawByteString; overload;
procedure strMoveRef(var source: string; var dest: string; const size: longint);
function strlEqual(const p1,p2:pansichar;const l: longint):boolean; overload;
function strlEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;
function strliEqual(const p1,p2:pansichar;const l: longint):boolean; overload;
function strliEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;
function strlsEqual(const p1,p2:pansichar;const l: longint):boolean; overload;
function strlsEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;
function strlsiEqual(const p1,p2:pansichar;const l: longint):boolean; overload;
function strlsiEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;
function strlsequal(p: pansichar; const s: RawByteString; l: longint): boolean; overload;
function strlEqual(p:pansichar;const s:RawByteString; l: longint):boolean; overload;
function strliEqual(p:pansichar;const s:RawByteString;l: longint):boolean; overload;
function strlBeginsWith(const p:pansichar; l:longint; const expectedStart:RawByteString):boolean;
function strliBeginsWith(const p:pansichar;l: longint;const expectedStart:RawByteString):boolean;
function strEqual(const s1,s2:RawByteString):boolean;
function striEqual(const s1,s2:RawByteString):boolean;
function strBeginsWith(const strToBeExaminated,expectedStart:RawByteString):boolean; overload;
function striBeginsWith(const strToBeExaminated,expectedStart:RawByteString):boolean; overload;
function strBeginsWith(const p:pansichar; const expectedStart:RawByteString):boolean; overload;
function striBeginsWith(const p:pansichar; const expectedStart:RawByteString):boolean; overload;
function strEndsWith(const strToBeExaminated,expectedEnd:RawByteString):boolean;
function striEndsWith(const strToBeExaminated,expectedEnd:RawByteString):boolean;
function strCompareClever(const s1, s2: RawByteString): integer;
function striCompareClever(const s1, s2: RawByteString): integer;
function strRpos(c:ansichar;s:RawByteString):longint;
function strCount(const str: RawByteString; const searched: ansichar; from: longint = 1): longint; overload;
function strCount(const str: RawByteString; const searched: TCharSet; from: longint = 1): longint; overload;
function strlsIndexOf(str,searched:pansichar; l1, l2: longint): longint; overload;
function strlsIndexOf(str:pansichar; const searched: TCharSet; length: longint): longint; overload;
function strlsiIndexOf(str,searched:pansichar; l1, l2: longint): longint;
function strIndexOf(const str,searched:RawByteString):longint; overload;
function strIndexOf(const str: RawByteString; const searched: TCharSet):longint; overload;
function striIndexOf(const str,searched:RawByteString):longint; overload;
function strIndexOf(const str,searched:RawByteString; from: longint):longint; overload;
function strIndexOf(const str: RawByteString; const searched: TCharSet; from: longint):longint; overload;
function striIndexOf(const str,searched:RawByteString; from: longint):longint; overload;
function strlsLastIndexOf(str,searched:pansichar; l1, l2: longint): longint; overload;
function strlsLastIndexOf(str:pansichar; const searched: TCharSet; length: longint): longint; overload;
function strlsiLastIndexOf(str,searched:pansichar; l1, l2: longint): longint;
function strLastIndexOf(const str: RawByteString; const searched: RawByteString):longint; overload;
function strLastIndexOf(const str: RawByteString; const searched: RawByteString; from: longint):longint; overload;
function strLastIndexOf(const str: RawByteString; const searched: TCharSet):longint; overload;
function strLastIndexOf(const str: RawByteString; const searched: TCharSet; from: longint):longint; overload;
function striLastIndexOf(const str: RawByteString; const searched: RawByteString):longint; overload;
function striLastIndexOf(const str: RawByteString; const searched: RawByteString; from: longint):longint; overload;
function strContains(const str,searched:RawByteString):boolean; overload;
function strContains(const str:RawByteString; const searched: TCharSet):boolean; overload;
function striContains(const str,searched:RawByteString):boolean; overload;
function strContains(const str,searched:RawByteString; from: longint):boolean; overload;
function strContains(const str:RawByteString; const searched: TCharSet; from: longint):boolean; overload;
function striContains(const str,searched:RawByteString; from: longint):boolean; overload;
procedure strlTrimLeft(var p: pansichar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
procedure strlTrimRight(var p: pansichar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
procedure strlTrim(var p: pansichar; var l: integer; const trimCharacters: TCharSet = [#0..' ']);
function strTrimLeft(const s:RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
function strTrimRight(const s:RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
function strTrim(const s: RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
function strTrimAndNormalize(const s: RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
function strNormalizeLineEndings(const s: RawByteString): RawByteString;
function strNormalizeLineEndingsUTF8(const s: RawByteString): RawByteString;
function strPrependIfMissing(const s: RawByteString; const expectedStart: RawByteString): RawByteString;
function strAppendIfMissing(const s: RawByteString; const expectedEnd: RawByteString): RawByteString;
function strSplitGet(const separator: RawByteString; var remainingPart: string):string; overload;
procedure strSplit(out firstPart: string; const separator: RawByteString; var remainingPart: string); overload;
procedure strSplit(out splitted: TStringArray;s: RawByteString; sep:RawByteString=',';includeEmpty:boolean=true); overload;
function strSplit(s:RawByteString;sep:RawByteString=',';includeEmpty:boolean=true):TStringArray; overload;
function strWrapSplit(const Line: RawByteString; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): TStringArray;
function strWrap(Line: RawByteString; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): RawByteString;
function strReverse(s: string): string;
function strSplitGetUntilBracketClosing(var text: RawByteString; const openBracket, closingBracket: RawByteString; updateText: boolean): RawByteString;
function strSplitGetBetweenBrackets(var text: RawByteString; const openBracket, closingBracket: RawByteString; updateText: boolean): RawByteString;
function strBeforeLast(const s: RawByteString; const sep: TCharSet): RawByteString; overload;
function strAfterLast(const s: RawByteString; const sep: TCharSet): RawByteString; overload;
function strJoin(const sl: TStrings; const sep: RawByteString = ', '; limit: Integer=0; const limitStr: RawByteString='...'): RawByteString; overload;
function strJoin(const sl: TStringArray; const sep: RawByteString = ', '; limit: Integer=0; const limitStr: RawByteString='...'): RawByteString; overload;
function StrToBoolDef(const S: RawByteString;const Def:Boolean): Boolean;
function strRemoveFileURLPrefix(const filename: RawByteString): RawByteString;
function strLoadFromFile(filename:RawByteString):RawByteString;
procedure strSaveToFile(filename: RawByteString;str:RawByteString);
function strLoadFromFileUTF8(filename:RawByteString):RawByteString;
procedure strSaveToFileUTF8(filename: RawByteString;str:RawByteString);
function strFromSIze(size: int64):string;
function strLengthUtf8(str: RawByteString): longint;
function strConvertToUtf8(str: RawByteString; from: TSystemCodePage): RawByteString;
function strConvertFromUtf8(str: RawByteString; toe: TSystemCodePage): RawByteString;
function strChangeEncoding(const str: RawByteString; from,toe: TSystemCodePage):RawByteString;
function strDecodeUTF16Character(var source: PUnicodeChar): integer;
function strGetUnicodeCharacter(const character: integer; encoding: TSystemCodePage = CP_UTF8): RawByteString;
function strGetUnicodeCharacterUTFLength(const character: integer): integer;
procedure strGetUnicodeCharacterUTF(const character: integer; buffer: pansichar);
function strDecodeUTF8Character(const str: RawByteString; var curpos: integer): integer; overload;
function strDecodeUTF8Character(var source: PChar; var remainingLength: SizeInt): integer; overload;
function strEncodingFromBOMRemove(var str:string):TSystemCodePage;
function strUpperCaseSpecialUTF8(codePoint: integer): string;
function strLowerCaseSpecialUTF8(codePoint: integer): string;
function strDecodeHTMLEntities(p:pansichar;l:longint;encoding:TSystemCodePage; strict: boolean = false):string; overload;
function strDecodeHTMLEntities(s:RawByteString;encoding:TSystemCodePage; strict: boolean = false):string; overload;
function strEscape(s:RawByteString; const toEscape: TCharSet; escapeChar: ansichar = '\'): RawByteString;
function strEscapeToHex(s:RawByteString; const toEscape: TCharSet; escape: RawByteString = '\x'): RawByteString;
function strUnescapeHex(s:RawByteString; escape: RawByteString = '\x'): RawByteString;
function strEscapeRegex(const s:RawByteString): RawByteString;
function strDecodeHex(s:RawByteString):RawByteString;
function strEncodeHex(s:RawByteString; const code: RawByteString = '0123456789ABCDEF'):RawByteString;
function strFromPchar(p:pansichar;l:longint):RawByteString;
function strFromPtr(p: pointer): RawByteString;
function strFromInt(i: int64; displayLength: longint): RawByteString;
function strDup(rep: RawByteString; const count: integer): RawByteString;
function strIsAbsoluteURI(const s: RawByteString): boolean;
function strResolveURI(rel, base: RawByteString): RawByteString;
function fileNameExpand(const rel: string): string;
function fileNameExpandToURI(const rel: string): string;
function fileMoveReplace(const oldname,newname: string): boolean;
procedure fileSaveSafe(filename: string; callback: TFileSaveSafe; data: pointer);
function strSimilarity(const s, t: RawByteString): integer;
function SwapEndian(const w: Word): Word; overload;
function SwapEndian(const w: DWord): DWord; overload;
function intLog10(i:longint):longint; overload;
function intLog(n,b: longint): longint; overload;
procedure intFactor(const n,p: longint; out e, r:longint);
function gcd(a,b: integer): integer; overload;
function gcd(a,b: cardinal): cardinal; overload;
function gcd(a,b: int64): int64; overload;
function lcm(a,b: int64): int64;
function coprime(a,b:cardinal): boolean;
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(const n: cardinal; var totient: TLongwordArray);
procedure intSieveDivisorCount(n: integer; var divcount: TLongintArray);
function dateWeekOfYear(const date:TDateTime):word; overload;
function dateWeekOfYear(year, month, day: integer):word; overload;
function dateIsLeapYear(const year: integer): boolean;
function dateTimeParsePartsTry(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil; options: TDateTimeParsingFlags = []): TDateTimeParsingResult;
procedure dateTimeParsePartsNew(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil);
procedure dateTimeParsePartsOld(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
function dateTimeParseNew(const input,mask:RawByteString; outtimezone: PInteger = nil): TDateTime;
function dateTimeParseOld(const input,mask:RawByteString; outtimezone: PDateTime = nil): TDateTime;
function dateTimeFormatNEW(const mask: RawByteString; y, m,d, h, n, s: Integer; nanoseconds: integer; timezone: integer = high(integer)): RawByteString; overload;
function dateTimeFormat(const mask: RawByteString; const dateTime: TDateTime): RawByteString; overload;
function dateTimeEncodeOLD(const y,m,d,h,n,s:integer; const secondFraction: double = 0): TDateTime;
function dateTimeFormatOLD(const mask: RawByteString; y, m,d, h, n, s: Integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): RawByteString; overload;
procedure timeParsePartsNew(const input,mask:RawByteString; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil);
procedure timeParsePartsOld(const input,mask:RawByteString; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
function timeParse(const input,mask:RawByteString): TTime;
function timeFormatOld(const mask: RawByteString; const h, n, s: integer; const secondFraction: double = 0; const timezone: TDateTime = Nan): RawByteString;
procedure dateParsePartsNew(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outtimezone: PInteger = nil);
procedure dateParsePartsOLD(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outtimezone: PDateTime = nil);
function dateParse(const input,mask:RawByteString): longint;
function dateFormat(const mask: RawByteString; const y, m, d: integer; const timezone: TDateTime = nan): RawByteString;
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); overload;
function stableSort(intArray: TLongintArray; compareFunction: TPointerCompareFunction; compareFunctionData: TObject=nil): TLongintArray; overload;
function stableSort(strArray: TStringArray; compareFunction: TPointerCompareFunction = nil; compareFunctionData: TObject=nil): TStringArray; overload;
function binarySearch(a,b: pointer; size: longint; compareFunction: TBinarySearchFunction = nil; compareFunctionData: TObject=nil; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): pointer;
function eUTF8: TSystemCodePage;
function eWindows1252: TSystemCodePage;
function arrayAdd(var a: TStringArray; const e: string):longint; overload;
function arrayAdd(var a: TStringArray; const a2: array of string):longint; overload;
procedure arrayPrepend(var a: TStringArray; const e: string); overload;
function arrayDelete(var a: TStringArray; const i: longint):string; overload;
function arrayDeleteUnordered(var a: TStringArray; const i: longint):string; overload;
procedure arrayReserveFast(var a: TStringArray; const len: longint; const reserveLength: longint); overload;
function arrayAddFast(var a: TStringArray; var len: longint; const e: string): longint; overload;
procedure arrayPrependFast(var a: TStringArray; var len: longint; const e: string); overload;
function arrayDeleteFast(var a: TStringArray; var len: longint; const i: longint):string; overload;
function arrayDeleteUnorderedFast(var a: TStringArray; var len: longint; const i: longint):string; overload;
procedure arrayInsert(var a: TStringArray; i: longint; const e: string); overload;
procedure arrayInsertFast(var a: TStringArray; var len: longint; i: longint; const e: string); overload;
function arrayIndexOf(const a: array of string; const e: string; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfSmallest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfLargest(const a: array of string; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayContains(const a: array of string; const e: string; slice1: integer = -1; slice2: integer = -1): boolean; overload;
procedure arrayInvert(a: TStringArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of string; slice1: integer = -1;slice2: integer = -1): TStringArray; overload;
function arrayGet(a: array of string; const i: integer): string; overload;
function arrayLast(a: array of string): string; overload;
function arrayLast(a: array of string; const default: string): string; overload;
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: array of longint):longint; overload;
procedure arrayPrepend(var a: TLongintArray; const e: longint); overload;
function arrayDelete(var a: TLongintArray; const i: longint):longint; overload;
function arrayDeleteUnordered(var a: TLongintArray; const i: longint):longint; overload;
procedure arrayReserveFast(var a: TLongintArray; const len: longint; const reserveLength: longint); overload;
function arrayAddFast(var a: TLongintArray; var len: longint; const e: longint): longint; overload;
procedure arrayPrependFast(var a: TLongintArray; var len: longint; const e: longint); overload;
function arrayDeleteFast(var a: TLongintArray; var len: longint; const i: longint):longint; overload;
function arrayDeleteUnorderedFast(var a: TLongintArray; var len: longint; const i: longint):longint; overload;
procedure arrayInsert(var a: TLongintArray; i: longint; const e: longint); overload;
procedure arrayInsertFast(var a: TLongintArray; var len: longint; i: longint; const e: longint); overload;
function arrayIndexOf(const a: array of longint; const e: longint; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfSmallest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfLargest(const a: array of longint; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayContains(const a: array of longint; const e: longint; slice1: integer = -1; slice2: integer = -1): boolean; overload;
procedure arrayInvert(a: TLongintArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of longint; slice1: integer = -1;slice2: integer = -1): TLongintArray; overload;
function arrayGet(a: array of longint; const i: integer): longint; overload;
function arrayLast(a: array of longint): longint; overload;
function arrayLast(a: array of longint; const default: longint): longint; overload;
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: array of longword):longint; overload;
procedure arrayPrepend(var a: TLongwordArray; const e: longword); overload;
function arrayDelete(var a: TLongwordArray; const i: longint):longword; overload;
function arrayDeleteUnordered(var a: TLongwordArray; const i: longint):longword; overload;
procedure arrayReserveFast(var a: TLongwordArray; const len: longint; const reserveLength: longint); overload;
function arrayAddFast(var a: TLongwordArray; var len: longint; const e: longword): longint; overload;
procedure arrayPrependFast(var a: TLongwordArray; var len: longint; const e: longword); overload;
function arrayDeleteFast(var a: TLongwordArray; var len: longint; const i: longint):longword; overload;
function arrayDeleteUnorderedFast(var a: TLongwordArray; var len: longint; const i: longint):longword; overload;
procedure arrayInsert(var a: TLongwordArray; i: longint; const e: longword); overload;
procedure arrayInsertFast(var a: TLongwordArray; var len: longint; i: longint; const e: longword); overload;
function arrayIndexOf(const a: array of longword; const e: longword; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfSmallest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfLargest(const a: array of longword; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayContains(const a: array of longword; const e: longword; slice1: integer = -1; slice2: integer = -1): boolean; overload;
procedure arrayInvert(a: TLongwordArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of longword; slice1: integer = -1;slice2: integer = -1): TLongwordArray; overload;
function arrayGet(a: array of longword; const i: integer): longword; overload;
function arrayLast(a: array of longword): longword; overload;
function arrayLast(a: array of longword; const default: longword): longword; overload;
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: array of int64):longint; overload;
procedure arrayPrepend(var a: TInt64Array; const e: int64); overload;
function arrayDelete(var a: TInt64Array; const i: longint):int64; overload;
function arrayDeleteUnordered(var a: TInt64Array; const i: longint):int64; overload;
procedure arrayReserveFast(var a: TInt64Array; const len: longint; const reserveLength: longint); overload;
function arrayAddFast(var a: TInt64Array; var len: longint; const e: int64): longint; overload;
procedure arrayPrependFast(var a: TInt64Array; var len: longint; const e: int64); overload;
function arrayDeleteFast(var a: TInt64Array; var len: longint; const i: longint):int64; overload;
function arrayDeleteUnorderedFast(var a: TInt64Array; var len: longint; const i: longint):int64; overload;
procedure arrayInsert(var a: TInt64Array; i: longint; const e: int64); overload;
procedure arrayInsertFast(var a: TInt64Array; var len: longint; i: longint; const e: int64); overload;
function arrayIndexOf(const a: array of int64; const e: int64; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfSmallest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfLargest(const a: array of int64; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayContains(const a: array of int64; const e: int64; slice1: integer = -1; slice2: integer = -1): boolean; overload;
procedure arrayInvert(a: TInt64Array; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of int64; slice1: integer = -1;slice2: integer = -1): TInt64Array; overload;
function arrayGet(a: array of int64; const i: integer): int64; overload;
function arrayLast(a: array of int64): int64; overload;
function arrayLast(a: array of int64; const default: int64): int64; overload;
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: array of float):longint; overload;
procedure arrayPrepend(var a: TFloatArray; const e: float); overload;
function arrayDelete(var a: TFloatArray; const i: longint):float; overload;
function arrayDeleteUnordered(var a: TFloatArray; const i: longint):float; overload;
procedure arrayReserveFast(var a: TFloatArray; const len: longint; const reserveLength: longint); overload;
function arrayAddFast(var a: TFloatArray; var len: longint; const e: float): longint; overload;
procedure arrayPrependFast(var a: TFloatArray; var len: longint; const e: float); overload;
function arrayDeleteFast(var a: TFloatArray; var len: longint; const i: longint):float; overload;
function arrayDeleteUnorderedFast(var a: TFloatArray; var len: longint; const i: longint):float; overload;
procedure arrayInsert(var a: TFloatArray; i: longint; const e: float); overload;
procedure arrayInsertFast(var a: TFloatArray; var len: longint; i: longint; const e: float); overload;
function arrayIndexOf(const a: array of float; const e: float; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfSmallest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayIndexOfLargest(const a: array of float; slice1: integer = -1; slice2: integer = -1): integer; overload;
function arrayContains(const a: array of float; const e: float; slice1: integer = -1; slice2: integer = -1): boolean; overload;
procedure arrayInvert(a: TFloatArray; slice1: integer = -1;slice2: integer = -1); overload;
function arraySlice(a: array of float; slice1: integer = -1;slice2: integer = -1): TFloatArray; overload;
function arrayGet(a: array of float; const i: integer): float; overload;
function arrayLast(a: array of float): float; overload;
function arrayLast(a: array of float; const default: float): float; overload;
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; overload;
function unequal(const a, b, c: integer): boolean; overload;
function unequal(const a: array of integer): boolean; overload;
function unequal(const a, b: cardinal): boolean; overload;
function unequal(const a, b, c: cardinal): boolean; overload;
function unequal(const a: array of cardinal): boolean; overload;
function unequal(const a, b: RawByteString): boolean; overload;
function unequal(const a, b, c: RawByteString): boolean; overload;
function unequal(const a: array of RawByteString): boolean; overload;
function unequal(const a, b: int64): boolean; overload;
function unequal(const a, b, c: int64): boolean; overload;
function unequal(const a: array of int64): boolean; overload;
function strBetween(const s, from, till: RawByteString): RawByteString;
function strBefore(const s, sep: RawByteString): RawByteString; overload;
function strAfter(const s, sep: RawByteString): RawByteString; overload;
function strBeforeLast(const s, sep: RawByteString): RawByteString; overload;
function strAfterLast(const s, sep: RawByteString): RawByteString; overload;
function striBetween(const s, from, till: RawByteString): RawByteString;
function striBefore(const s, sep: RawByteString): RawByteString; overload;
function striAfter(const s, sep: RawByteString): RawByteString; overload;
function striBeforeLast(const s, sep: RawByteString): RawByteString; overload;
function striAfterLast(const s, sep: RawByteString): RawByteString; overload;
function intSqrt(const i: longint): longint; overload;
function intSqrt(const i: int64): int64; overload;
function modPow(i, e, m: longint): longint; overload;
function intBound(min, i, max: longint): longint; overload;
function modPow(i, e, m: int64): int64; overload;
function intBound(min, i, max: int64): int64; overload;
function arrayBinarySearch(a: TStringArray; const value: string; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;
function arrayBinarySearch(a: TLongintArray; const value: longint; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;
function arrayBinarySearch(a: TLongwordArray; const value: longword; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;
function arrayBinarySearch(a: TInt64Array; const value: int64; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;
function arrayBinarySearch(a: TFloatArray; const value: float; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;
procedure ignore(const intentionallyUnusedParameter: string); overload;
procedure ignore(const intentionallyUnusedParameter: boolean); overload;
procedure ignore(const intentionallyUnusedParameter: integer); overload;
procedure ignore(const intentionallyUnusedParameter: Int64); overload;
procedure ignore(const intentionallyUnusedParameter: TObject); overload;
procedure ignore(const intentionallyUnusedParameter: pointer); overload;

Types

float = extended;
TTime = TDateTime;
SizeInt = integer;
TValueSign = -1..1;
RawByteString = ansistring;
UnicodeString = WideString;
PUnicodeChar = ˆWideChar;
TSystemCodePage = Word;
TStringArray=array of string;
TLongintArray =array of longint;
TLongwordArray =array of longword;
TInt64Array =array of int64;
TFloatArray = array of float;
TCharSet = set of ansichar;
TProcedureOfObject = procedure () of object;
TStreamLikeWrite = procedure(const Buffer; Count: Longint) of object;
TFileSaveSafe = procedure (stream: TStream; data: pointer);
TDateTimeParsingFlag = (...);
TDateTimeParsingFlags = set of TDateTimeParsingFlag;
TDateTimeParsingResult = (...);
TPointerCompareFunction = function (data: TObject; a, b: pointer): longint;
TBinarySearchChoosen = (...);
TBinarySearchAcceptedCondition = (...);
TBinarySearchAcceptedConditions = set of TBinarySearchAcceptedCondition;
TBinarySearchFunction = function (data: TObject; a: pointer): longint;

Constants

NaN = 0.0/0.0;
Infinity = 1.0/0.0;
NegInfinity = -1.0/0.0;
LineEnding = #13#10;
CP_UTF16 = 1200;
CP_UTF16BE = 1201;
CP_UTF8 = 65001;
CP_NONE = $FFFF;
CP_ASCII = 20127;
CP_UTF32 = 12000;
CP_UTF32BE = 12001;
CP_WINDOWS1252 = 1252;
CP_LATIN1 = 28591;
powersOf10: array[0..9] of longint = (1,10,100,1000,10000,100000,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 procedureToMethod(proc: TProcedure): TMethod;
 
function makeMethod(code, data: pointer): TMethod;
 
procedure threadedCall(proc: TProcedureOfObject; isfinished: TNotifyEvent); overload;

Calls proc in an new thread

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

Calls proc in an new thread

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

Calls proc in an new thread

function charDecodeDigit(c: char): integer;
 
function charDecodeHexDigit(c: char): integer;
 
function strlmove(dest,source:pansichar;destLen,sourceLen: longint):pansichar;

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:RawByteString; start:longint):RawByteString;

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

function strSlice(const first,last:pansichar):RawByteString; overload;

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

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

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

procedure strMoveRef(var source: string; var dest: string; const size: longint);

Like move: moves count strings from source memory to dest memory. Keeps the reference count intact. Size is count of strings * sizeof(string)!

function strlEqual(const p1,p2:pansichar;const l: longint):boolean; overload;

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

function strlEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;

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

function strliEqual(const p1,p2:pansichar;const l: longint):boolean; overload;

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

function strliEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;

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

function strlsEqual(const p1,p2:pansichar;const l: longint):boolean; overload;

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

function strlsEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;

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

function strlsiEqual(const p1,p2:pansichar;const l: longint):boolean; overload;

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

function strlsiEqual(const p1,p2:pansichar;const l1,l2: longint):boolean; overload;

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

function strlsequal(p: pansichar; const s: RawByteString; l: longint): boolean; overload;
 
function strlEqual(p:pansichar;const s:RawByteString; l: longint):boolean; overload;

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

function strliEqual(p:pansichar;const s:RawByteString;l: longint):boolean; overload;

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

function strlBeginsWith(const p:pansichar; l:longint; const expectedStart:RawByteString):boolean;

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

function strliBeginsWith(const p:pansichar;l: longint;const expectedStart:RawByteString):boolean;

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

function strEqual(const s1,s2:RawByteString):boolean;

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

function striEqual(const s1,s2:RawByteString):boolean;

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

function strBeginsWith(const strToBeExaminated,expectedStart:RawByteString):boolean; overload;

Tests if the strToBeExaminated starts with expectedStart

function striBeginsWith(const strToBeExaminated,expectedStart:RawByteString):boolean; overload;

Tests if the strToBeExaminated starts with expectedStart

function strBeginsWith(const p:pansichar; const expectedStart:RawByteString):boolean; overload;

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

function striBeginsWith(const p:pansichar; const expectedStart:RawByteString):boolean; overload;

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

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

Tests if the strToBeExaminated ends with expectedEnd

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

Tests if the strToBeExaminated ends with expectedEnd

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

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

function striCompareClever(const s1, s2: RawByteString): integer;

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

function strRpos(c:ansichar;s:RawByteString):longint;

Searchs the last index of c in s

function strCount(const str: RawByteString; const searched: ansichar; from: longint = 1): longint; overload;

Counts all occurrences of searched in searchIn (case sensitive)

function strCount(const str: RawByteString; const searched: TCharSet; from: longint = 1): longint; overload;

Counts all occurrences of searched in searchIn (case sensitive)

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

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

function strlsIndexOf(str:pansichar; const searched: TCharSet; length: longint): longint; overload;

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

function strlsiIndexOf(str,searched:pansichar; 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:RawByteString):longint; overload;

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

function strIndexOf(const str: RawByteString; const searched: TCharSet):longint; overload;

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

function striIndexOf(const str,searched:RawByteString):longint; overload;

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

function strIndexOf(const str,searched:RawByteString; from: longint):longint; overload;

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

function strIndexOf(const str: RawByteString; const searched: TCharSet; from: longint):longint; overload;

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

function striIndexOf(const str,searched:RawByteString; from: longint):longint; overload;

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

function strlsLastIndexOf(str,searched:pansichar; l1, l2: longint): longint; overload;

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

function strlsLastIndexOf(str:pansichar; const searched: TCharSet; length: longint): longint; overload;

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

function strlsiLastIndexOf(str,searched:pansichar; l1, l2: longint): longint;

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

function strLastIndexOf(const str: RawByteString; const searched: RawByteString):longint; overload;

Searchs the last occurrence of searched in str, case-sensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function strLastIndexOf(const str: RawByteString; const searched: RawByteString; from: longint):longint; overload;

Searchs the last occurrence of searched in str, case-sensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function strLastIndexOf(const str: RawByteString; const searched: TCharSet):longint; overload;

Searchs the last occurrence of searched in str, case-sensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function strLastIndexOf(const str: RawByteString; const searched: TCharSet; from: longint):longint; overload;

Searchs the last occurrence of searched in str, case-sensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function striLastIndexOf(const str: RawByteString; const searched: RawByteString):longint; overload;

Searchs the last occurrence of searched in str, case-insensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function striLastIndexOf(const str: RawByteString; const searched: RawByteString; from: longint):longint; overload;

Searchs the last occurrence of searched in str, case-insensitive, returns 0 on no occurrence (Attention: opposite parameter to pos)

function strContains(const str,searched:RawByteString):boolean; overload;

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

function strContains(const str:RawByteString; const searched: TCharSet):boolean; overload;

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

function striContains(const str,searched:RawByteString):boolean; overload;

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

function strContains(const str,searched:RawByteString; from: longint):boolean; overload;

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

function strContains(const str:RawByteString; const searched: TCharSet; from: longint):boolean; overload;

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

function striContains(const str,searched:RawByteString; from: longint):boolean; overload;

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

procedure strlTrimLeft(var p: pansichar; 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: pansichar; 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: pansichar; 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:RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;

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

function strTrimRight(const s:RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
 
function strTrim(const s: RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;
 
function strTrimAndNormalize(const s: RawByteString; const trimCharacters: TCharSet = [#0..' ']):RawByteString;

Replaces all #13#10 or #13 by #10

function strNormalizeLineEndings(const s: RawByteString): RawByteString;

Replaces all #$D#$A, #$D #$85, #$85, #$2028, or #13 by #10. Experimental, behaviour might change in future

function strNormalizeLineEndingsUTF8(const s: RawByteString): RawByteString;

Prepends expectedStart, if s does not starts with expectedStart

function strPrependIfMissing(const s: RawByteString; const expectedStart: RawByteString): RawByteString;

Appends expectedEnd, if s does not end with expectedEnd

function strAppendIfMissing(const s: RawByteString; const expectedEnd: RawByteString): RawByteString;
 
function strSplitGet(const separator: RawByteString; 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: RawByteString; 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: RawByteString; sep:RawByteString=',';includeEmpty:boolean=true); overload;

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

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

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

function strWrapSplit(const Line: RawByteString; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): TStringArray;
 
function strWrap(Line: RawByteString; MaxCol: Integer = 80; const BreakChars: TCharSet = [' ', #9]): RawByteString;
 
function strReverse(s: string): string;

reverses a string. Assumes the encoding is utf-8

function strSplitGetUntilBracketClosing(var text: RawByteString; const openBracket, closingBracket: RawByteString; updateText: boolean): RawByteString;
 
function strSplitGetBetweenBrackets(var text: RawByteString; const openBracket, closingBracket: RawByteString; updateText: boolean): RawByteString;
 
function strBeforeLast(const s: RawByteString; const sep: TCharSet): RawByteString; overload;

If the string s has the form 'STARTsep...' it returns 'START'. E.g. for /foo/bar it returns /foo with AllowDirectorySeparators do

function strAfterLast(const s: RawByteString; const sep: TCharSet): RawByteString; overload;

If the string s has the form '...sepEND' it returns 'END'. E.g. for /foo/bar it returns bar with AllowDirectorySeparators

function strJoin(const sl: TStrings; const sep: RawByteString = ', '; limit: Integer=0; const limitStr: RawByteString='...'): RawByteString; 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: RawByteString = ', '; limit: Integer=0; const limitStr: RawByteString='...'): RawByteString; 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: RawByteString;const Def:Boolean): Boolean;

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

function strRemoveFileURLPrefix(const filename: RawByteString): RawByteString;

Removes a file:// prefix from filename if it is there

function strLoadFromFile(filename:RawByteString):RawByteString;

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: RawByteString;str:RawByteString);

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:RawByteString):RawByteString;

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

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

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: RawByteString): 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: RawByteString; from: TSystemCodePage): RawByteString;

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

function strConvertFromUtf8(str: RawByteString; toe: TSystemCodePage): RawByteString;

Converts a utf-8 string to the encoding from

function strChangeEncoding(const str: RawByteString; from,toe: TSystemCodePage):RawByteString;

Changes the string encoding from from to toe

function strDecodeUTF16Character(var source: PUnicodeChar): integer;
 
function strGetUnicodeCharacter(const character: integer; encoding: TSystemCodePage = CP_UTF8): RawByteString;

Get unicode character character in a certain encoding

function strGetUnicodeCharacterUTFLength(const character: integer): integer;
 
procedure strGetUnicodeCharacterUTF(const character: integer; buffer: pansichar);
 
function strDecodeUTF8Character(const str: RawByteString; var curpos: integer): integer; overload;

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 strDecodeUTF8Character(var source: PChar; var remainingLength: SizeInt): integer; overload;

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

function strEncodingFromBOMRemove(var str:string):TSystemCodePage;

Gets the encoding from an unicode bom and removes it

function strUpperCaseSpecialUTF8(codePoint: integer): string;

This function converts codePoint to the corresponding uppercase codepoint according to the unconditional cases of SpecialCasing.txt of Unicode 8.
It cannot be used to convert a character to uppercase, as SpecialCasing.txt is not a map from normal characters to their uppercase variants. It is a collection of special characters that do not have an ordinary uppercase variant and are converted to something else. (e.g. ß -> SS)
The function signature is preliminary and likely to change.

function strLowerCaseSpecialUTF8(codePoint: integer): string;

This function converts codePoint to the corresponding lowercase codepoint according to the unconditional cases of SpecialCasing.txt of Unicode 8.
It cannot be used to convert a character to lowercase, as SpecialCasing.txt is not a map from normal characters to their lowercase variants. It is a collection of special characters that do not have an ordinary lowercase variant and are converted to something else.
The function signature is preliminary and likely to change.

function strDecodeHTMLEntities(p:pansichar;l:longint;encoding:TSystemCodePage; strict: boolean = false):string; overload;

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:RawByteString;encoding:TSystemCodePage; strict: boolean = false):string; overload;

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(s:RawByteString; const toEscape: TCharSet; escapeChar: ansichar = '\'): RawByteString;

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

function strEscapeToHex(s:RawByteString; const toEscape: TCharSet; escape: RawByteString = '\x'): RawByteString;

Replace all occurences of x \in toEscape with escape + hex(ord(x))

function strUnescapeHex(s:RawByteString; escape: RawByteString = '\x'): RawByteString;

Replace all occurences of escape + XX with chr(XX)

function strEscapeRegex(const s:RawByteString): RawByteString;

Returns a regex matching s

function strDecodeHex(s:RawByteString):RawByteString;

Decodes a binary hex string like 202020 where every pair of hex digits corresponds to one char (deprecated, use strUnescapeHex)

function strEncodeHex(s:RawByteString; const code: RawByteString = '0123456789ABCDEF'):RawByteString;

Encodes to a binary hex string like 202020 where every pair of hex digits corresponds to one char (deprecated, use strEscapeToHex)

function strFromPchar(p:pansichar;l:longint):RawByteString;

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

function strFromPtr(p: pointer): RawByteString;

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

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

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(rep: RawByteString; const count: integer): RawByteString;

Creates count copies of rep

function strIsAbsoluteURI(const s: RawByteString): boolean;

Checks if s is an absolute uri (i.e. has a [a-zA-Z][a-zA-Z0-9+-.]:// prefix)

function strResolveURI(rel, base: RawByteString): RawByteString;

Returns a absolute uri for a uri relative to the uri base.
E.g. strResolveURI('foo/bar', 'http://example.org/abc/def') returns 'http://example.org/abc/foo/bar'
Or. strResolveURI('foo/bar', 'http://example.org/abc/def/') returns 'http://example.org/abc/def/foo/bar'
base may be relative itself (e.g. strResolveURI('foo/bar', 'test/') becomes 'test/foo/bar')

function fileNameExpand(const rel: string): string;

Expands a path to an absolute path, if it not already is one

function fileNameExpandToURI(const rel: string): string;

Expands a path to an absolute path starting with file://

function fileMoveReplace(const oldname,newname: string): boolean;

Moves oldname to newname, replacing newname if it exists

procedure fileSaveSafe(filename: string; callback: TFileSaveSafe; data: pointer);
 
function strSimilarity(const s, t: RawByteString): integer;

Levenshtein distance between s and t (i.e. the minimal count of characters to change/add/remove to convert s to t). O(n**2) time, O(n) space

function SwapEndian(const w: Word): Word; overload;
 
function SwapEndian(const w: DWord): DWord; overload;
 
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(const 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: integer): integer; overload;

Calculates the greatest common denominator

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

Calculates the greatest common denominator

function gcd(a,b: int64): int64; overload;

Calculates the greatest common denominator

function lcm(a,b: int64): int64;

Calculates the least common multiple (just a*b div gcd(a,b), so it can easily overflow)

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

Checks if two numbers are coprime

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(const n: cardinal; var totient: TLongwordArray);

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; overload;

Week of year

function dateWeekOfYear(year, month, day: integer):word; overload;
 
function dateIsLeapYear(const year: integer): boolean;
 
Returns

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

function dateTimeParsePartsTry(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil; options: TDateTimeParsingFlags = []): TDateTimeParsingResult;

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 microseconds (e.g. use [.zzzzzz] for optional ms with exactly 6 digit precision, use [.z[z[z[z[z[z]]]]]] for optional µs 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 ansichar (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) (mmm+ for short or long dates)
"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) there

There are old and new functions, because the signature has changed from double to int. Do not use the OLD functions unless you are porting existing code.

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 dateTimeParsePartsNew(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil);

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

procedure dateTimeParsePartsOld(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
 
function dateTimeParseNew(const input,mask:RawByteString; outtimezone: PInteger = nil): TDateTime;

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

function dateTimeParseOld(const input,mask:RawByteString; outtimezone: PDateTime = nil): TDateTime;
 
function dateTimeFormatNEW(const mask: RawByteString; y, m,d, h, n, s: Integer; nanoseconds: integer; timezone: integer = high(integer)): RawByteString; overload;

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

function dateTimeFormat(const mask: RawByteString; const dateTime: TDateTime): RawByteString; overload;

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

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

Encodes a date time

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

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

procedure timeParsePartsNew(const input,mask:RawByteString; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PInteger = nil; outtimezone: PInteger = nil);

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

procedure timeParsePartsOld(const input,mask:RawByteString; outHour, outMinutes, outSeconds: PInteger; outSecondFraction: PDouble = nil; outtimezone: PDateTime = nil);
 
function timeParse(const input,mask:RawByteString): TTime;

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

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

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

procedure dateParsePartsNew(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outtimezone: PInteger = nil);

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

procedure dateParsePartsOLD(const input,mask:RawByteString; outYear, outMonth, outDay: PInteger; outtimezone: PDateTime = nil);
 
function dateParse(const input,mask:RawByteString): longint;

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

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

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); overload;

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).
Only the > 0 and <= 0 return values are discerned. (i.e. you can safely use a comparison function that e.g. only returns +7 and 0)
Currently it uses a combination of merge and insert sort. Merge requires the allocation of additional memory.

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

general stable sort functions for arrays (modifying the array inline and returning it)

function stableSort(strArray: TStringArray; compareFunction: TPointerCompareFunction = nil; compareFunctionData: TObject=nil): TStringArray; overload;
 
function binarySearch(a,b: pointer; size: longint; compareFunction: TBinarySearchFunction = nil; compareFunctionData: TObject=nil; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): pointer;

General binary search function. It can find an element or a lower/upper bound.
a points to the first element in the (ascending, sorted) array, b to the last, size the size of each element
compareFunction is a TBinarySearchFunction comparing the searched element to another element
compareFunctionData is the data passed to the comparison function as first argument (you can think of it as searched element)
choosen is the element that should be returned, if there are multiple matches (bsFirst, bsLast or bsAny) .
condition the comparison relation between the returned and searched element (E.g. for [bsGreater, bsEqual] the returned element satisfies compareFunction(reference, returned) <= 0.)
returns a pointer to the found match or nil if there is none.
(note that you can combine, e.g. bsGreater and bsLast, which will always return the last element, unless all are lower)

Beware of the pointers. You need to be very carefully. a and b point to the first and last elements. They are not the element, they are pointers to the location of the element in the array. If a = b, the array has one element. You need to pass a < b for empty arrays.
The first parameter of compareFunction is user defined data, so it can be anything. The second parameter is a pointer to the location of an array element. It is not the array element itself, not even on a list of pointers.
The same holds for the pointer returned by the function, i.e. it is like that second parameter.

function eUTF8: TSystemCodePage;
 
function eWindows1252: TSystemCodePage;
 
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: array of string):longint; overload;

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

procedure arrayPrepend(var a: TStringArray; const e: string); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnordered(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); overload;

Ensures that a has at least reserveLength elements

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

returns i with a[i]=e

procedure arrayPrependFast(var a: TStringArray; var len: longint; const e: string); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnorderedFast(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]

procedure arrayInsert(var a: TStringArray; i: longint; const e: string); overload;

Inserts element e at position i in a

procedure arrayInsertFast(var a: TStringArray; var len: longint; i: longint; const e: string); overload;

Inserts element e at position i in a

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

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

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

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

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

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

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

Tests if element e exists 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; overload;

Extracts a array slice

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

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; overload;

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

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

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: array of longint):longint; overload;

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

procedure arrayPrepend(var a: TLongintArray; const e: longint); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnordered(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); overload;

Ensures that a has at least reserveLength elements

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

returns i with a[i]=e

procedure arrayPrependFast(var a: TLongintArray; var len: longint; const e: longint); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnorderedFast(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]

procedure arrayInsert(var a: TLongintArray; i: longint; const e: longint); overload;

Inserts element e at position i in a

procedure arrayInsertFast(var a: TLongintArray; var len: longint; i: longint; const e: longint); overload;

Inserts element e at position i in a

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

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

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

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

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

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

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

Tests if element e exists 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; overload;

Extracts a array slice

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

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; overload;

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

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

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: array of longword):longint; overload;

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

procedure arrayPrepend(var a: TLongwordArray; const e: longword); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnordered(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); overload;

Ensures that a has at least reserveLength elements

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

returns i with a[i]=e

procedure arrayPrependFast(var a: TLongwordArray; var len: longint; const e: longword); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnorderedFast(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]

procedure arrayInsert(var a: TLongwordArray; i: longint; const e: longword); overload;

Inserts element e at position i in a

procedure arrayInsertFast(var a: TLongwordArray; var len: longint; i: longint; const e: longword); overload;

Inserts element e at position i in a

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

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

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

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

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

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

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

Tests if element e exists 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; overload;

Extracts a array slice

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

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; overload;

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

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

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: array of int64):longint; overload;

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

procedure arrayPrepend(var a: TInt64Array; const e: int64); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnordered(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); overload;

Ensures that a has at least reserveLength elements

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

returns i with a[i]=e

procedure arrayPrependFast(var a: TInt64Array; var len: longint; const e: int64); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnorderedFast(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]

procedure arrayInsert(var a: TInt64Array; i: longint; const e: int64); overload;

Inserts element e at position i in a

procedure arrayInsertFast(var a: TInt64Array; var len: longint; i: longint; const e: int64); overload;

Inserts element e at position i in a

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

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

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

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

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

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

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

Tests if element e exists 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; overload;

Extracts a array slice

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

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; overload;

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

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

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: array of float):longint; overload;

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

procedure arrayPrepend(var a: TFloatArray; const e: float); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnordered(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); overload;

Ensures that a has at least reserveLength elements

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

returns i with a[i]=e

procedure arrayPrependFast(var a: TFloatArray; var len: longint; const e: float); overload;

Prepends e to a, i.e. inserts e at position 0. (Quite slow, O(n))

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

Removes element at position i from a
Returns e=a[i]

function arrayDeleteUnorderedFast(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]

procedure arrayInsert(var a: TFloatArray; i: longint; const e: float); overload;

Inserts element e at position i in a

procedure arrayInsertFast(var a: TFloatArray; var len: longint; i: longint; const e: float); overload;

Inserts element e at position i in a

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

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

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

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

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

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

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

Tests if element e exists 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; overload;

Extracts a array slice

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

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; overload;

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

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

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; overload;

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

function unequal(const a, b: RawByteString): boolean; overload;

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

function unequal(const a: array of RawByteString): boolean; overload;

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

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

Checks if all elements are pairwise unequal

function strBetween(const s, from, till: RawByteString): RawByteString;

If the string s has the form '...fromMIDDLEtill...' it returns 'MIDDLE'

function strBefore(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form 'STARTsep...' it returns 'START'

function strAfter(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form '...sepEND' it returns 'END'

function strBeforeLast(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form 'STARTsep...' it returns 'START'

function strAfterLast(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form '...sepEND' it returns 'END'

function striBetween(const s, from, till: RawByteString): RawByteString;

If the string s has the form '...fromMIDDLEtill...' it returns 'MIDDLE'

function striBefore(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form 'STARTsep...' it returns 'START'

function striAfter(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form '...sepEND' it returns 'END'

function striBeforeLast(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form 'STARTsep...' it returns 'START'

function striAfterLast(const s, sep: RawByteString): RawByteString; overload;

If the string s has the form '...sepEND' it returns 'END'

function intSqrt(const i: longint): longint; overload;
 
function intSqrt(const i: int64): int64; overload;
 
function modPow(i, e, m: longint): longint; overload;

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

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

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

function intBound(min, i, max: int64): int64; overload;
 
function arrayBinarySearch(a: TStringArray; const value: string; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;

Binary search in a string array

a the ascending, sorted array
value the searched reference value
choosen which value it should return, if there are multiple possible matches
condition how the reference value should be compared with the values in the array (e.g. [bsGreater, bsEqual] will only return a match that is greater-or-equal-than value) returns the index of the found match or -1 if there is no match

function arrayBinarySearch(a: TLongintArray; const value: longint; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;

Binary search in a longint array

a the ascending, sorted array
value the searched reference value
choosen which value it should return, if there are multiple possible matches
condition how the reference value should be compared with the values in the array (e.g. [bsGreater, bsEqual] will only return a match that is greater-or-equal-than value) returns the index of the found match or -1 if there is no match

function arrayBinarySearch(a: TLongwordArray; const value: longword; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;

Binary search in a longword array

a the ascending, sorted array
value the searched reference value
choosen which value it should return, if there are multiple possible matches
condition how the reference value should be compared with the values in the array (e.g. [bsGreater, bsEqual] will only return a match that is greater-or-equal-than value) returns the index of the found match or -1 if there is no match

function arrayBinarySearch(a: TInt64Array; const value: int64; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;

Binary search in a int64 array

a the ascending, sorted array
value the searched reference value
choosen which value it should return, if there are multiple possible matches
condition how the reference value should be compared with the values in the array (e.g. [bsGreater, bsEqual] will only return a match that is greater-or-equal-than value) returns the index of the found match or -1 if there is no match

function arrayBinarySearch(a: TFloatArray; const value: float; choosen: TBinarySearchChoosen = bsAny; condition: TBinarySearchAcceptedConditions = [bsEqual]): integer; overload;

Binary search in a float array

a the ascending, sorted array
value the searched reference value
choosen which value it should return, if there are multiple possible matches
condition how the reference value should be compared with the values in the array (e.g. [bsGreater, bsEqual] will only return a match that is greater-or-equal-than value) returns the index of the found match or -1 if there is no match

procedure ignore(const intentionallyUnusedParameter: string); overload;

Ignores the parameter to suppress warnings

procedure ignore(const intentionallyUnusedParameter: boolean); overload;

Ignores the parameter to suppress warnings

procedure ignore(const intentionallyUnusedParameter: integer); overload;

Ignores the parameter to suppress warnings

procedure ignore(const intentionallyUnusedParameter: Int64); overload;

Ignores the parameter to suppress warnings

procedure ignore(const intentionallyUnusedParameter: TObject); overload;

Ignores the parameter to suppress warnings

procedure ignore(const intentionallyUnusedParameter: pointer); overload;

Ignores the parameter to suppress warnings

Types

float = extended;
 
TTime = TDateTime;
 
SizeInt = integer;
 
TValueSign = -1..1;
 
RawByteString = ansistring;
 
UnicodeString = WideString;
 
PUnicodeChar = ˆWideChar;
 
TSystemCodePage = Word;
 
TStringArray=array of string;
 
TLongintArray =array of longint;
 
TLongwordArray =array of longword;
 
TInt64Array =array of int64;
 
TFloatArray = array of float;
 
TCharSet = set of ansichar;
 
TProcedureOfObject = procedure () of object;
 
TStreamLikeWrite = procedure(const Buffer; Count: Longint) of object;
 
TFileSaveSafe = procedure (stream: TStream; data: pointer);
 
TDateTimeParsingFlag = (...);
 
Values
  • dtpfStrict:  
TDateTimeParsingFlags = set of TDateTimeParsingFlag;
 
TDateTimeParsingResult = (...);
 
Values
  • dtprSuccess:  
  • dtprFailureValueTooHigh:  
  • dtprFailureValueTooHigh2:  
  • dtprFailure:  
TPointerCompareFunction = function (data: TObject; a, b: pointer): longint;

Compare function to compare the two values to which a and b, ideally returning -1 for aˆ<bˆ, 0 for aˆ=bˆ, +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

TBinarySearchChoosen = (...);
 
Values
  • bsAny:  
  • bsFirst:  
  • bsLast:  
TBinarySearchAcceptedCondition = (...);
 
Values
  • bsLower:  
  • bsEqual:  
  • bsGreater:  
TBinarySearchAcceptedConditions = set of TBinarySearchAcceptedCondition;
 
TBinarySearchFunction = function (data: TObject; a: pointer): longint;

Should return 0 if the searched element is equal to a, -1 if the searched element is smaller than a, and +1 if the searched element is larger than a. (that is the opposite of what you might expect, but it is logical: the data parameter has to come first to match a method signature. The data parameter is compared to a parameter (to match a standalone comparison function signature))

Constants

NaN = 0.0/0.0;
 
Infinity = 1.0/0.0;
 
NegInfinity = -1.0/0.0;
 
LineEnding = #13#10;
 
CP_UTF16 = 1200;
 
CP_UTF16BE = 1201;
 
CP_UTF8 = 65001;
 
CP_NONE = $FFFF;
 
CP_ASCII = 20127;
 
CP_UTF32 = 12000;
 
CP_UTF32BE = 12001;
 
CP_WINDOWS1252 = 1252;
 
CP_LATIN1 = 28591;
 
powersOf10: array[0..9] of longint = (1,10,100,1000,10000,100000,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.14.0.