ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
cstring.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_strings of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
9
10template<typename TChar> class TCString;
11
13
14
16
17//==================================================================================================
18/// This class specializes its base class \alib{strings;TString;String} in that respect that
19/// the character strings represented are guaranteed to be zero-terminated.<br>
20/// Zero-terminated strings are widely used by programming language \b C and are often called
21/// "C-strings", what gave the class its name.
22///
23/// \see
24/// For an introduction into the \alib string classes see this module's
25/// \ref alib_mod_strings "Programmer's Manual".
26///
27/// @tparam TChar The \ref alib_characters_chars "character type" of this string.
28//==================================================================================================
29template<typename TChar>
30class TCString : public TString<TChar>
31{
32 protected:
33 /// Shortcut to the base type.
35
36 public:
37 /// Defaulted default constructor. Leaves this instance \b uninitialized and undefined.
38 constexpr TCString() =default;
39
40 /// Constructor accepting a pointer to a character array and a string length.
41 /// \note
42 /// It is a user's responsibility to ensure that the character array provided includes
43 /// a terminating \c '\0' character.<br>
44 /// In debug-compilations a run-time assertion is raised if the provided buffer is not
45 /// zero-terminated.
46 /// @param pBuffer The buffer to use.
47 /// @param contentLength The length of the content in the given buffer.
48 constexpr
49 explicit
50 TCString( const TChar* pBuffer, integer contentLength )
51 : base( pBuffer, contentLength ) {
52 #if ALIB_DEBUG // needed to avoid empty {} in constexpr constructor
54 || base::buffer[base::length] == '\0', "STRINGS",
55 "Error: Explicit construction of CString with unterminated string." )
56 #endif
57 }
58
59
60 /// Constructor accepting \c nullptr. Constructs a nulled string.
61 constexpr TCString(lang::IsNullptr auto const &) noexcept : base( nullptr, 0 ) {}
62
63 /// Templated \b implicit constructor accepting a \c const reference to an object of a
64 /// type that satisfies the concept \alib{characters;IsImplicitZTArraySource}.
65 ///
66 /// Custom types can be enabled for this constructor by specializing the traits-type
67 /// \alib{characters;ZTArrayTraits}, which is used for both;
68 /// the implementation of the concept, and
69 /// the implementation of this constructor itself.
70 ///
71 /// @tparam T The type of the given \p{src}.
72 /// Requires satisfying the concept \alib{characters;IsImplicitZTArraySource}.
73 /// Deduced by the compiler.
74 /// @param src The source of the string data to copy.
75 template <typename T>
77 constexpr TCString(const T& src)
78 : base( characters::ZTArrayTraits<std::remove_cv_t<T>, TChar>::Buffer( src ),
79 characters::ZTArrayTraits<std::remove_cv_t<T>, TChar>::Length( src ) ) {
80 #if ALIB_DEBUG && !ALIB_DEBUG_ASSERTION_PRINTABLES
82 || base::buffer[base::length] == '\0', "STRINGS",
83 "Error: Implicit construction of CString with unterminated string." )
84 #endif
85 }
86
87 /// Templated \b implicit constructor accepting a \c const pointer to an object of a
88 /// type that satisfies the concept \alib{characters;IsImplicitZTArraySource}.
89 ///
90 /// Custom types can be enabled for this constructor by specializing the traits-type
91 /// \alib{characters;ZTArrayTraits}, which is used for both;
92 /// the implementation of the concept, and
93 /// the implementation of this constructor itself.
94 ///
95 /// @tparam T The type of the given \p{src}.
96 /// Requires satisfying the concept \alib{characters;IsImplicitZTArraySource}.
97 /// Deduced by the compiler.
98 /// @param src A pointer to the source of the string data to copy.
99 template <typename T>
101 constexpr TCString(const T* src)
102 : base( characters::ZTArrayTraits<std::remove_cv_t<T>, TChar>::Buffer( *src ),
103 characters::ZTArrayTraits<std::remove_cv_t<T>, TChar>::Length( *src ) ) {
105 || base::buffer[base::length] == '\0', "STRINGS",
106 "Error: Implicit construction of CString with unterminated string." )
107 }
108
109 /// Templated \b explicit constructor accepting a \c const reference to an object of a
110 /// type that satisfies the concept \alib{characters;IsExplicitZTArraySource}.
111 ///
112 /// Custom types can be enabled for this constructor by specializing the traits-type
113 /// \alib{characters;ZTArrayTraits}, which is used for both;
114 /// the implementation of the concept, and
115 /// the implementation of this constructor itself.
116 ///
117 /// @tparam T The type of the given \p{src}.
118 /// Requires satisfying the concept \alib{characters;IsExplicitZTArraySource}.
119 /// Deduced by the compiler.
120 /// @param src The source of the string data to copy.
121 template <typename T>
123 constexpr explicit TCString(T& src)
124 : base( characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( src ),
125 characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Length( src ) ) {
126 #if ALIB_DEBUG // needed to avoid empty {} in constexpr constructor
128 || base::buffer[base::length] == '\0', "STRINGS",
129 "Error: Explicit construction of CString with unterminated string." )
130 #endif
131 }
132
133 /// Templated \b explicit constructor accepting a \c const pointer to an object of a
134 /// type that satisfies the concept \alib{characters;IsExplicitZTArraySource}.
135 ///
136 /// Custom types can be enabled for this constructor by specializing the traits-type
137 /// \alib{characters;ZTArrayTraits}, which is used for both;
138 /// the implementation of the concept, and
139 /// the implementation of this constructor itself.
140 ///
141 /// @tparam T The type of the given \p{src}.
142 /// Requires satisfying the concept \alib{characters;IsExplicitZTArraySource}.
143 /// Deduced by the compiler.
144 /// @param src A pointer to the source of the string data to copy.
145 template <typename T>
147 constexpr explicit TCString(T* src)
148 : base( characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
149 characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {
150 #if ALIB_DEBUG // needed to avoid empty {} in constexpr constructor
152 || base::buffer[base::length] == '\0', "STRINGS",
153 "Error: Explicit construction of CString with unterminated string." )
154 #endif
155 }
156
157 /// Templated \b explicit constructor accepting a \b mutable reference to an object of a
158 /// type that satisfies the concept \alib{characters;IsMutableZTArraySource}.
159 ///
160 /// Custom types can be enabled for this constructor by specializing the traits-type
161 /// \alib{characters;ZTArrayTraits}, which is used for both;
162 /// the implementation of the concept, and
163 /// the implementation of this constructor itself.
164 ///
165 /// @tparam T The type of the given \p{src}.
166 /// Requires satisfying the concept \alib{characters;IsMutableZTArraySource}.
167 /// Deduced by the compiler.
168 /// @param src The source of the string data to copy.
169 template <typename T>
171 constexpr explicit TCString(T& src)
172 : base( characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Buffer(const_cast<T&>( src )),
173 characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Length(const_cast<T&>( src )) ) {
174 #if ALIB_DEBUG // needed to avoid empty {} in constexpr constructor
176 || base::buffer[base::length] == '\0', "STRINGS",
177 "Error: Construction of CString (from mutable object) with unterminated string." )
178 #endif
179 }
180
181 /// Templated \b explicit constructor accepting a \b mutable pointer to an object of a
182 /// type that satisfies the concept \alib{characters;IsMutableZTArraySource}.
183 ///
184 /// Custom types can be enabled for this constructor by specializing the traits-type
185 /// \alib{characters;ZTArrayTraits}, which is used for both;
186 /// the implementation of the concept, and
187 /// the implementation of this constructor itself.
188 ///
189 /// @tparam T The type of the given \p{src}.
190 /// Requires satisfying the concept \alib{characters;IsMutableZTArraySource}.
191 /// Deduced by the compiler.
192 /// @param src A pointer to the source of the string data to copy.
193 template <typename T>
195 constexpr explicit TCString(T* src)
196 : base( characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Buffer( *src ),
197 characters::ZTArrayTraits<std::remove_cv_t<T>,TChar>::Length( *src ) ) {
198 #if ALIB_DEBUG // needed to avoid empty {} in constexpr constructor
200 || base::buffer[base::length] == '\0', "STRINGS",
201 "Error: Construction of CString (from mutable object) with unterminated string." )
202 #endif
203 }
204
205 /// Constructor which allocates memory including an extra character for zero-termination,
206 /// copies the given string's contents and lets this \b %CString represent this new
207 /// zero-terminated character array.<br>
208 /// Note that it is up to the using code to duly deallocate the memory, because the
209 /// destructor of this type does not do so.
210 ///
211 /// \see
212 /// Methods #Allocate and #Free for information how to use allocated string objects.
213 ///
214 /// @tparam TAllocator The type of the given \p{allocator}, as prototyped with
215 /// \alib{lang;Allocator}. Deduced by the compiler.
216 /// @param allocator The allocator to use.
217 /// @param copy The string to copy to the new memory allocated.
218 template<typename TAllocator>
220 TCString( TAllocator& allocator, const TString<TChar>& copy ) {
221 if( (base::length= copy.Length()) == 0 ) {
222 base::buffer= copy.Buffer();
223 return;
224 }
225
226 auto* newBuf= allocator().template AllocArray<TChar>( copy.Length() + 1);
227 copy.CopyTo( newBuf );
228 newBuf[base::length]= '\0';
229 base::buffer= newBuf;
230 }
231
232 //######################################### casting back ########################################
233 /// Templated \b implicit <c>cast operator</c> constructing an instance of type \p{T} from
234 /// this string instance.
235 /// This operator requires the type \p{T} satisfying the concept
236 /// \alib{characters;IsImplicitZTArrayCast}.
237 ///
238 /// Custom types can be enabled for this operator by specializing the traits-type
239 /// \alib{characters;ArrayTraits}, which is used for both;
240 /// the implementation of the concept, and the implementation of this operator itself.
241 ///
242 /// @tparam T The type to implicitly cast this instance to.
243 /// Requires satisfying the concept \alib{characters;IsImplicitZTArrayCast}.
244 /// Deduced by the compiler.
245 /// @return A value of type \p{T}.
246 template< typename T>
250 std::remove_cv_t<T> >::value )
251 constexpr operator T() const
253
254 /// Templated \b explicit <c>cast operator</c> constructing an instance of type \p{T} from
255 /// this string instance.
256 /// This operator requires the type \p{T} satisfying the concept
257 /// \alib{characters;IsExplicitZTArrayCast}.
258 ///
259 /// Custom types can be enabled for this operator by specializing the traits-type
260 /// \alib{characters;ArrayTraits}, which is used for both;
261 /// the implementation of the concept, and
262 /// the implementation of this operator itself.
263 ///
264 /// @tparam T The type to implicitly cast this instance to.
265 /// Deduced by the compiler.
266 /// @return A value of type \p{T}.
267 template< typename T>
273 std::remove_cv_t<T> >::value )
274
275 constexpr explicit operator T() const
277
278
279 /// Templated \b implicit <c>cast operator</c> constructing an instance of type \p{T} from
280 /// this string instance.
281 /// This operator requires the type \p{T} satisfying the concept
282 /// \alib{characters;IsImplicitZTArrayCast}.
283 ///
284 /// Custom types can be enabled for this operator by specializing the traits-type
285 /// \alib{characters;ZTArrayTraits}, which is used for both;
286 /// the implementation of the concept, and
287 /// the implementation of this operator itself.
288 ///
289 /// @tparam T The type to implicitly cast this instance to.
290 /// Requires satisfying the concept \alib{characters;IsImplicitZTArrayCast}.
291 /// Deduced by the compiler.
292 /// @return A value of type \p{T}.
293 template< typename T>
294 requires ( !alib::characters::IsImplicitArrayCast <T, TChar>
298 std::remove_cv_t<T> >::value )
299
300 constexpr operator T() const
302
303
304 /// Templated \b explicit <c>cast operator</c> constructing an instance of type \p{T} from
305 /// this string instance.
306 /// This operator requires the type \p{T} satisfying the concept
307 /// \alib{characters;IsExplicitZTArrayCast}.
308 ///
309 /// Custom types can be enabled for this operator by specializing the traits-type
310 /// \alib{characters;ZTArrayTraits}, which is used for both;
311 /// the implementation of the concept, and
312 /// the implementation of this operator itself.
313 ///
314 /// @tparam T The type to explicitly cast this instance to.
315 /// Deduced by the compiler.
316 /// @return A value of type \p{T}.
317 template< typename T>
322 std::remove_cv_t<T> >::value )
323 constexpr explicit operator T() const
325
326
327 /// Reads a character at a given index.<br> Overrides
328 /// \alib{strings;TString::operator[];String::operator[]} to change the debug assertion
329 /// to allow inclusion of the termination character.
330 ///
331 /// \attention
332 /// No parameter check is performed (other than an assertions in debug-compilation of
333 /// \alib). See \alib{strings;TString::operator[];String::operator[]} for details.
334 ///
335 /// @param op The index of the character within this object's buffer.
336 /// @returns If the character contained at index \p{op}.
337 TChar operator[] (integer op) const {
338 ALIB_ASSERT_ERROR( op >= 0 && op <= base::length, "STRINGS",
339 "Index out of bounds: 0 <= {} < {}.", op, base::length )
340 return base::buffer[op];
341 }
342
343 /// Returns the index of the first character which is included, respectively <em>not</em>
344 /// included in a given set of characters.
345 ///
346 /// This method searches forwards. For backwards search, see
347 /// \alib{strings;TString::LastIndexOfAny;String::LastIndexOfAny}.
348 ///
349 /// \note
350 /// This method overrides method \alib{strings;TString::IndexOfAny;String::IndexOf}.
351 /// This implementation however expects a \b %CString with parameter \p{needles}
352 /// (beside the fact that it has to be invoked on a \b %CString itself).
353 /// If no zero-terminated needle string is available, the parent's original method
354 /// needs to be invoked. This has to be done by explicitly naming
355 /// the parent class in the invocation, like, for example, in
356 ///
357 /// myCString.TString::IndexOfAny<Inclusion::Include>( myString );
358 ///
359 /// \note
360 /// On most platforms, this zero-terminated version should perform slightly faster than
361 /// the original method in class \b %String.
362 ///
363 /// @tparam TCheck Defaults to \alib{CHK}, which is the normal invocation mode.
364 /// If \c <false> is added to the method name, no parameter checks are
365 /// performed and the needles must not be empty.
366 /// @tparam TInclusion Denotes whether the search returns the first index that holds a value
367 /// that is included or that is not excluded in the set of needle
368 /// characters.
369 /// @param needles Set of characters to be taken into account.
370 /// @param startIdx The index to start the search at. If the given value is less than \c 0,
371 /// it is set to \c 0. If it exceeds the length of the string, the length of
372 /// the string is returned.
373 /// Defaults to \c 0.
374 ///
375 /// @return The index of the first character found which is included, respectively not
376 /// included, in the given set of characters. If nothing is found, \c -1 is returned.
377 template <lang::Inclusion TInclusion,
378 typename TCheck= CHK >
379 integer IndexOfAny( const TCString& needles, integer startIdx= 0 )
380 const {
381 if (TCheck::value) {
382 if ( startIdx < 0 ) startIdx= 0;
383 if ( startIdx >= base::length ) return -1;
384 } else {
385 ALIB_ASSERT_ERROR( startIdx >= 0
386 && startIdx < base::length
387 && needles.Length() != 0, "STRINGS",
388 "Non checking and illegal parameters: 0 <= {} < {}, needles: {}",
389 startIdx, base::length, needles.Length() )
390 }
391
392
393 if constexpr ( TInclusion == lang::Inclusion::Include ) {
395 return idx >= 0 ? idx + startIdx : -1;
396 } else {
397 const TChar* haystack= base::buffer + startIdx;
398 integer idx= characters::IndexOfAnyExcludedZT<TChar>( haystack, needles );
399 return idx < 0 || *( haystack + idx ) == '\0' ? -1 : startIdx + idx;
400 } }
401
402 /// Sets this object to a zero-terminated copy of the given string, allocated in
403 /// given \p{allocator}.
404 ///
405 /// \note
406 /// In case given \p{copy} is empty or nulled, no allocation is performed and this string
407 /// is set to empty. Still the pointer to the buffer is copied. Thus, this string
408 /// behaves in respect to method #IsNull the same as given string \p{copy}.
409 ///
410 /// @tparam TAllocator The type of the given \p{allocator}, as prototyped with
411 /// \alib{lang;Allocator}. Deduced by the compiler.
412 /// @param allocator The allocator to use.
413 /// @param copy The string to copy to the new memory allocated.
414 template<typename TAllocator>
416 void Allocate( TAllocator& allocator, const TString<TChar>& copy ) {
417 if( (base::length= copy.Length()) == 0 ) {
418 base::buffer= copy.Buffer();
419 return;
420 }
421
422 auto* newBuf= allocator().template AllocArray<TChar>( base::length + 1);
423 copy.CopyTo( newBuf );
424 newBuf[base::length]= '\0';
425 base::buffer= newBuf;
426 }
427
428 /// Deallocates this String's memory in \p{allocator} and sets this instance to \e nulled.
429 ///
430 /// @see Notes in the similar method \alib{strings;TString::Free} of the base class, which
431 /// apply with this override likewise.
432 ///
433 /// @tparam TAllocator The type of the given \p{allocator}, as prototyped with
434 /// \alib{lang;Allocator}. Deduced by the compiler.
435 /// @param allocator The allocator to use.
436 template<typename TAllocator>
438 void Free( TAllocator& allocator ) const {
439 if( base::length == 0 || base::buffer == nullptr )
440 return;
441 allocator().FreeArray( base::buffer, base::length + 1 );
442 }
443}; // class TCString
444
445//##################################################################################################
446// Specializations of ArrayTraits for this class CString
447//##################################################################################################
448} ALIB_EXPORT namespace alib::characters {
449#if !DOXYGEN
450template<typename TChar> struct ZTArrayTraits<strings::TCString<TChar>, TChar>
451{
452 using T= strings::TCString<TChar>;
453 static constexpr Policy Access = Policy::Implicit;
454 static constexpr Policy Construction = Policy::ExplicitOnly;
455 static constexpr const TChar* Buffer(const T& src) { return src.Buffer(); }
456 static constexpr integer Length(const T& src) { return src.Length(); }
457 static constexpr T Construct(const TChar* b, integer l ) { return T(b, l); }
458};
459
460template<typename TChar> struct ArrayTraits<strings::TCString<TChar>, TChar>
461{
462 using T= strings::TCString<TChar>;
463 static constexpr Policy Access = Policy::Implicit;
464 static constexpr Policy Construction = Policy::ExplicitOnly;
465 static constexpr const TChar* Buffer(const T& src) { return src.Buffer(); }
466 static constexpr integer Length(const T& src) { return src.Length(); }
467
468 static constexpr T Construct(const TChar* b, integer l) { return T(b, l); }
469};
470#endif // !DOXYGEN
471
472} ALIB_EXPORT namespace alib {
473
474/// Type alias in namespace \b alib.
475using CString = strings::TCString <character>;
476
477/// Type alias in namespace \b alib.
478using ComplementCString= strings::TCString <complementChar>;
479
480/// Type alias in namespace \b alib.
481using StrangeCString = strings::TCString <strangeChar>;
482
483/// Type alias in namespace \b alib.
484using NCString = strings::TCString <nchar>;
485
486/// Type alias in namespace \b alib.
487using WCString = strings::TCString <wchar>;
488
489/// Type alias in namespace \b alib.
490using XCString = strings::TCString <xchar>;
491
492
493} ALIB_EXPORT namespace alib::strings {
494
495
496//==================================================================================================
497/// This template class has three specializations for types \alib{characters;nchar},
498/// \alib{characters;wchar}, and \alib{characters;xchar}, which each provide the following
499/// static \c constexpr methods:
500/// - #EmptyString,
501/// - #NewLine, and
502/// - #DefaultWhitespaces.
503///
504/// The class is useful to implement methods that are templated with the character type they use.
505///
506/// \note
507/// In non-templated code (that works with fixed or logical character sizes), it might lead to
508/// better readability if the following shortcut/alias functions of namespace #alib are used:
509/// - \ref EMPTY_CSTRING, \ref EMPTY_COMPLEMENT_CSTRING, \ref EMPTY_STRANGE_CSTRING,
510/// \ref EMPTY_NCSTRING, \ref EMPTY_WCSTRING, \ref EMPTY_XCSTRING,
511/// - \ref NEW_LINE, \ref COMPLEMENT_NEW_LINE, \ref STRANGE_NEW_LINE,
512/// \ref NNEW_LINE, \ref WNEW_LINE, \ref XNEW_LINE and
513/// - \ref DEFAULT_WHITESPACES, \ref COMPLEMENT_DEFAULT_WHITESPACES,
514/// \ref STRANGE_DEFAULT_WHITESPACES, \ref NDEFAULT_WHITESPACES, \ref WDEFAULT_WHITESPACES,
515/// \ref XDEFAULT_WHITESPACES.
516/// <p>
517///
518/// \note
519/// Constants for \e nulled strings are given with
520/// \ref NULL_STRING, \ref NULL_COMPLEMENT_STRING, \ref NULL_STRANGE_STRING,
521/// \ref NULL_NSTRING, \ref NULL_WSTRING, and \ref NULL_XSTRING. However, those are returning
522/// type \b String instead of \b CString. For \e nulled objects of type \b CString use the
523/// keyword \c nullptr which performs implicit constexpr creation.
524///
525/// \see
526/// See also manual chapter \ref alib_strings_details_constants.
527///
528/// @tparam TChar The \ref alib_characters_chars "character type".
529//==================================================================================================
530template<typename TChar>
532{
533 #if DOXYGEN
534 /// @return A \e zero-terminated empty string.
535 constexpr inline static CString<TChar> EmptyString();
536
537 /// On Windows OS, the returned string contains characters <c>'\\r'</c> and <c>'\\n'</c>, on
538 /// other platforms just character <c>'\\n'</c>.
539 /// @return A \e zero-terminated string containing platform-dependent "newline" charcater(s).
540 constexpr inline static CString<TChar> NewLine;
541
542 /// @return A zero-terminated string containing default whitespace characters "space", "newline"
543 /// "carriage return" and "tabulator", hence <c>" \n\r\t"</c>.
544 constexpr inline static CString<TChar> DefaultWhitespaces());
545 #endif
546};
547
548
549#if !DOXYGEN
550
551template<> struct CStringConstantsTraits<nchar>
552{
553 constexpr static NCString EmptyString() { return "" ; }
554
555 #if defined(_WIN32)
556 constexpr static NCString NewLine() { return "\r\n" ; }
557 #else
558 constexpr static NCString NewLine() { return "\n" ; }
559 #endif
560
561 constexpr static NCString DefaultWhitespaces() { return " \n\r\t" ; }
562};
563
564template<> struct CStringConstantsTraits<wchar>
565{
566 constexpr static WCString EmptyString() { return A_WCHAR("" ); }
567
568 #if defined(_WIN32)
569 constexpr static WCString NewLine() { return A_WCHAR("\r\n" ); }
570 #else
571 constexpr static WCString NewLine() { return A_WCHAR("\n" ); }
572 #endif
573
574 constexpr static WCString DefaultWhitespaces() { return A_WCHAR(" \n\r\t"); }
575};
576
577template<> struct CStringConstantsTraits<xchar>
578{
579 constexpr static XCString EmptyString() { return A_XCHAR("" ); }
580
581 #if defined(_WIN32)
582 constexpr static XCString NewLine() { return A_XCHAR("\r\n" ); }
583 #else
584 constexpr static XCString NewLine() { return A_XCHAR("\n" ); }
585 #endif
586
587 constexpr static XCString DefaultWhitespaces() { return A_XCHAR(" \n\r\t"); }
588};
589
590#endif //!DOXYGEN
591
592} ALIB_EXPORT namespace alib {
593
594
595/// A zero-terminated, empty string.
597
598/// A zero-terminated, empty string.
600
601/// A zero-terminated, empty string.
603
604/// A zero-terminated, empty string.
606
607/// A zero-terminated, empty string.
609
610/// A zero-terminated, empty string.
612
613
614
615/// A zero-terminated string containing the new-line character sequence.
617
618/// A zero-terminated string containing the new-line character sequence.
620
621/// A zero-terminated string containing the new-line character sequence.
623
624/// A zero-terminated string containing the new-line character sequence.
626
627/// A zero-terminated string containing the new-line character sequence.
629
630/// A zero-terminated string containing the new-line character sequence.
632
633
634
635/// A zero-terminated string of default whitespace characters.
637
638/// A zero-terminated string of default whitespace characters.
640
641/// A zero-terminated string of default whitespace characters.
643
644/// A zero-terminated string of default whitespace characters.
646
647/// A zero-terminated string of default whitespace characters.
649
650/// A zero-terminated string of default whitespace characters.
652
653
654} // namespace [alib]
655
656
657// Note(25/01/17):
658// Clang strangely did not find the following templated operators when they resided in an
659// exported namespace.
660// The workaround was to not export the namespace but export each operator instead.
661// We think this is wrong behavior and not aligned with the language specification.
662#if !DOXYGEN
663namespace alib::strings {
664
666template<typename TChar>
667bool operator== (const TCString<TChar>& lhs, const TCString<TChar>& rhs)
668{ return lhs. template Equals <CHK, lang::Case::Sensitive>(rhs); }
669
671template<typename TChar, typename T>
672requires (!std::is_same_v<T, TCString<TChar>>)
673bool operator== (const TCString<TChar>& lhs, const T& rhs)
674{ return lhs. template Equals <CHK, lang::Case::Sensitive>(rhs); }
675
677template<typename TChar>
678auto operator<=> (const TCString<TChar>& lhs, const TCString<TChar>& rhs)
679{ return lhs. template CompareTo<CHK, lang::Case::Sensitive>(rhs); }
680
682template<typename TChar, typename T>
683requires (!std::same_as<TCString<TChar>, T>)
684auto operator<=> (const TCString<TChar>& lhs, const T& rhs)
685{ return lhs. template CompareTo<CHK, lang::Case::Sensitive>(rhs); }
686
687} // namespace [alib::strings]
688#endif // !DOXYGEN
void Free(TAllocator &allocator) const
Definition cstring.inl:438
constexpr TCString(const T &src)
Definition cstring.inl:77
TCString(TAllocator &allocator, const TString< TChar > &copy)
Definition cstring.inl:220
TString< TChar > base
Shortcut to the base type.
Definition cstring.inl:34
constexpr TCString(T &src)
Definition cstring.inl:123
constexpr TCString(const TChar *pBuffer, integer contentLength)
Definition cstring.inl:50
constexpr TCString(const T *src)
Definition cstring.inl:101
TChar operator[](integer op) const
Definition cstring.inl:337
integer IndexOfAny(const TCString &needles, integer startIdx=0) const
Definition cstring.inl:379
constexpr TCString()=default
Defaulted default constructor. Leaves this instance uninitialized and undefined.
constexpr TCString(T *src)
Definition cstring.inl:195
constexpr TCString(T *src)
Definition cstring.inl:147
constexpr TCString(T &src)
Definition cstring.inl:171
void Allocate(TAllocator &allocator, const TString< TChar > &copy)
Definition cstring.inl:416
constexpr TCString(lang::IsNullptr auto const &) noexcept
Constructor accepting nullptr. Constructs a nulled string.
Definition cstring.inl:61
integer CopyTo(TChar *dest) const
Definition string.inl:1726
constexpr integer Length() const
Definition string.inl:316
constexpr const character * Buffer() const
Definition string.inl:311
constexpr TString() noexcept=default
constexpr bool IsNull() const
Definition string.inl:350
#define ALIB_WARNINGS_RESTORE
Definition alib.inl:719
#define ALIB_WARNINGS_IGNORE_DOCS
Definition alib.inl:702
#define A_XCHAR(STR)
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
#define A_WCHAR(STR)
integer IndexOfAnyIncludedZT(const TChar *haystack, const TChar *needles)
integer IndexOfAnyExcludedZT(const TChar *haystack, const TChar *needles)
Inclusion
Denotes how members of a set something should be taken into account.
@ Include
Chooses inclusion.
auto operator<=>(const String &lhs, const String &rhs)
Definition string.inl:2090
constexpr StrangeCString EMPTY_STRANGE_CSTRING
A zero-terminated, empty string.
Definition cstring.inl:602
constexpr StrangeCString STRANGE_NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:622
strings::TCString< strangeChar > StrangeCString
Type alias in namespace alib.
Definition cstring.inl:481
constexpr WCString WNEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:628
constexpr ComplementCString COMPLEMENT_DEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:639
strings::TCString< complementChar > ComplementCString
Type alias in namespace alib.
Definition cstring.inl:478
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:616
constexpr CString EMPTY_CSTRING
A zero-terminated, empty string.
Definition cstring.inl:596
strings::TCString< character > CString
Type alias in namespace alib.
Definition cstring.inl:475
characters::wchar wchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TCString< xchar > XCString
Type alias in namespace alib.
Definition cstring.inl:490
constexpr NCString NNEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:625
constexpr XCString XNEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:631
strings::TCString< wchar > WCString
Type alias in namespace alib.
Definition cstring.inl:487
strings::TCString< nchar > NCString
Type alias in namespace alib.
Definition cstring.inl:484
characters::nchar nchar
Type alias in namespace alib.
constexpr XCString XDEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:651
constexpr CString DEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:636
constexpr NCString NDEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:645
constexpr StrangeCString STRANGE_DEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:642
constexpr WCString WDEFAULT_WHITESPACES
A zero-terminated string of default whitespace characters.
Definition cstring.inl:648
characters::xchar xchar
Type alias in namespace alib.
constexpr ComplementCString EMPTY_COMPLEMENT_CSTRING
A zero-terminated, empty string.
Definition cstring.inl:599
constexpr XCString EMPTY_XCSTRING
A zero-terminated, empty string.
Definition cstring.inl:611
constexpr WCString EMPTY_WCSTRING
A zero-terminated, empty string.
Definition cstring.inl:608
constexpr NCString EMPTY_NCSTRING
A zero-terminated, empty string.
Definition cstring.inl:605
constexpr ComplementCString COMPLEMENT_NEW_LINE
A zero-terminated string containing the new-line character sequence.
Definition cstring.inl:619
See sibling type NC.
Definition chk_nc.inl:33
static constexpr Policy Access
static integer Length(const TStringSource &src)
static TStringSource Construct(const TChar *array, integer length)
static constexpr Policy Construction
static const TChar * Buffer(const TStringSource &src)
static constexpr Policy Construction
static constexpr Policy Access
static const TChar * Buffer(const TStringSource &src)
static TStringSource Construct(const TChar *array, integer length)
static integer Length(const TStringSource &src)
static constexpr CString< TChar > DefaultWhitespaces())
"carriage return" and "tabulator", hence " \n\r\t".
static constexpr CString< TChar > NewLine
Definition cstring.inl:540
static constexpr CString< TChar > EmptyString()