8#ifndef HPP_ALIB_STRINGS_STRING
9#define HPP_ALIB_STRINGS_STRING 1
11#if !defined (HPP_ALIB) && !defined(ALIB_DOX)
15#if !defined(HPP_ALIB_STRINGS_FWDS)
19#if !defined (HPP_ALIB_CHARACTERS_CHARARRAY)
25#if !defined(HPP_ALIB_LANG_TMP) && !defined(ALIB_DOX)
30#if !defined (_GLIBCXX_ITERATOR) && !defined (_ITERATOR_)
38 #pragma warning( push )
39 #pragma warning( disable : 4127 )
42namespace alib {
namespace strings {
72template<
typename TChar>
84 #if ALIB_DEBUG_STRINGS
85 void dbgCheck()
const;
93 #if !defined(ALIB_DOX)
174 #if defined(ALIB_DOX)
193 template <
typename TCharArray>
211 template<
typename TCharArray>
213 operator TCharArray ()
const
229 template<
typename TCharArray>
231 operator TCharArray ()
const
237 std::is_same<std::nullptr_t,T>::value )
253 template <
typename T,
255 typename std::enable_if<v, int>::type = 0 >
313 template <
bool TCheck= true>
318 if constexpr ( TCheck )
329 "Non checking and region out of range or empty" )
436 template <
bool TCheck= true>
440 if constexpr (TCheck)
444 "Non checking version: Index out of range" )
458 template <
bool TCheck= true>
461 if constexpr (TCheck)
480 template <
bool TCheck= true>
484 if constexpr (TCheck)
571 template <
bool TCheck =
true,
577 if constexpr ( TCheck )
622 template <
bool TCheck =
true,
630 if (TCheck && rhs.
IsNull() )
return +1;
633 if ( TCheck &&
length == 0 )
return rhs.
length == 0 ? 0 : -1;
634 if ( rhs.
length == 0 )
return +1;
645 return thisIsShorter ? -1 : 1;
672 template <
bool TCheck =
true,
679 if constexpr ( TCheck )
683 cmpSub.
buffer+= rhsRegionStart;
684 cmpSub.
length= rhsRegionLength;
686 return CompareTo<true, TSensitivity>( cmpSub );
689 return CompareTo<false, TSensitivity>(
TString( rhs.
buffer + rhsRegionStart,
722 template <
bool TCheck =
true,
731 if constexpr ( TCheck )
735 cmpSub.
buffer+= rhsRegionStart;
736 cmpSub.
length= rhsRegionLength;
739 return TString(
buffer + regionStart, regionLength ).CompareTo<
true, TSensitivity>( cmpSub );
743 .CompareTo<
false, TSensitivity>(
TString( rhs.
buffer + rhsRegionStart,
768 template<
bool TCheck =
true,
774 if constexpr ( TCheck )
776 if ( pos < 0 || pos + needleLength >
length || needle.
IsNull () )
778 if ( needleLength == 0 )
784 "STRINGS",
"Non checking and index out of range" )
786 "STRINGS",
"Non checking and emtpy compare string" )
811 template<
bool TCheck =
true,
815 if constexpr ( TCheck )
825 "Non checking and needle longer than this string." )
827 "Non checking and emtpy needle given." )
845 template<
bool TCheck =
true,
849 if constexpr ( TCheck )
859 "Non checking and needle longer than this string." )
861 "Non checking and emtpy needle given." )
888 template <
bool TCheck= true>
893 if constexpr ( TCheck )
896 if ( startIdx < 0 ) startIdx= 0;
897 else if ( startIdx >=
length )
return -1;
903 "Non checking and index out of range" )
911 return result !=
nullptr ? result -
buffer
926 template <
bool TCheck= true>
931 if constexpr ( TCheck )
943 "STRINGS",
"Non checking and region out of range or empty" )
951 return result !=
nullptr ? result -
buffer
970 return result !=
nullptr ? result -
buffer
988 template <
bool TCheck= true>
992 if constexpr ( TCheck )
995 if ( startIdx < 0 ) startIdx= 0;
1001 "STRINGS",
"Non checking and index out of range" )
1005 return result !=
nullptr ? result -
buffer
1026 template <
bool TCheck= true>
1031 if constexpr ( TCheck )
1034 if ( startIndex < 0 )
return -1;
1040 "STRINGS",
"Non checking and index out of range" )
1044 while( startIndex >= 0 &&
buffer[ startIndex ] != needle )
1085 if constexpr (TCheck)
1087 if ( startIdx < 0 ) startIdx= 0;
1088 if ( startIdx >=
length )
return -1;
1093 "STRINGS",
"Non checking and illegal parameters" )
1103 return idx == -1 ? -1 : startIdx + idx;
1132 if constexpr (TCheck)
1134 if ( startIdx < 0 )
return -1;
1140 "STRINGS",
"Non checking and illegal parameters" )
1167 template<
bool TCheck =
true,
1172 if constexpr (TCheck)
1176 if ( startIdx < 0 ) startIdx= 0;
1182 "STRINGS",
"Non checking and illegal parameters" )
1186 return indexOfString<TSensitivity>(needle, startIdx);
1206 template <
bool TCheck= true>
1213 if constexpr ( TCheck )
1216 if ( idx < 0 ) idx= 0;
1217 else if ( idx >=
length )
return idx;
1222 "STRINGS",
"Non checking and index out of range" )
1269 template <
bool TCheck= true>
1274 if constexpr ( TCheck )
1277 if ( startPos < 0 ) startPos= 0;
1278 else if ( startPos >=
length )
return 0;
1283 "STRINGS",
"Non checking and index out of range" )
1288 while( startPos <
length && (startPos= IndexOf<false>( needle, startPos )) >= 0 )
1312 template <
bool TCheck= true>
1318 if constexpr ( TCheck )
1321 if ( startPos < 0 ) startPos= 0;
1322 else if ( startPos >=
length )
return 0;
1327 "STRINGS",
"Non checking and index out of range" )
1332 while( startPos <
length && (startPos= IndexOf<false>( needle, startPos )) >= 0 )
1335 if( startPos <
Length() && *(
buffer + startPos) == omit )
1361 template<
bool TCheck =
true,
1370 if constexpr (TCheck)
1372 if ( startPos < 0 ) startPos= 0;
1373 if ( startPos + nLen >
length )
return 0;
1378 "STRINGS",
"Non checking and illegal parameters" )
1382 while( (startPos= IndexOf<false, TSensitivity>( needle, startPos )) >= 0 )
1384 startPos+= needle.
Length();
1410 template<
bool TCheck =
true,
1420 if constexpr (TCheck)
1422 if ( startPos < 0 ) startPos= 0;
1423 if ( startPos + nLen >
length )
return 0;
1428 "STRINGS",
"Non checking and illegal parameters" )
1433 while( (startPos= IndexOf<false, TSensitivity>( needle, startPos )) >= 0 )
1438 || ContainsAt<false>( omit, startPos ) ) )
1497 integer* newIdx=
nullptr )
const;
1513 return ParseInt( 0, numberFormat, newIdx );
1529 return ParseInt( 0,
nullptr, newIdx );
1548 return ParseInt( startIdx,
nullptr, newIdx );
1582 integer* newIdx=
nullptr )
const;
1598 return ParseDec( 0, numberFormat, newIdx );
1614 return ParseDec( 0,
nullptr, newIdx );
1633 return ParseDec( startIdx,
nullptr, newIdx );
1663 integer* newIdx=
nullptr )
const;
1680 return ParseBin( 0, numberFormat, newIdx );
1696 return ParseBin( 0,
nullptr, newIdx );
1715 return ParseBin( startIdx,
nullptr, newIdx );
1745 integer* newIdx=
nullptr )
const;
1762 return ParseHex( 0, numberFormat, newIdx );
1778 return ParseHex( 0,
nullptr, newIdx );
1797 return ParseHex( startIdx,
nullptr, newIdx );
1827 integer* newIdx=
nullptr )
const;
1844 return ParseOct( 0, numberFormat, newIdx );
1860 return ParseOct( 0,
nullptr, newIdx );
1879 return ParseOct( startIdx,
nullptr, newIdx );
1909 integer* newIdx=
nullptr )
const;
1925 return ParseFloat( 0, numberFormat, newIdx );
1960 return ParseFloat( startIdx,
nullptr, newIdx );
1997 if (regionStart >=
length)
2005 if (regionStart < 0 )
2007 regionLength+= regionStart;
2012 if ( regionLength < 0 )
2019 if ( regionLength > maxRegionLength )
2020 regionLength= maxRegionLength;
2023 return regionLength == 0;
2041 template<
typename TCharConstOrMutable>
2054 TCharConstOrMutable*
p;
2085 return p == other.
p;
2093 return !(*
this == other);
2201 return p <= other.
p;
2220 return p >= other.
p;
2282 #if !defined(ALIB_DOX)
2293 template<lang::Case TSensitivity =lang::Case::Sensitive>
2297 #if !defined(ALIB_DOX)
2305#if defined(ALIB_DOX)
2364#elif ALIB_CPP_STANDARD < 20 || defined(_MSC_VER)
2366template<
typename TChar,
typename TCharArray>
bool operator== (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return lhs.
template Equals <true, lang::Case::Sensitive>(rhs); }
2367template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) )
operator== (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return rhs.
template Equals <true, lang::Case::Sensitive>(lhs); }
2368template<
typename TChar,
typename TCharArray>
bool operator!= (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return !lhs.
template Equals <true, lang::Case::Sensitive>(rhs); }
2369template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) )
operator!= (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return !rhs.
template Equals <true, lang::Case::Sensitive>(lhs); }
2371template<
typename TChar,
typename TCharArray>
bool operator< (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return lhs.
template CompareTo<true, lang::Case::Sensitive>(rhs) < 0; }
2372template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) ) operator< (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return rhs.
template CompareTo<true, lang::Case::Sensitive>(lhs) > 0; }
2373template<
typename TChar,
typename TCharArray>
bool operator<= (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return lhs.
template CompareTo<true, lang::Case::Sensitive>(rhs) <= 0; }
2374template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) ) operator<= (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return rhs.
template CompareTo<true, lang::Case::Sensitive>(lhs) >= 0; }
2375template<
typename TChar,
typename TCharArray>
bool operator> (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return lhs.
template CompareTo<true, lang::Case::Sensitive>(rhs) > 0; }
2376template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) ) operator> (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return rhs.
template CompareTo<true, lang::Case::Sensitive>(lhs) < 0; }
2377template<
typename TChar,
typename TCharArray>
bool operator>= (
const TString<TChar>& lhs,
const TCharArray& rhs) {
return lhs.
template CompareTo<true, lang::Case::Sensitive>(rhs) >= 0; }
2378template<
typename TChar,
typename TCharArray>
ATMP_T_IF(
bool, !
ATMP_ISOF(TCharArray, TString<TChar>) ) operator>= (
const TCharArray& lhs,
const TString<TChar>& rhs) {
return rhs.
template CompareTo<true, lang::Case::Sensitive>(lhs) <= 0; }
2404template<
typename TChar>
2409 TChar* buf=
new TChar[
static_cast<size_t>(src.
Length())];
2422template<
typename TChar>
2426 delete[]
string.Buffer();
2433#if !defined(ALIB_DOX)
2436extern template ALIB_API integer TString<nchar>::indexOfString<lang::Case::Sensitive>(
const TString<nchar >&,
integer )
const;
2437extern template ALIB_API integer TString<nchar>::indexOfString<lang::Case::Ignore >(
const TString<nchar >&,
integer )
const;
2450extern template ALIB_API integer TString<wchar>::indexOfString<lang::Case::Sensitive>(
const TString<wchar>&,
integer )
const;
2451extern template ALIB_API integer TString<wchar>::indexOfString<lang::Case::Ignore >(
const TString<wchar>&,
integer )
const;
2464extern template ALIB_API integer TString<xchar>::indexOfString<lang::Case::Sensitive>(
const TString<xchar >&,
integer )
const;
2465extern template ALIB_API integer TString<xchar>::indexOfString<lang::Case::Ignore >(
const TString<xchar >&,
integer )
const;
2480#if ALIB_DEBUG_STRINGS
2481 extern template ALIB_API void TString<nchar>::dbgCheck()
const;
2482 extern template ALIB_API void TString<wchar>::dbgCheck()
const;
2483 extern template ALIB_API void TString<xchar>::dbgCheck()
const;
2490#if defined(_MSC_VER)
2491 #pragma warning( pop )
TRandomAccessIterator & operator-=(integer n)
TRandomAccessIterator operator+(integer n) const
bool operator<=(TRandomAccessIterator other) const
TCharConstOrMutable & operator*() const
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE TRandomAccessIterator & operator++()
TCharConstOrMutable value_type
Implementation of std::iterator_traits.
bool operator<(TRandomAccessIterator other) const
TCharConstOrMutable & operator*()
bool operator>=(TRandomAccessIterator other) const
TRandomAccessIterator & operator+=(integer n)
bool operator!=(TRandomAccessIterator other) const
TCharConstOrMutable & reference
Implementation of std::iterator_traits.
std::random_access_iterator_tag iterator_category
Implementation of std::iterator_traits.
TCharConstOrMutable * pointer
Implementation of std::iterator_traits.
integer operator-(TRandomAccessIterator other) const
bool operator==(TRandomAccessIterator other) const
bool operator>(TRandomAccessIterator other) const
TRandomAccessIterator operator--(int)
TRandomAccessIterator & operator--()
integer difference_type
Implementation of std::iterator_traits.
TRandomAccessIterator operator++(int)
TCharConstOrMutable & operator[](integer n) const
TRandomAccessIterator(TCharConstOrMutable *start=nullptr)
TRandomAccessIterator operator-(integer n) const
ConstIterator cend() const
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfOrLength(TChar needle, integer startIdx) const
constexpr bool IsNull() const
int CompareTo(const TString< TChar > &rhs) const
uint64_t ParseDec(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
ALIB_WARNINGS_RESTORE ConstReverseIterator rbegin() const
uint64_t ParseOct(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
integer IndexOf(TChar needle, integer startIdx=0) const
int64_t ParseInt(integer *newIdx) const
ConstReverseIterator crbegin() const
constexpr bool IsEmpty() const
double ParseFloat(integer startIdx, integer *newIdx) const
int CompareTo(const TString &rhs, integer rhsRegionStart, integer rhsRegionLength=MAX_LEN) const
TChar CharAt(integer idx) const
ALIB_API integer indexOfString(const TString &needle, integer startIdx) const
uint64_t ParseOct(integer *newIdx) const
integer IndexOfSegmentEnd(TChar opener, TChar closer, integer idx) const
double ParseFloat(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
constexpr bool IsNotEmpty() const
ConstReverseIterator rend() const
TRandomAccessIterator< const TChar > ConstIterator
uint64_t ParseDec(integer startIdx, integer *newIdx) const
integer IndexOfFirstDifference(const TString &needle, lang::Case sensitivity=lang::Case::Sensitive, integer idx=0) const
ALIB_API uint64_t ParseHex(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
constexpr integer Length() const
integer IndexOf(const TString &needle, integer startIdx=0) const
TChar CharAtStart() const
TChar operator[](integer idx) const
uint64_t ParseOct(integer startIdx, integer *newIdx) const
uint64_t ParseBin(integer startIdx, integer *newIdx) const
bool ContainsAt(const TString &needle, integer pos) const
constexpr bool IsNotNull() const
ALIB_API uint64_t ParseBin(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
integer CountChar(TChar needle, integer startPos=0) const
int64_t ParseInt(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
integer IndexOfAny(const TString &needles, integer startIdx=0) const
uint64_t ParseDec(integer *newIdx) const
constexpr TString(const TCharArray &src)
ConstIterator cbegin() const
integer CopyTo(TChar *dest) const
std::size_t Hashcode() const
std::size_t HashcodeIgnoreCase() 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
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
TString(ConstIterator &start, ConstIterator &end)
integer CountChar(TChar needle, TChar omit, integer startPos) const
integer Count(const TString &needle, const TString &omit, integer startPos=0) const
std::reverse_iterator< ConstIterator > ConstReverseIterator
bool AdjustRegion(integer ®ionStart, integer ®ionLength) const
integer IndexOfOrLength(TChar needle) const
integer IndexOf(TChar needle, integer regionStart, integer regionLength) const
bool Equals(const TString< TChar > &rhs) const
ConstReverseIterator crend() const
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE ConstIterator end() const
uint64_t ParseHex(integer *newIdx) const
ALIB_API double ParseFloat(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API int64_t ParseInt(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ConstIterator begin() const
ALIB_API uint64_t ParseOct(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_WARNINGS_RESTORE integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
bool EndsWith(const TString &needle) const
int CompareTo(const TString &rhs, integer rhsRegionStart, integer rhsRegionLength, integer regionStart, integer regionLength=MAX_LEN) const
double ParseFloat(integer *newIdx) const
bool StartsWith(const TString &needle) const
constexpr TString() noexcept=default
integer Count(const TString &needle, integer startPos=0) const
uint64_t ParseBin(integer *newIdx) const
constexpr const TChar * Buffer() const
integer LastIndexOfAny(const TString &needles, integer startIdx=MAX_LEN) const
ALIB_API uint64_t ParseDecDigits(integer startIdx=0, integer *newIdx=nullptr) const
uint64_t ParseHex(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
integer WStringLength() const
uint64_t ParseBin(TNumberFormat< TChar > *numberFormat, integer *newIdx=nullptr) const
uint64_t ParseHex(integer startIdx, integer *newIdx) const
#define ATMP_ISOF( T, TBase)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_IGNORE_DOCS
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_STRING_DBG_CHK(instance)
#define ATMP_SELECT_IF_1TP(TParam, ...)
#define ATMP_T_IF(T, Cond)
@ Include
Chooses inclusion.
bool operator==(const String &lhs, const String &rhs)
static constexpr integer MAX_LEN
strings::TString< TChar > AllocateCopy(const strings::TString< TChar > &src)
void DeleteString(const strings::TString< TChar > &string)
bool operator!=(const String &lhs, const String &rhs)
bool operator<=>(const String &lhs, const String &rhs)
constexpr XString NullXString()
WString NULL_W_STRING
A global instance of a nulled string of wide character size.
ComplementString NULL_COMPLEMENT_STRING
A global instance of a nulled string of complementary character size.
characters::wchar wchar
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
strings::TString< complementChar > ComplementString
Type alias in namespace alib.
NString NULL_N_STRING
A global instance of a nulled string of wide character size.
characters::xchar xchar
Type alias in namespace alib.
constexpr String NullString()
strings::TString< wchar > WString
Type alias in namespace alib.
constexpr NString NullNString()
XString NULL_X_STRING
A global instance of a nulled string of strange character size.
strings::TString< character > String
Type alias in namespace alib.
constexpr ComplementString NullComplementString()
constexpr StrangeString NullStrangeString()
strings::TString< strangeChar > StrangeString
Type alias in namespace alib.
StrangeString NULL_STRANGE_STRING
A global instance of a nulled string of strange character size.
characters::nchar nchar
Type alias in namespace alib.
String NULL_STRING
A global instance of a nulled string of standard character size.
strings::TString< xchar > XString
Type alias in namespace alib.
constexpr WString NullWString()
lang::integer integer
Type alias in namespace alib.
static integer IndexOfFirstDifference(const TChar *haystack, integer haystackLength, const TChar *needle, integer needleLength, lang::Case sensitivity)
static integer LastIndexOfAnyExclude(const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
static integer IndexOfAnyExcluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
static int CompareIgnoreCase(const TChar *lhs, const TChar *rhs, integer cmpLength)
static void Copy(const TChar *src, integer length, TChar *dest)
static bool Equal(TChar lhs, TRhs rhs)
static ALIB_WARNINGS_RESTORE const TChar * Search(const TChar *haystack, integer haystackLength, TChar needle)
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfAnyIncluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
static constexpr ConstructionType Construction
static TString Construct(const TChar *array, integer length)