template<typename TChar,
integer TCapacity, typename TAllocator = lang::HeapAllocator>
class alib::strings::TLocalString< TChar, TCapacity, TAllocator >
This type specializes class AString by adding a character array member of templated size which is used as the "external" string buffer. The single motivation for the use of this class is performance optimization.
Assembled character strings often have a rather short lifetime and are disposed quickly after their usage. If the maximum length of the assembled string is known, such strings may be created as local values of this type, with that maximum length given as template parameter TCapacity. With that, the allocation and deallocation of heap memory (or whatever is used with the provided allocator) for the string is omitted and allocation and destruction of the local string is performed in constant time O(1).
But even if an instance of this class is allocated (instead of being a local variable on the stack), in common cases, still a performance improvement applies. This is due to the fact that besides the class object itself, no second memory allocation for the string buffer is performed.
If during the use of an instance of this class the buffer's fixed TCapacity is exceeded, a new buffer is allocated from the given allocator, just as it is always done with growing strings managed in AString objects. This means, the use of this class is safe and no restrictions apply. Of course, if possible, for performance-critical code sections, the predefined size TCapacity should be chosen large enough to allow the internal buffer to survive the use.
With debug-builds of ALib, parent class AString optionally (and by default) raises a warning if an external buffer is replaced by a new (heap) allocation. (Note that from an AString perspective, this class's internal field buffer is an external character array). With use cases that do not allow foreseeing a maximum buffer size, the warning has to be disabled by invoking DbgDisableBufferReplacementWarning.
For more information on warnings, see SetBuffer(integer).
With the provision of an assignment operator, the explicit restriction of parent class to not allow assignments is lifted with this type.
- Note
- For commonly used sizes and character types, some convenient typedefs exists in namespace alib, which use HeapAllocator. These type definitions are:
- String8, String16, String32 ... String1K, String2K, String4K,
- NString8, NString16, NString32 ... NString1K, NString2K, NString4K, and
- WString8, WString16, WString32 ... WString1K, WString2K, WString4K.
- Template Parameters
-
| TChar | The character type of this string. Alias names for specializations of this class are provided in namespace alib with type definitions LocalString<TCapacity>, NLocalString<TCapacity>, WLocalString<TCapacity>, XLocalString<TCapacity>, ComplementLocalString<TCapacity> and StrangeLocalString<TCapacity>. |
| TCapacity | The capacity of the string buffer allocated locally "inside" the class. |
| TAllocator | The allocator type to use. Defaults to HeapAllocator. |
Definition at line 63 of file localstring.inl.
|
| constexpr | TLocalString () |
| template<typename TAppendable> |
| | TLocalString (const TAppendable &src) |
| | TLocalString (const TLocalString ©) |
| constexpr | TLocalString (TAllocator &pAllocator) |
| | TLocalString (TLocalString &&move) noexcept |
| template<typename TAppendable> |
| TLocalString & | operator= (const TAppendable &src) |
| TLocalString & | operator= (const TLocalString ©) |
| TLocalString & | operator= (TLocalString &&move) |
| | ~TAString () noexcept |
| | Destructs an AString object. An internally allocated buffer will be deleted.
|
| TAString & | _ (const TAppendable &src) |
| TAString & | Append (const TCharSrc *src, integer srcLength) |
| const_iterator | begin () const |
| integer | Capacity () const |
| void | dbgCheck () const |
| void | DbgDisableBufferReplacementWarning () |
| TAString & | Delete (integer regionStart, integer regionLength=MAX_LEN) |
| TAString & | DeleteEnd (integer regionLength) |
| TAString & | DeleteStart (integer regionLength) |
| integer | DetectLength (integer offset=0) |
| const_iterator | end () const |
| void | EnsureRemainingCapacity (integer spaceNeeded) |
| void | GrowBufferAtLeastBy (integer minimumGrowth) |
| bool | HasInternalBuffer () const |
| TAString & | InsertAt (const TString< TChar > &src, integer pos) |
| TAString & | InsertChars (TChar c, integer qty) |
| TAString & | InsertUninitialized (integer pos, integer size) |
| TAString & | NewLine () |
| constexpr | operator T () const |
| TAString & | operator+= (const TAppendable &src) |
| TAString & | operator<< (const TAppendable &src) |
| TAString & | operator= (const TAString ©) |
| TChar | operator[] (integer idx) const |
| constexpr TChar | pop_back () |
| constexpr void | push_back (TChar ch) |
| const_reverse_iterator | rbegin () const |
| const_reverse_iterator | rend () const |
| TAString & | ReplaceRegion (TChar c, integer regionStart, integer regionLength) |
| TAString & | ReplaceSubstring (const TString< TChar > &src, integer regionStart, integer regionLength) |
| TAString & | Reset () |
| TAString & | Reverse (integer regionStart=0, integer regionLength=MAX_LEN) |
| integer | SearchAndReplace (TChar needle, TChar replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN) |
| void | SetBuffer (integer newCapacity) |
| void | SetCharAt (integer idx, TChar c) |
| void | SetLength (integer newLength) |
| void | SetNull () |
| | Invokes SetBuffer(0).
|
| TAString & | ShortenBy (integer charsToRemove) |
| TAString & | ShortenTo (integer newLength) |
| constexpr const TChar * | Terminate () const |
| TAString & | ToLower (integer regionStart=0, integer regionLength=MAX_LEN) |
| TAString & | ToUpper (integer regionStart=0, integer regionLength=MAX_LEN) |
| TAString & | Trim (const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces()) |
| integer | TrimAt (integer idx, const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces()) |
| TAString & | TrimEnd (const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces()) |
| TAString & | TrimStart (const TCString< TChar > &trimChars=CStringConstantsTraits< TChar >::DefaultWhitespaces()) |
| TChar * | VBuffer () const |
| constexpr | TString () noexcept=default |
| template<typename T> |
| constexpr | TString (const T &src) noexcept |
| constexpr | TString (const TChar *pBuffer, integer pLength) noexcept |
|
constexpr | TString (const TString &) noexcept=default |
| | Defaulted copy constructor.
|
| | TString (const_iterator &start, const_iterator &end) |
| constexpr | TString (lang::IsNullptr auto const &) noexcept |
| | Constructor accepting nullptr. Constructs a nulled string.
|
| template<typename T> |
| constexpr | TString (T &src) noexcept |
| template<typename TAllocator> |
| | TString (TAllocator &allocator, const TString< TChar > ©) |
|
constexpr | TString (TString &&) noexcept=default |
| | Defaulted move constructor.
|
| bool | AdjustRegion (integer ®ionStart, integer ®ionLength) const |
| template<typename TAllocator> |
| void | Allocate (TAllocator &allocator, const TString< TChar > ©) |
| const_iterator | begin () const |
| constexpr const TChar * | Buffer () const |
| const_iterator | cbegin () const |
| const_iterator | cend () const |
| template<typename TCheck = CHK> |
| TChar | CharAt (integer idx) const |
| template<typename TCheck = CHK> |
| TChar | CharAtEnd () const |
| template<typename TCheck = CHK> |
| TChar | CharAtStart () const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| int | CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength, integer regionStart, integer regionLength=MAX_LEN) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| int | CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength=MAX_LEN) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| int | CompareTo (const TString< TChar > &rhs) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| bool | ContainsAt (const TString &needle, integer pos) const |
| integer | CopyTo (TChar *dest) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| integer | Count (const TString &needle, const TString &omit, integer startPos=0) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| integer | Count (const TString &needle, integer startPos=0) const |
| template<typename TCheck = CHK> |
| integer | CountChar (TChar needle, integer startPos=0) const |
| template<typename TCheck = CHK> |
| integer | CountChar (TChar needle, TChar omit, integer startPos) const |
| const_reverse_iterator | crbegin () const |
| const_reverse_iterator | crend () const |
| const_iterator | end () const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| bool | EndsWith (const TString &needle) const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| bool | Equals (const TString< TChar > &rhs) const |
| template<typename TAllocator> |
| void | Free (TAllocator &allocator) |
| std::size_t | Hashcode () const |
| std::size_t | HashcodeIgnoreCase () const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| integer | IndexOf (const TString &needle, integer startIdx=0, integer endIdx=strings::MAX_LEN) const |
| template<typename TCheck = CHK> |
| integer | IndexOf (TChar needle, integer regionStart, integer regionLength) const |
| template<typename TCheck = CHK> |
| integer | IndexOf (TChar needle, integer startIdx=0) const |
| template<lang::Inclusion TInclusion, typename TCheck = CHK> |
| integer | IndexOfAny (const TString &needles, integer startIdx=0) const |
| template<typename TCheck = CHK> |
| integer | IndexOfFirstDifference (const TString &needle, lang::Case sensitivity=lang::Case::Sensitive, integer startIdx=0) const |
| integer | IndexOfOrLength (TChar needle) const |
| template<typename TCheck = CHK> |
| integer | IndexOfOrLength (TChar needle, integer startIdx) const |
| integer | IndexOfSegmentEnd (TChar opener, TChar closer, integer idx) const |
| constexpr bool | IsEmpty () const |
| constexpr bool | IsNotEmpty () const |
| constexpr bool | IsNotNull () const |
| constexpr bool | IsNull () const |
| template<typename TCheck = CHK> |
| integer | LastIndexOf (TChar needle, integer startIndex=MAX_LEN) const |
| template<lang::Inclusion TInclusion, typename TCheck = CHK> |
| integer | LastIndexOfAny (const TString &needles, integer startIdx=MAX_LEN) const |
| constexpr integer | Length () const |
| template<typename T> |
| constexpr | operator T () const |
| constexpr TString & | operator= (const TString &) noexcept=default |
| constexpr TString & | operator= (TString &&) noexcept=default |
| TChar | operator[] (integer idx) const |
| uint64_t | ParseBin (integer *newIdx) const |
| uint64_t | ParseBin (integer startIdx, integer *newIdx) const |
| uint64_t | ParseBin (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| uint64_t | ParseBin (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| uint64_t | ParseDec (integer *newIdx) const |
| uint64_t | ParseDec (integer startIdx, integer *newIdx) const |
| uint64_t | ParseDec (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| uint64_t | ParseDec (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| uint64_t | ParseDecDigits (integer startIdx=0, integer *newIdx=nullptr) const |
| double | ParseFloat (integer *newIdx) const |
| double | ParseFloat (integer startIdx, integer *newIdx) const |
| double | ParseFloat (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| double | ParseFloat (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| uint64_t | ParseHex (integer *newIdx) const |
| uint64_t | ParseHex (integer startIdx, integer *newIdx) const |
| uint64_t | ParseHex (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| uint64_t | ParseHex (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| int64_t | ParseInt (integer *newIdx) const |
| int64_t | ParseInt (integer startIdx, integer *newIdx) const |
| int64_t | ParseInt (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| int64_t | ParseInt (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| uint64_t | ParseOct (integer *newIdx) const |
| uint64_t | ParseOct (integer startIdx, integer *newIdx) const |
| uint64_t | ParseOct (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
| uint64_t | ParseOct (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
| const_reverse_iterator | rbegin () const |
| const_reverse_iterator | rend () const |
| size_type | size () const |
| template<typename TCheck = CHK, lang::Case TSensitivity = lang::Case::Sensitive> |
| bool | StartsWith (const TString &needle) const |
| template<typename TCheck = CHK> |
| TString< TChar > | Substring (integer regionStart, integer regionLength=MAX_LEN) const |
| integer | WStringLength () const |
| | AllocatorMember () |
| AllocatorInterface< lang::HeapAllocator > | AI () const noexcept |
| lang::HeapAllocator & | GetAllocator () const noexcept |