Substr Unit

High Performance string processing library.

Allows for linear scaling with thread count and includes AVX2, AVX512 optimized kernels. The speed-up on single threaded code ranges from 3-100x, while multi-threading on 16 cores would add another factor of ~13x. A total speed-up of 100x is not considered a rarity and 1000x is relatively easily possible.

Functions

NameDescription
AnsiQuotedStrS in Quote, every Quote inside doubled.
BoolToStr'-1' for True, '0' for False.
CheckMemoryAllocCountThe calling thread's heap calls - GetMem, AllocMem, ReallocMem and FreeMem - since its last MarkMemoryAllocCount, or since the thread started if it never set one.
FloatToStrThe text of Value with up to 15 significant digits, correctly rounded.
FloatToStrF (4)Value as text in Format, its digits correctly rounded.
FmtStr (2)Writes Args into Result by the format text Format, with the format settings given or FormatSettings.
Format (2)The format text with Args written into it, as Substring.Format.
GetSubstringA view of SrcLen characters of Src from SrcIdx (1-based), copying none: Subrange as a function.
InstallMemoryAllocCountPuts the counting manager in front of the memory manager in use: from then on the counts see every heap call.
IntToStr (2)The decimal text of Value.
IsDelimiterWhether the character at Index (1-based) is one of Delimiters.
LastDelimiterThe 1-based position of the last character that is one of Delimiters, 0 when there is none.
LeftStrThe first ACount characters of AText.
LiveMemoryBlocksProcess-wide: the blocks allocated (GetMem, AllocMem) minus the blocks freed (FreeMem) while the counting manager was installed.
MarkMemoryAllocCountSets the calling thread's mark: its counts start from zero.
MemoryAllocCountThe calling thread's heap calls since its last MarkMemoryAllocCount, by kind.
MidStrACount characters of AText from AStart (1-based).
PosThe 1-based position of SubStr in Str at or after Offset, 0 if none.
PosExThe 1-based position of SubStr in S at or after Offset, 0 if none.
ProcessMemoryAllocCountProcess-wide: the heap calls of every thread - GetMem, AllocMem, ReallocMem and FreeMem - while the counting manager was installed.
QuotedStrS in apostrophes, every apostrophe inside doubled.
RemoveMemoryAllocCountTakes the counting manager out: the memory manager it stood in front of serves every call, uncounted.
RightStrThe last ACount characters of AText.
SplitStringSplits S into List at every character of Delimiters, the empty parts included.
StringOfCharCount times Ch.
StrToBoolConverts S to a Boolean by ToBoolean's rules.
StrToFloatConverts S to a Double by ToDouble's rules, correctly rounded.
StrToIntConverts S to an Integer by ToInteger's rules.
StrToInt64Converts S to an Int64 by ToInt64's rules.
TrimSrc without the characters <= ' ' at both ends.
TrimLeftSrc without the characters <= ' ' at its start.
TrimRightSrc without the characters <= ' ' at its end.
UniqueStringGives Str its own copy of its characters, shared with no other string.

Variables

NameTypeInitial valueDescription
SubstringAllocCheckBooleanFalse

True: an operation that would take memory from the memory manager outside Capacity and Resize raises ESubstringAllocError. False, the default: it allocates.

Classes

NameDescription
TSubstringListA list of Substrings kept in rows, each row a whole Substring.
TSubstringListAsciiTSubstringList comparing items with 'a'..'z' folded to upper case unless CaseSensitive is True.
TSubstringListInvariantTSubstringList comparing items with case ignored by the operating system's uppercase table, unless CaseSensitive is True.
TSubstringListLinguisticTSubstringList comparing items by the rules of the default locale or of LocaleID, case ignored unless CaseSensitive is True.

Records

NameDescription
SubstringA UTF-16 string for local variables, designed for allocation-free string operations that scale linearly with the thread count.
TMemoryAllocCountThe calling thread's heap calls since its last MarkMemoryAllocCount, by kind, as MemoryAllocCount returns them.
TSubstringListEnumeratorEnumerates the list's items in order, each read in place.
TSubstringThreadStatsThe counters of the calling thread's memory for long texts, as Substring.ThreadStats returns them.

Types

NameDescription
PSubstringA pointer to a Substring: TSubstringList.Items gives one, the list's item itself.

Events

NameDescription
TSubstringListSortCompareA custom order for CustomSort and Sort: negative when Item1 sorts before Item2, 0 when they are equal, positive when it sorts after.

Exceptions

NameDescription
ESubstringAllocErrorMemory an operation would take from the memory manager while SubstringAllocCheck is True, outside Capacity and Resize.
ESubstringCaseErrorA routine that compares by code unit was asked to ignore case: Replace with rfIgnoreCase.
ESubstringEncodingErrorAn AnsiString, UTF8String, RawByteString, ShortString, AnsiChar or PAnsiChar argument.
ESubstringErrorThe base class of the exceptions Substring raises.
ESubstringInPlaceErrorA write after the text on characters the string does not own alone.
ESubstringRangeErrorAn index, a count or a window outside the text.
ESubstringThreadErrorA failed system call that prepares a thread's memory for long texts; in a build that defines SUBSTRING_STRICT_OWNER, also a long text of another thread used without a copy.