template<typename TChar,
integer TCapacity>
class alib::strings::TLocalString< TChar, TCapacity >
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 de-allocation of heap memory 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 on the heap (using keyword new
), still some performance improvements apply, because 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 heap, 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 to foresee a maximum buffer size, the warning has to be disabled by invoking DbgDisableBufferReplacementWarning .
For more information on warnings, see AString::SetBuffer .
- Note
- For commonly used sizes and character types, some convenient typedefs exists in namespace alib. 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.
Alias names for specializations of this class using character types character , nchar , wchar , xchar , complementChar and strangeChar 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. |
Definition at line 65 of file localstring.hpp.
|
constexpr | TLocalString () |
|
template<class TAppendable > |
| TLocalString (const TAppendable &src) |
|
| TLocalString (const TLocalString ©) |
|
| TLocalString (TLocalString &&move) noexcept |
|
TLocalString & | operator= (const TLocalString ©) |
|
TLocalString & | operator= (TLocalString &&move) |
|
constexpr | TAString () |
|
| TAString (const TAString ©) |
|
| TAString (TAString &&move) noexcept |
|
template<class TAppendable > |
| TAString (const TAppendable &src) |
|
| ~TAString () noexcept |
|
template<typename TCharArray > |
| operator TCharArray () const |
|
template<typename TCharArray > |
| operator TCharArray () const |
|
TAString & | operator= (const TAString ©) |
|
ALIB_API void | SetBuffer (integer newCapacity) |
|
ALIB_API void | SetBuffer (TChar *extBuffer, integer extBufferSize, integer extLength=0, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender) |
|
void | EnsureRemainingCapacity (integer spaceNeeded) |
|
void | GrowBufferAtLeastBy (integer minimumGrowth) |
|
integer | Capacity () const |
|
bool | HasInternalBuffer () const |
|
void | SetNull () |
|
const TChar * | Terminate () const |
|
TChar * | VBuffer () const |
|
template<bool TCheck = true> |
void | SetCharAt (integer idx, TChar c) |
|
TChar & | operator[] (integer idx) |
|
void | SetLength (integer newLength) |
|
void | DetectLength () |
|
TAString & | ShortenTo (integer newLength) |
|
template<bool TCheck = true, typename TCharSrc > |
TAString & | Append (const TCharSrc *src, integer srcLength) |
|
template<bool TCheck = true> |
TAString & | Append (const TChar *src, integer srcLength) |
|
template<bool TCheck = true> |
TAString & | Append (const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN) |
|
template<bool TCheck = true> |
TAString & | _ (const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN) |
|
TAString & | NewLine () |
|
template<bool TCheck = true, typename TAppendable > |
TAString & | Append (const TAppendable &src) |
|
template<bool TCheck = true, class TAppendable > |
TAString & | _ (const TAppendable &src) |
|
template<class TAppendable > |
TAString & | operator<< (const TAppendable &src) |
|
TAString & | Reset () |
|
template<bool TCheck = true, typename TAppendable > |
TAString & | Reset (const TAppendable &src) |
|
TAString & | _ () |
|
template<bool TCheck = true> |
TAString & | InsertAt (const TString< TChar > &src, integer pos) |
|
template<bool TCheck = true> |
TAString & | InsertChars (TChar c, integer qty) |
|
template<bool TCheck = true> |
TAString & | InsertChars (TChar c, integer qty, integer pos) |
|
template<bool TCheck = true> |
TAString & | Delete (integer regionStart, integer regionLength=MAX_LEN) |
|
template<bool TCheck = true> |
TAString & | DeleteStart (integer regionLength) |
|
template<bool TCheck = true> |
TAString & | DeleteEnd (integer regionLength) |
|
ALIB_API TAString & | Trim (const TCString< TChar > &trimChars=TT_StringConstants< TChar >::DefaultWhitespaces()) |
|
ALIB_API integer | TrimAt (integer idx, const TCString< TChar > &trimChars=TT_StringConstants< TChar >::DefaultWhitespaces()) |
|
TAString & | TrimStart (const TCString< TChar > &trimChars=TT_StringConstants< TChar >::DefaultWhitespaces()) |
|
TAString & | TrimEnd (const TCString< TChar > &trimChars=TT_StringConstants< TChar >::DefaultWhitespaces()) |
|
template<bool TCheck = true> |
TAString & | ReplaceSubstring (const TString< TChar > &src, integer regionStart, integer regionLength) |
|
template<bool TCheck = true> |
TAString & | ReplaceRegion (TChar c, integer regionStart, integer regionLength) |
|
ALIB_API integer | SearchAndReplace (TChar needle, TChar replacement, integer startIdx=0) |
|
ALIB_API integer | SearchAndReplace (const TString< TChar > &needle, const TString< TChar > &replacement, integer startIdx=0, integer maxReplacements=MAX_LEN, lang::Case sensitivity=lang::Case::Sensitive) |
|
template<bool TCheck = true> |
TAString & | ToUpper (integer regionStart=0, integer regionLength=MAX_LEN) |
|
template<bool TCheck = true> |
TAString & | ToLower (integer regionStart=0, integer regionLength=MAX_LEN) |
|
template<bool TCheck = true> |
TAString & | Reverse (integer regionStart=0, integer regionLength=MAX_LEN) |
|
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE Iterator | begin () |
|
Iterator | end () |
|
ALIB_WARNINGS_RESTORE ReverseIterator | rbegin () |
|
ReverseIterator | rend () |
|
void | dbgCheck () const |
|
void | DbgDisableBufferReplacementWarning () |
|
constexpr | TString () noexcept=default |
|
constexpr | TString (const TString &) noexcept=default |
|
constexpr | TString (TString &&) noexcept=default |
|
TString & | operator= (const TString &) noexcept=default |
|
TString & | operator= (TString &&) noexcept=default |
|
constexpr | TString (const TChar *pBuffer, integer pLength) noexcept |
|
template<typename TCharArray > |
constexpr | TString (const TCharArray &src) |
|
template<typename TCharArray > |
| operator TCharArray () const |
|
template<typename TCharArray > |
| operator TCharArray () const |
|
template<bool TCheck = true> |
TString< TChar > | Substring (integer regionStart, integer regionLength=MAX_LEN) const |
|
constexpr const TChar * | Buffer () const |
|
constexpr integer | Length () const |
|
integer | WStringLength () const |
|
constexpr bool | IsNull () const |
|
constexpr bool | IsNotNull () const |
|
constexpr bool | IsEmpty () const |
|
constexpr bool | IsNotEmpty () const |
|
template<bool TCheck = true> |
TChar | CharAt (integer idx) const |
|
template<bool TCheck = true> |
TChar | CharAtStart () const |
|
template<bool TCheck = true> |
TChar | CharAtEnd () const |
|
TChar | operator[] (integer idx) const |
|
std::size_t | Hashcode () const |
|
std::size_t | HashcodeIgnoreCase () const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
bool | Equals (const TString< TChar > &rhs) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
int | CompareTo (const TString< TChar > &rhs) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
int | CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength=MAX_LEN) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
int | CompareTo (const TString &rhs, integer rhsRegionStart, integer rhsRegionLength, integer regionStart, integer regionLength=MAX_LEN) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
bool | ContainsAt (const TString &needle, integer pos) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
bool | StartsWith (const TString &needle) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
bool | EndsWith (const TString &needle) const |
|
template<bool TCheck = true> |
integer | IndexOf (TChar needle, integer startIdx=0) const |
|
template<bool TCheck = true> |
integer | IndexOf (TChar needle, integer regionStart, integer regionLength) const |
|
integer | IndexOfOrLength (TChar needle) const |
|
template<bool TCheck = true> |
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer | IndexOfOrLength (TChar needle, integer startIdx) const |
|
template<bool TCheck = true> |
ALIB_WARNINGS_RESTORE integer | LastIndexOf (TChar needle, integer startIndex=MAX_LEN) const |
|
template<lang::Inclusion TInclusion, bool TCheck = true> |
integer | IndexOfAny (const TString &needles, integer startIdx=0) const |
|
template<lang::Inclusion TInclusion, bool TCheck = true> |
integer | LastIndexOfAny (const TString &needles, integer startIdx=MAX_LEN) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
integer | IndexOf (const TString &needle, integer startIdx=0) const |
|
template<bool TCheck = true> |
integer | IndexOfFirstDifference (const TString &needle, lang::Case sensitivity=lang::Case::Sensitive, integer idx=0) const |
|
integer | IndexOfSegmentEnd (TChar opener, TChar closer, integer idx) const |
|
template<bool TCheck = true> |
integer | CountChar (TChar needle, integer startPos=0) const |
|
template<bool TCheck = true> |
integer | CountChar (TChar needle, TChar omit, integer startPos) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
integer | Count (const TString &needle, integer startPos=0) const |
|
template<bool TCheck = true, lang::Case TSensitivity = lang::Case::Sensitive> |
integer | Count (const TString &needle, const TString &omit, integer startPos=0) const |
|
ALIB_API uint64_t | ParseDecDigits (integer startIdx=0, integer *newIdx=nullptr) const |
|
ALIB_API int64_t | ParseInt (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
|
int64_t | ParseInt (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
|
int64_t | ParseInt (integer *newIdx) const |
|
int64_t | ParseInt (integer startIdx, integer *newIdx) const |
|
ALIB_API 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 | ParseDec (integer *newIdx) const |
|
uint64_t | ParseDec (integer startIdx, integer *newIdx) const |
|
ALIB_API 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 | ParseBin (integer *newIdx) const |
|
uint64_t | ParseBin (integer startIdx, integer *newIdx) const |
|
ALIB_API uint64_t | ParseHex (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
|
uint64_t | ParseHex (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
|
uint64_t | ParseHex (integer *newIdx) const |
|
uint64_t | ParseHex (integer startIdx, integer *newIdx) const |
|
ALIB_API uint64_t | ParseOct (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
|
uint64_t | ParseOct (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
|
uint64_t | ParseOct (integer *newIdx) const |
|
uint64_t | ParseOct (integer startIdx, integer *newIdx) const |
|
ALIB_API double | ParseFloat (integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const |
|
double | ParseFloat (TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const |
|
double | ParseFloat (integer *newIdx) const |
|
double | ParseFloat (integer startIdx, integer *newIdx) const |
|
integer | CopyTo (TChar *dest) const |
|
bool | AdjustRegion (integer ®ionStart, integer ®ionLength) const |
|
ConstIterator | begin () const |
|
ConstIterator | cbegin () const |
|
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE ConstIterator | end () const |
|
ConstIterator | cend () const |
|
ALIB_WARNINGS_RESTORE ConstReverseIterator | rbegin () const |
|
ConstReverseIterator | rend () const |
|
ConstReverseIterator | crbegin () const |
|
ConstReverseIterator | crend () const |
|
| TString (ConstIterator &start, ConstIterator &end) |
|