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