BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_stringview.h
Go to the documentation of this file.
1/// @file bslstl_stringview.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_stringview.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_STRINGVIEW
9#define INCLUDED_BSLSTL_STRINGVIEW
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_stringview bslstl_stringview
15/// @brief Provide a standard-compliant `basic_string_view` class template.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_stringview
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_stringview-purpose"> Purpose</a>
25/// * <a href="#bslstl_stringview-classes"> Classes </a>
26/// * <a href="#bslstl_stringview-macros"> Macros </a>
27/// * <a href="#bslstl_stringview-canonical-header"> Canonical Header </a>
28/// * <a href="#bslstl_stringview-description"> Description </a>
29/// * <a href="#bslstl_stringview-lexicographical-comparisons"> Lexicographical Comparisons </a>
30/// * <a href="#bslstl_stringview-operations"> Operations </a>
31/// * <a href="#bslstl_stringview-user-defined-literals"> User-defined literals </a>
32/// * <a href="#bslstl_stringview-bsl-string_view-and-std-string_view"> bsl::string_view and std::string_view </a>
33/// * <a href="#bslstl_stringview-background"> Background </a>
34/// * <a href="#bslstl_stringview-usage"> Usage </a>
35/// * <a href="#bslstl_stringview-example-1-basic-syntax"> Example 1: Basic Syntax </a>
36///
37/// # Purpose {#bslstl_stringview-purpose}
38/// Provide a standard-compliant @ref basic_string_view class template.
39///
40/// # Classes {#bslstl_stringview-classes}
41///
42/// - bsl::basic_string_view: C++ compliant @ref basic_string_view implementation
43/// - bsl::string_view: `typedef` for `bsl::basic_string_view<char>`
44/// - bsl::wstring_view: `typedef` for `bsl::basic_string_view<wchar_t>`
45///
46/// # Macros {#bslstl_stringview-macros}
47///
48/// - BSLSTL_STRING_VIEW_IS_ALIASED: `bsl::string_view` => `std::string_view`
49/// - BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST: are different classes
50///
51/// # Canonical Header {#bslstl_stringview-canonical-header}
52/// bsl_string_view.h
53///
54/// @see ISO C++ Standard, bdlb_stringviewutil
55///
56/// # Description {#bslstl_stringview-description}
57/// This component defines a single class template
58/// `bsl::basic_string_view` and aliases for ordinary and wide character
59/// specializations `bsl::string_view` and `bsl::wstring_view` implementing
60/// standard containers, `std::string_view` and `std::wstring_view`, that can
61/// refer to a constant contiguous sequence of char-like objects with the first
62/// element of the sequence at position zero.
63///
64/// An instantiation of @ref basic_string_view is a value-semantic type whose
65/// salient attribute is the sequence of characters it represents. The
66/// @ref basic_string_view `class` is parameterized by the character type,
67/// `CHAR_TYPE` and that character type's traits, `CHAR_TRAITS`. The traits for
68/// each character type provide functions that assign, compare, and copy a
69/// sequence of those characters.
70///
71/// A @ref basic_string_view meets the requirements of a sequential container with
72/// random access iterators as specified in the [basic.string_view] section of
73/// the C++ standard [24.4]. The @ref basic_string_view implemented here adheres
74/// to the C++17 standard, except that it does not have template specializations
75/// `std::u16string_view` and `std::u32string_view`. Note that if compiler
76/// supports C++17 standard, then `stl` implementation of @ref basic_string_view is
77/// used.
78///
79/// ## Lexicographical Comparisons {#bslstl_stringview-lexicographical-comparisons}
80///
81///
82/// Two @ref basic_string_view s `lhs` and `rhs` are lexicographically compared by
83/// first determining `N`, the smaller of the lengths of `lhs` and `rhs`, and
84/// comparing characters at each position between 0 and `N - 1`, using
85/// `CHAR_TRAITS::compare` in lexicographical fashion. If
86/// `CHAR_TRAITS::compare` determines that string_views are non-equal (smaller
87/// or larger), then this is the result. Otherwise, the lengths of the
88/// string_views are compared and the shorter string_view is declared the
89/// smaller. Lexicographical comparison returns equality only when both
90/// string_views have the same length and the same character value in each
91/// respective position.
92///
93/// ## Operations {#bslstl_stringview-operations}
94///
95///
96/// This section describes the run-time complexity of operations on instances of
97/// @ref basic_string_view :
98/// @code
99/// Legend
100/// ------
101/// 'V' - the 'CHAR_TYPE' template parameter type of the
102/// 'basic_string_view'
103/// 'a', 'b' - two distinct objects of type 'basic_string_view<V>'
104/// 'k' - an integral number
105/// 'p' - a pointer defining a sequence of 'CHAR_TYPE' characters
106///
107/// +----------------------------------------------+--------------------------+
108/// | Operation | Complexity |
109/// |==============================================+==========================|
110/// | basic_string_view<V> a (default construction)| O[1] |
111/// |----------------------------------------------+--------------------------|
112/// | basic_string_view<V> a(b) (copy construction)| O[1] |
113/// |----------------------------------------------+--------------------------|
114/// | basic_string_view<V> a(p) | O[n] |
115/// |----------------------------------------------+--------------------------|
116/// | basic_string_view<V> a(p, k) | O[1] |
117/// |----------------------------------------------+--------------------------|
118/// | a.~basic_string_view<V>() (destruction) | O[1] |
119/// |----------------------------------------------+--------------------------|
120/// | a.begin(), a.end(), | O[1] |
121/// | a.cbegin(), a.cend(), | |
122/// | a.rbegin(), a.rend(), | |
123/// | a.crbegin(), a.crend() | |
124/// |----------------------------------------------+--------------------------|
125/// | a.size() | O[1] |
126/// |----------------------------------------------+--------------------------|
127/// | a.max_size() | O[1] |
128/// |----------------------------------------------+--------------------------|
129/// | a.remove_prefix(k) | O[1] |
130/// | a.remove_suffix(k) | |
131/// |----------------------------------------------+--------------------------|
132/// | a[k] | O[1] |
133/// |----------------------------------------------+--------------------------|
134/// | a.at(k) | O[1] |
135/// |----------------------------------------------+--------------------------|
136/// | a.front() | O[1] |
137/// |----------------------------------------------+--------------------------|
138/// | a.back() | O[1] |
139/// |----------------------------------------------+--------------------------|
140/// | a.swap(b), swap(a, b) | O[1] |
141/// |----------------------------------------------+--------------------------|
142/// | a = b; (assignment) | O[1] |
143/// |----------------------------------------------+--------------------------|
144/// | a == b, a != b | O[n] |
145/// |----------------------------------------------+--------------------------|
146/// | a < b, a <= b, a > b, a >= b | O[n] |
147/// +----------------------------------------------+--------------------------+
148/// @endcode
149///
150/// ## User-defined literals {#bslstl_stringview-user-defined-literals}
151///
152///
153/// The user-defined literal operators are declared for the `bsl::string_view`
154/// and `bsl::wstring_view` types. The ud-suffix `_sv` is chosen to distinguish
155/// between the `bsl`-string_view's user-defined literal operators and the
156/// `std`-string_view's user-defined literal `operator ""sv` introduced in the
157/// C++14 standard and implemented in the standard library provided by the
158/// compiler vendor. Note that the `bsl`-string_view's `operator""_sv`,
159/// unlike the `std`-string_view's `operator ""sv`, can be used in a client's
160/// code if the compiler supports the C++11 standard. Also note that if the
161/// compiler supports the C++17 standard then the `std`-string_view's
162/// `operator ""sv` can be used to initialize a `bsl`-string_view as follows:
163/// @code
164/// using namespace std::string_view_literals;
165/// bsl::string_view sv = "test"sv;
166/// @endcode
167///
168/// Also note that `bsl`-string_view's user-defined literal operators are
169/// declared in the `bsl::literals::string_view_literals` namespace, where
170/// `literals` and @ref string_view_literals are inline namespaces. Access to
171/// these operators can be gained with either `using namespace bsl::literals`,
172/// `using namespace bsl::string_view_literals` or
173/// `using namespace bsl::literals::string_view_literals`. But we recommend
174/// `using namespace bsl::string_view_literals` to minimize the scope of the
175/// using declaration:
176/// @code
177/// using namespace bsl::string_view_literals;
178/// bsl::string_view svr = "test"_sv;
179/// @endcode
180///
181/// ## bsl::string_view and std::string_view {#bslstl_stringview-bsl-string_view-and-std-string_view}
182///
183///
184/// The following macros are provided to allow developers who work with both
185/// `bsl::string_view` (which exists for *all* supported language levels) and
186/// `std::string_view` (which does not exist for all language levels and whose
187/// feature set differs according to language level) to define and test
188/// their interfaces as appropriate.
189///
190/// * `BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY`: If defined, the
191/// `std::string_view` class is exists.
192/// `assert(true == bsl::is_class<std::string_view>);'
193///
194/// * `BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST`: If defined, both
195/// `std::string_view` and `bsl::string_view` exist, and they are each is a
196/// distinct class.
197/// `assert(false == bsl::is_same_v<bsl::string_view, std::string_view>);'
198///
199/// * `BSLSTL_STRING_VIEW_IS_ALIASED': If defined, both `std::string_view` and
200/// `bsl::string_view` exist *and* the latter is implemented as an alias to
201/// the former.
202/// `assert(true == bsl::is_same_v<bsl::string_view, std::string_view>);'
203///
204/// ### Background {#bslstl_stringview-background}
205///
206///
207/// `std::string_view` was introduced in the Standard library for C++17.
208/// Later versions of the Standard have added features. One of the goals of
209/// `bsl::string_view` is to make *all* `std::string_view` features
210/// available to Bloomberg developers, irrespective of the language level being
211/// used. Thus, `bsl::string_view` provides a `std::string_view` implementation
212/// for C++03, C++11, and CPP14 -- language levels that have no
213/// `std::string_view` class. For later language levels, `bsl::string_view`
214/// may be implemented as an alias to `std::string_view` itself. Alternatively,
215/// for some language levels, the two classes may both be available. For
216/// example, for CPP17, `bsl::string_view` can be constructed from appropriate
217/// iterators (a feature of the C++20 standard) but the native C++17
218/// `std::string_view` cannot.
219///
220/// ## Usage {#bslstl_stringview-usage}
221///
222///
223/// In this section we show intended use of this component.
224///
225/// ### Example 1: Basic Syntax {#bslstl_stringview-example-1-basic-syntax}
226///
227///
228/// The `bsl::string_view` can be used as a lightweight replacement of the
229/// `bsl::string`, unless you need to modify the content. It takes up no more
230/// space and doesn't allocate memory:
231/// @code
232/// bslma::TestAllocator da("Default", veryVeryVeryVerbose);
233/// bslma::DefaultAllocatorGuard dag(&da);
234///
235/// bslma::TestAllocator sfa ("StringFootprint", veryVeryVeryVerbose);
236/// bslma::TestAllocator svfa("StringViewFootprint", veryVeryVeryVerbose);
237/// bslma::TestAllocator ssa ("StringSupplied", veryVeryVeryVerbose);
238///
239/// const char *LONG_STRING = "0123456789012345678901234567890123456789"
240/// "0123456789012345678901234567890123456789";
241///
242/// bsl::string *sPtr = new (sfa ) bsl::string(LONG_STRING, &ssa);
243/// bsl::string_view *svPtr = new (svfa) bsl::string_view(LONG_STRING);
244///
245/// assert(sfa.numBytesInUse() >= svfa.numBytesInUse());
246/// assert(0 < ssa.numBytesInUse());
247/// assert(0 == da.numBytesInUse());
248/// @endcode
249/// At the same time it supports all most used `access` operations of the
250/// `bsl::string`, using the same interfaces:
251/// @code
252/// const bsl::string& STR = *sPtr;
253/// const bsl::string_view& SV = *svPtr;
254///
255/// assert(STR.length() == SV.length());
256/// assert(STR.empty() == SV.empty());
257/// assert(STR.front() == SV.front());
258/// assert(STR.at(15) == SV.at(15));
259/// assert(STR.find("345") == SV.find("345"));
260/// assert(STR.find_last_not_of("578") == SV.find_last_not_of("578"));
261/// assert(STR.compare(0, 3, "012") == SV.compare(0, 3, "012"));
262/// @endcode
263/// However, using the `bsl::string_view`, you need to be especially attentive
264/// to the lifetime of the source character string, since the component
265/// explicitly refers to it:
266/// @code
267/// assert(LONG_STRING != STR.data());
268/// assert(LONG_STRING == SV.data());
269///
270/// sfa.deleteObject(sPtr);
271/// svfa.deleteObject(svPtr);
272/// @endcode
273/// @}
274/** @} */
275/** @} */
276
277/** @addtogroup bsl
278 * @{
279 */
280/** @addtogroup bslstl
281 * @{
282 */
283/** @addtogroup bslstl_stringview
284 * @{
285 */
286
287#include <bslscm_version.h>
288
289#include <bslstl_hash.h>
290#include <bslstl_iterator.h>
291#include <bslstl_stdexceptutil.h>
292
294
295#include <bslh_hash.h>
296
297#include <bslmf_addconst.h>
298#include <bslmf_addpointer.h>
299#include <bslmf_enableif.h>
300#include <bslmf_isconvertible.h>
303#include <bslmf_switch.h>
304
305#include <bsls_assert.h>
307#include <bsls_keyword.h>
308#include <bsls_libraryfeatures.h>
309#include <bsls_nullptr.h>
310#include <bsls_performancehint.h>
311#include <bsls_platform.h>
312
313#include <cstddef> // for 'std::size_t'
314#include <functional> // for 'std::less', 'std::greater_equal'
315#include <string> // for 'std::char_traits'
316
317#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
318# include <bsls_nativestd.h>
319#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
320
321#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) \
322&& (!defined(BSLS_LIBRARYFEATURES_HAS_CPP23_BASELINE_LIBRARY) || \
323 (defined(BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED) && \
324 (BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED < 23)))
325 /// `bsl` and `std::string_view`s coexist when we have at least C++17
326 /// standard library available, but C++20 library is not available, or it
327 /// is disabled due to ABI compatibility reasons.
328# define BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
329#endif
330
331#if defined (BSLS_LIBRARYFEATURES_HAS_CPP23_BASELINE_LIBRARY) && \
332 !(defined(BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED) && \
333 (BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED < 23))
334
335 /// `BSLSTL_STRING_VIEW_IS_ALIASED` is defined when `bsl::string_view` and
336 /// its accompanying symbols are aliases to their `std` equivalents.
337 ///
338 /// \note Note that `std::string` may coexist with `bsl::string_view` that is *not* an
339 /// alias of it; see `BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST`.
340# define BSLSTL_STRING_VIEW_IS_ALIASED
341
342# include <string_view>
343
344 namespace bsl {
345
346using std::basic_string_view;
347using std::string_view;
348using std::wstring_view;
349
350# if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
351using std::u8string_view;
352# endif
353
354using std::u16string_view;
355using std::u32string_view;
356
357using std::swap;
358
359using std::operator==;
360using std::operator!=;
361using std::operator<;
362using std::operator<=;
363using std::operator>;
364using std::operator>=;
365
366}
367#endif // BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY & not disabled
368
369#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
370
371#if defined(BSLS_PLATFORM_OS_WINDOWS) || \
372 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130) || \
373 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION == 0x5150)
374 // Windows or Sun CC before version 5.12.4 or Sun CC version 5.12.6
375
376# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 1
377#else
378# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 0
379#endif
380
381
382namespace bslstl {
383
384 // ===========================
385 // struct 'StringView_Identity
386 // ===========================
387
388template <class TYPE>
390#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
391 // See 'Implementation Notes' in the implementation .cpp file.
392
393 // TYPES
394 struct type {
395 // DATA
396 TYPE d_value;
397
398 // CREATOR
399
400 /// Initialize `d_value` from the specified `argument`, of the
401 /// specified `ARG_TYPE`, where `ARG_TYPE` can be any type that is
402 /// convertible to the specified `TYPE`.
403 template <class ARG_TYPE>
404 type(const ARG_TYPE& argument,
405 typename
407 int>::type = 0);
408
409 type(const type&) = default;
410
411 // MANIPULATORS
412
413 type& operator=(const type&) = default;
414
415 /// Assign the specified `rhs` of type `TYPE` to this object, and
416 /// return a reference providing modifiable access to the `TYPE`
417 /// object held by this object.
418 TYPE& operator=(const TYPE& rhs);
419
420 /// Return a reference providing modifiable access to the `TYPE`
421 /// object held by this object.
422 operator TYPE&();
423
424 // ACCESSOR
425
426 /// Return a const reference to the `TYPE` object held by this
427 /// object.
428 operator const TYPE&() const;
429 };
430#else
431 // TYPES
432 typedef TYPE type;
433#endif
434};
435
436} // close package namespace
437
438
439namespace bsl {
440
441// Import @ref char_traits into the 'bsl' namespace so that @ref basic_string_view
442// and @ref char_traits are always in the same namespace.
443
444using std::char_traits;
445
446 // =======================
447 // class basic_string_view
448 // =======================
449
450/// This class template provides an STL-compliant @ref string_view . This
451/// implementation offers strong exception guarantees (see below), with the
452/// general rule that any method that attempts to access a position outside
453/// the valid range of a string_view throws `std::out_of_range`.
454///
455///
456/// \note Note that the search methods, such as `find`, `rfind`, etc, do *not*
457/// actually access invalid positions, so they do *not* throw exceptions.
458///
459/// More generally, this class supports an almost complete set of *in-core*
460/// *value* *semantic* operations, including copy construction, assignment,
461/// equality comparison (but excluding `ostream` printing since this
462/// component is below STL). A precise operational definition of when two
463/// objects have the same value can be found in the description of
464/// `operator==` for the class. This class is *exception* *neutral* with
465/// full guarantee of rollback: if an exception is thrown during the
466/// invocation of a method on a pre-existing object, the object is left
467/// unchanged. In no event is memory leaked.
468///
469/// See @ref bslstl_stringview
470template <class CHAR_TYPE, class CHAR_TRAITS = char_traits<CHAR_TYPE> >
472
473 public:
474 // TYPES
476 typedef CHAR_TYPE value_type;
478 typedef const value_type *const_pointer;
483
484 typedef bsl::reverse_iterator<iterator> reverse_iterator;
485 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
486
487 typedef std::size_t size_type;
488 typedef std::ptrdiff_t difference_type;
489
490 public:
491 // CLASS DATA
492
493 /// Value used to denote "not-a-position", guaranteed to be outside the
494 /// range `[0 .. max_size()]`.
495 static const size_type npos = ~size_type(0);
496
497 private:
498 // DATA
499 const CHAR_TYPE *d_start_p; // pointer to the data
500 size_type d_length; // length of the view
501
502 // PRIVATE ACCESSORS
503
504 /// Lexicographically compare the substring of this string starting at
505 /// the specified `lhsPosition` of length `lhsNumChars` with the
506 /// specified initial `otherNumChars` characters in the specified
507 /// `other` string, and return a negative value if the indicated
508 /// substring of this string is less than `other`, a positive value if
509 /// it is greater than `other`, and 0 in case of equality.
510 ///
511 /// \pre The behavior is undefined unless `lhsPosition <= length()`,
512 /// `lhsNumChars <= length()`, and
513 /// `lhsPosition <= length() - lhsNumChars`.
515 int privateCompareRaw(size_type lhsPosition,
516 size_type lhsNumChars,
517 const CHAR_TYPE *other,
518 size_type otherNumChars) const;
519
520 public:
521 // TRAITS
524
525 // CREATORS
526
527 /// Create an empty view.
530
531 /// Create a view that has the same value as the specified `original`
532 /// object.
533 basic_string_view(const basic_string_view& original) = default;
534
535 /// Create a view of the specified null-terminated `characterString` (of
536 /// length `CHAR_TRAITS::length(characterString)`).
538 basic_string_view(const CHAR_TYPE *characterString); // IMPLICIT
539
540#ifdef BSLS_COMPILERFEATURES_FULL_CPP11
541 /// A view cannot be constructed from a `nullptr` or from a literal `0`.
543#endif
544
545 /// Create a view that has the same value as the subview of the
546 /// optionally specified `numChars` length starting at the beginning of the specified `characterString`.
547 ///
548 /// \pre The behavior is undefined unless
549 /// `characterString || (numChars == 0)` and `numChars <= max_size()`.
551 basic_string_view(const CHAR_TYPE *characterString,
552 size_type numChars);
553
554 /// Create a view of the characters in the range starting at the
555 /// specified `first`, a contiguous iterator, to the position
556 /// immediately before the specified `end`, a sentinel type.
557 ///
558 /// \pre The behavior is undefined unless:
559 /// * `[first, last)` is a contiguous valid range,
560 /// * if `first` is 0, then `0 == last - first`, and
561 /// * the `SENTINEL` type is *not* convertible to `std::size_t`.
562 ///
563 /// \note Note that contiguous iterator types also provide random access.
564 /// Also note that pointers to `CHAR_TYPE` can be used as iterator and
565 /// sentinel types. If `to_address` is not available the contiguous
566 /// iterator must also be convertible to `const CHAR_TYPE*`.
567#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY)
568 template <class CONTIG_ITER, class SENTINEL>
570 basic_string_view(CONTIG_ITER first,
571 SENTINEL last,
572 typename
575 decltype(&(*std::declval<CONTIG_ITER>())),
576 const CHAR_TYPE*
577 >::value
579 >::type * = 0);
580#else
581 template <class CONTIG_ITER, class SENTINEL>
583 basic_string_view(CONTIG_ITER first,
584 SENTINEL last,
585 typename
589 >::type * = 0);
590#endif
591
592 /// Create a view of the specified `string`.
593 template <class ALLOCATOR>
595 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& str);
596 // IMPLICIT
597
598#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
599 /// Create a view identical to the specified `view`.
602 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view);
603 // IMPLICIT
604
605#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
606
607 /// Destroy this object.
609
610 // MANIPULATORS
611
612 /// Assign to this view the value of the specified `rhs` object, and
613 /// return a reference providing modifiable access to this view.
615
616 /// Assign to this view the value of the specified `rhs` object, and
617 /// return a reference providing modifiable access to this view.
618 template <class ALLOCATOR>
621 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
623
624 /// Move the start of this view forward by the specified `numChars`.
625 ///
626 /// \pre The behavior is undefined unless `numChars <= length()`.
628 void remove_prefix(size_type numChars);
629
630 /// Move the end of this view back by the specified `numChars`.
631 ///
632 /// \pre The behavior is undefined unless `numChars <= length()`.
634 void remove_suffix(size_type numChars);
635
636 /// Exchange the value of this view with the value of the specified
637 /// `other` object.
639
640 // ACCESSORS
641
642 // *** iterator support ***
643
644 /// Return an iterator providing non-modifiable access to the first
645 /// character of this view (or the past-the-end iterator if this view is
646 /// empty).
651
652 /// Return the past-the-end iterator for this view.
657
658 /// Return a reverse iterator providing non-modifiable access to the
659 /// last character of this view (or the past-the-end reverse iterator if
660 /// this view is empty).
665
666 /// Return the past-the-end reverse iterator for this view.
671
672 // *** capacity ***
673
674 /// Return the length of this view.
677
678 /// Return the length of this view.
681
682 /// Return the maximal possible length of this view.
683 /// \note Note that requests
684 /// to create a view longer than this number of characters are
685 /// guaranteed to raise an `std::length_error` exception.
688
689 /// Return `true` if this view has length 0, and `false` otherwise.
692
693 // *** element access ***
694
695 /// Return a reference providing non-modifiable access to the character
696 /// at the specified `position` in this view.
697 ///
698 /// \pre The behavior is undefined unless `position < length()`.
700 const_reference operator[](size_type position) const;
701
702 /// Return a reference providing non-modifiable access to the character
703 /// at the specified `position` in this view. Throw `std::out_of_range`
704 /// if `position >= length()`.
706 const_reference at(size_type position) const;
707
708 /// Return a reference providing non-modifiable access to the character at the first position in this view.
709 ///
710 /// \pre The behavior is undefined if
711 /// this view is empty.
714
715 /// Return a reference providing non-modifiable access to the character at the last position in this view.
716 ///
717 /// \pre The behavior is undefined if this view is empty.
718 ///
719 /// \note Note that the last position is `length() - 1`.
722
723 /// Return an address providing non-modifiable access to the underlying character array.
724 ///
725 /// \note Note that this array may be not null-terminated.
728
729 // *** string operations ***
730
731 /// Copy from this view, starting from the optionally specified
732 /// `position`, the specified `numChars` or `length() - position`
733 /// characters, whichever is smaller, into the specified
734 /// `characterString` buffer, and return the number of characters
735 /// copied. If `position` is not specified, 0 is used. Throw `std::out_of_range` if `position > length()`.
736 ///
737 /// \note Note that the output
738 /// `characterString` is *not* null-terminated.
739 ///
740 /// \pre The behavior is undefined unless `characterString` has enough room to hold at least
741 /// `numChars` or `length() - position`, whichever is smaller, and the
742 /// `characterString` does not lie within the source range to be copied.
743 size_type copy(CHAR_TYPE *characterString,
744 size_type numChars,
745 size_type position = 0) const;
746
747 /// Return a view whose value is the subview starting at the optionally
748 /// specified `position` in this view, of length the optionally
749 /// specified `numChars` or `length() - position`, whichever is smaller.
750 /// If `position` is not specified, 0 is used (i.e., the subview is from
751 /// the beginning of this view). If `numChars` is not specified, `npos`
752 /// is used (i.e., the entire suffix from `position` to the end of the
753 /// view is returned). Throw `std::out_of_range` if
754 /// `position > length()`.
757 size_type numChars = npos) const;
758
759 /// Lexicographically compare this view with the specified `other` view,
760 /// and return a negative value if this view is less than `other`, a
761 /// positive value if it is greater than `other`, and 0 in case of
762 /// equality. See {Lexicographical Comparisons}.
765
766 /// Lexicographically compare the subview of this view of the specified
767 /// `numChars` length starting at the specified `position` (or the
768 /// suffix of this view starting at `position` if
769 /// `position + numChars > length()`) with the specified `other` view,
770 /// and return a negative value if the indicated subview of this view is
771 /// less than `other`, a positive value if it is greater than `other`,
772 /// and 0 in case of equality. Throw `std::out_of_range` if
773 /// `position > length()`. See {Lexicographical Comparisons}.
775 int compare(size_type position,
776 size_type numChars,
777 basic_string_view other) const;
778
779 /// Lexicographically compare the subview of this view of the specified
780 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
781 /// suffix of this view starting at `lhsPosition` if
782 /// `lhsPosition + lhsNumChars > length()`) with the subview of the
783 /// specified `other` view of the specified `otherNumChars` length
784 /// starting at the specified `otherPosition` (or the suffix of `other`
785 /// starting at `otherPosition` if
786 /// `otherPosition + otherNumChars > other.length()`). Return a
787 /// negative value if the indicated subview of this view is less than
788 /// the indicated subview of `other`, a positive value if it is greater
789 /// than the indicated subview of `other`, and 0 in case of equality.
790 /// Throw `std::out_of_range` if `lhsPosition > length()` or
791 /// `otherPosition > other.length()`. See {Lexicographical
792 /// Comparisons}.
794 int compare(size_type lhsPosition,
795 size_type lhsNumChars,
796 basic_string_view other,
797 size_type otherPosition,
798 size_type otherNumChars) const;
799
800 /// Lexicographically compare this view with the specified
801 /// null-terminated `other` string (of length
802 /// `CHAR_TRAITS::length(other)`), and return a negative value if this
803 /// view is less than `other`, a positive value if it is greater than
804 /// `other`, and 0 in case of equality.
805 ///
806 /// \pre The behavior is undefined unless `other` is a null-terminated string.
808 int compare(const CHAR_TYPE *other) const;
809
810 /// Lexicographically compare the subview of this view of the specified
811 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
812 /// suffix of this view starting at `lhsPosition` if
813 /// `lhsPosition + lhsNumChars > length()`) with the specified
814 /// null-terminated `other` string (of length
815 /// `CHAR_TRAITS::length(other)`), and return a negative value if the
816 /// indicated subview of this view is less than `other`, a positive
817 /// value if it is greater than `other`, and 0 in case of equality.
818 /// Throw `std::out_of_range` if `lhsPosition > length()`.
820 int compare(size_type lhsPosition,
821 size_type lhsNumChars,
822 const CHAR_TYPE *other) const;
823
824 /// Lexicographically compare the subview of this view of the specified
825 /// `lhsNumChars` length starting at the specified `lhsPosition` (or the
826 /// suffix of this view starting at `lhsPosition` if
827 /// `lhsPosition + lhsNumChars > length()`) with the specified `other`
828 /// string of the specified `otherNumChars` length, and return a
829 /// negative value if the indicated subview of this view is less than
830 /// `other`, a positive value if it is greater than `other`, and 0 in
831 /// case of equality. `CHAR_TRAITS::lt` is used to compare characters.
832 /// Throw `std::out_of_range` if `lhsPosition > length()`.
833 ///
834 /// \pre The behavior is undefined unless `other || 0 == otherNumChars`.
836 int compare(size_type lhsPosition,
837 size_type lhsNumChars,
838 const CHAR_TYPE *other,
839 size_type otherNumChars) const;
840
841 /// Return `true` if this view contains with the specified `subview`, and
842 /// `false` otherwise. See {Lexicographical Comparisons}.
845
846 /// Return `true` if this view contains with the specified `character`,
847 /// and `false` otherwise.
849 bool contains(CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT;
850
851 /// Return `true` if this view contains with the specified
852 /// `characterString`, and `false` otherwise.
854 bool contains(const CHAR_TYPE* characterString) const;
855
856 /// Return `true` if this view starts with the specified `subview`, and
857 /// `false` otherwise. See {Lexicographical Comparisons}.
860
861 /// Return `true` if this view starts with the specified `character`,
862 /// and `false` otherwise.
864 bool starts_with(CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT;
865
866 /// Return `true` if this view starts with the specified
867 /// `characterString`, and `false` otherwise.
869 bool starts_with(const CHAR_TYPE* characterString) const;
870
871 /// Return `true` if this view ends with the specified `subview`, and
872 /// `false` otherwise. See {Lexicographical Comparisons}.
875
876 // Return `true` if this view ends with the specified `character`, and
877 // `false` otherwise.
879 bool ends_with(CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT;
880
881 /// Return `true` if this view ends with the specified
882 /// `characterString`, and `false` otherwise.
884 bool ends_with(const CHAR_TYPE* characterString) const;
885
886 /// Return the starting position of the *first* occurrence of the
887 /// specified `subview`, if it can be found in this view (on or *after*
888 /// the optionally specified `position`) using `CHAR_TRAITS::eq` to
889 /// compare characters, and return `npos` otherwise.
892 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
893
894 /// Return the starting position of the *first* occurrence of the
895 /// specified `characterString` of the specified `numChars` length, if
896 /// such a string can be found in this view (on or *after* the specified
897 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and return `npos` otherwise.
898 ///
899 /// \pre The behavior is undefined unless
900 /// `characterString || (numChars == 0)`.
902 size_type find(const CHAR_TYPE *characterString,
903 size_type position,
904 size_type numChars) const;
905
906 /// Return the starting position of the *first* occurrence of the
907 /// specified null-terminated `characterString`, if such a string can be
908 /// found in this view (on or *after* the optionally specified
909 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
910 /// return `npos` otherwise.
912 size_type find(const CHAR_TYPE *characterString,
913 size_type position = 0) const;
914
915 /// Return the position of the *first* occurrence of the specified
916 /// `character`, if such an occurrence can be found in this view (on or
917 /// *after* the optionally specified `position` if such a `position` is
918 /// specified), and return `npos` otherwise.
920 size_type find(CHAR_TYPE character,
921 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
922
923 /// Return the starting position of the *last* occurrence of the
924 /// specified `subview` within this view, if such a sequence can be
925 /// found in this view (on or *before* the optionally specified
926 /// `position` if such a `position` is specified) using
927 /// `CHAR_TRAITS::eq` to compare characters, and return `npos`
928 /// otherwise.
931 basic_string_view subview,
932 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
933
934 /// Return the starting position of the *last* occurrence of the
935 /// specified `characterString` of the specified `numChars` length, if
936 /// such a string can be found in this view (on or *after* the specified
937 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and return `npos` otherwise.
938 ///
939 /// \pre The behavior is undefined unless
940 /// `characterString || (numChars == 0)`.
942 size_type rfind(const CHAR_TYPE *characterString,
943 size_type position,
944 size_type numChars) const;
945
946 /// Return the starting position of the *last* occurrence of the
947 /// specified null-terminated `characterString`, if such a string can be
948 /// found in this view (on or *after* the optionally specified
949 /// `position`) using `CHAR_TRAITS::eq` to compare characters, and
950 /// return `npos` otherwise.
952 size_type rfind(const CHAR_TYPE *characterString,
953 size_type position = npos) const;
954
955 /// Return the position of the *last* occurrence of the specified
956 /// `character`, if such an occurrence can be found in this view (on or
957 /// *before* the optionally specified `position` if such a `position` is
958 /// specified), and return `npos` otherwise.
960 size_type rfind(CHAR_TYPE character,
961 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
962
963 /// Return the position of the *first* occurrence of a character
964 /// belonging to the specified `subview`, if such an occurrence can be
965 /// found in this view (on or *after* the optionally specified
966 /// `position` if such a `position` is specified), and return `npos`
967 /// otherwise.
969 size_type find_first_of(
970 basic_string_view subview,
971 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
972
973 /// Return the position of the *first* occurrence of a character
974 /// belonging to the specified `characterString` of the specified
975 /// `numChars` length, if such a string can be found in this view (on or
976 /// *after* the specified `position`) using `CHAR_TRAITS::eq` to compare
977 /// characters, and return `npos` otherwise.
978 ///
979 /// \pre The behavior is undefined unless `characterString || (numChars == 0)`.
981 size_type find_first_of(const CHAR_TYPE *characterString,
982 size_type position,
983 size_type numChars) const;
984
985 /// Return the position of the *first* occurrence of a character
986 /// belonging to the specified `characterString`, if such an occurrence
987 /// can be found in this view (on or *after* the optionally specified
988 /// `position`), and return `npos` otherwise.
990 size_type find_first_of(const CHAR_TYPE *characterString,
991 size_type position = 0) const;
992
993 /// Return the position of the *first* occurrence of the specified
994 /// `character`, if such an occurrence can be found in this view (on or
995 /// *after* the optionally specified `position` if such a `position` is
996 /// specified), and return `npos` otherwise.
998 size_type find_first_of(
999 CHAR_TYPE character,
1000 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
1001
1002 /// Return the position of the *last* occurrence of a character
1003 /// belonging to the specified `subview`, if such an occurrence can be
1004 /// found in this view (on or *before* the optionally specified
1005 /// `position` if such a `position` is specified), and return `npos`
1006 /// otherwise.
1009 basic_string_view subview,
1010 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1011
1012 /// Return the position of the *last* occurrence of a character
1013 /// belonging to the specified `characterString` of the specified
1014 /// `numChars` length, if such a string can be found in this view (on or
1015 /// *after* the specified `position`) using `CHAR_TRAITS::eq` to compare
1016 /// characters, and return `npos` otherwise.
1017 ///
1018 /// \pre The behavior is undefined unless `characterString || (numChars == 0)`.
1020 size_type find_last_of(const CHAR_TYPE *characterString,
1021 size_type position,
1022 size_type numChars) const;
1023
1024 /// Return the position of the *last* occurrence of a character
1025 /// belonging to the specified `characterString`, if such an occurrence
1026 /// can be found in this view (on or *after* the optionally specified
1027 /// `position`), and return `npos` otherwise.
1029 size_type find_last_of(const CHAR_TYPE *characterString,
1030 size_type position = npos) const;
1031
1032 /// Return the position of the *last* occurrence of the specified
1033 /// `character`, if such an occurrence can be found in this view (on or
1034 /// *before* the optionally specified `position` if such a `position` is
1035 /// specified), and return `npos` otherwise.
1038 CHAR_TYPE character,
1039 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1040
1041 /// Return the position of the *first* occurrence of a character *not*
1042 /// belonging to the specified `subview`, if such an occurrence can be
1043 /// found in this view (on or *after* the optionally specified
1044 /// `position` if such a `position` is specified), and return `npos`
1045 /// otherwise.
1048 basic_string_view subview,
1049 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
1050
1051 /// Return the position of the *first* occurrence of a character *not*
1052 /// belonging to the specified `characterString` of the specified
1053 /// `numChars` length, if such an occurrence can be found in this view
1054 /// (on or *after* the specified `position`) using `CHAR_TRAITS::eq` to
1055 /// compare characters, and return `npos` otherwise.
1056 ///
1057 /// \pre The behavior is undefined unless `characterString || (numChars == 0)`.
1059 size_type find_first_not_of(const CHAR_TYPE *characterString,
1060 size_type position,
1061 size_type numChars) const;
1062
1063 /// Return the position of the *first* occurrence of a character *not*
1064 /// belonging to the specified `characterString`, if such an occurrence
1065 /// can be found in this view (on or *after* the optionally specified
1066 /// `position`), and return `npos` otherwise.
1068 size_type find_first_not_of(const CHAR_TYPE *characterString,
1069 size_type position = 0) const;
1070
1071 /// Return the position of the *first* occurrence of a character
1072 /// *different* from the specified `character`, if such an occurrence
1073 /// can be found in this view (on or *after* the optionally specified
1074 /// `position` if such a `position` is specified), and return `npos`
1075 /// otherwise.
1078 CHAR_TYPE character,
1079 size_type position = 0) const BSLS_KEYWORD_NOEXCEPT;
1080
1081 /// Return the position of the *last* occurrence of a character *not*
1082 /// belonging to the specified `subview`, if such an occurrence can be
1083 /// found in this view (on or *before* the optionally specified
1084 /// `position` if such a `position` is specified), and return `npos`
1085 /// otherwise.
1088 basic_string_view subview,
1089 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1090
1091 /// Return the position of the *last* occurrence of a character *not*
1092 /// belonging to the specified `characterString` of the specified
1093 /// `numChars` length, if such an occurrence can be found in this view
1094 /// (on or *after* the specified `position`) using `CHAR_TRAITS::eq` to
1095 /// compare characters, and return `npos` otherwise.
1096 ///
1097 /// \pre The behavior is undefined unless `characterString || (numChars == 0)`.
1099 size_type find_last_not_of(const CHAR_TYPE *characterString,
1100 size_type position,
1101 size_type numChars) const;
1102
1103 /// Return the position of the *last* occurrence of a character *not*
1104 /// belonging to the specified `characterString`, if such an occurrence
1105 /// can be found in this view (on or *after* the optionally specified
1106 /// `position`), and return `npos` otherwise.
1108 size_type find_last_not_of(const CHAR_TYPE *characterString,
1109 size_type position = npos) const;
1110
1111 /// Return the position of the *last* occurrence of a character
1112 /// *different* from the specified `character`, if such an occurrence
1113 /// can be found in this view (on or *before* the optionally specified
1114 /// `position` if such a `position` is specified), and return `npos`
1115 /// otherwise.
1118 CHAR_TYPE character,
1119 size_type position = npos) const BSLS_KEYWORD_NOEXCEPT;
1120
1121 // *** BDE compatibility with platform libraries: ***
1122
1123 /// Convert this `const` object to a string type native to the
1124 /// compiler`s library, instantiated with the same character type and
1125 /// traits type. The return string will contain the same sequence of
1126 /// characters as this object and will have a default-constructed
1127 /// allocator.
1128 template <class ALLOCATOR>
1130 operator std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>()
1131 const
1132 {
1133 // See {DRQS 131792157} for why this is inline.
1134 return std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>(d_start_p,
1135 d_length);
1136 }
1137
1138#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1139 /// Convert this object to a `std::basic_string_view`.
1140 constexpr operator std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>() const;
1141
1142 // HIDDEN FRIENDS
1143 friend constexpr
1144 bool operator==(basic_string_view lhs,
1145 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs)
1146 noexcept
1147 {
1148 return std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>{
1149 lhs.data(), lhs.length()} == rhs;
1150 }
1151
1152#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1153 friend constexpr
1154 auto operator<=>(basic_string_view lhs,
1155 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs)
1156 noexcept
1157 {
1158 return std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>{
1159 lhs.data(), lhs.length()} <=> rhs;
1160 }
1161
1162#else // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1163 friend constexpr
1164 bool operator==(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1166 noexcept
1167 {
1168 return rhs == lhs;
1169 }
1170
1171 friend constexpr
1173 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs)
1174 noexcept
1175 {
1176 return !(lhs == rhs);
1177 }
1178
1179 friend constexpr
1180 bool operator!=(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1182 noexcept
1183 {
1184 return !(lhs == rhs);
1185 }
1186
1187 friend constexpr
1189 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs) noexcept
1190 {
1191 return std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>{
1192 lhs.data(), lhs.length()} < rhs;
1193 }
1194
1195 friend constexpr
1196 bool operator<(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1197 basic_string_view rhs) noexcept
1198 {
1199 return lhs < std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>{
1200 rhs.data(), rhs.length()};
1201 }
1202
1203 friend constexpr
1205 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs) noexcept
1206 {
1207 return rhs < lhs;
1208 }
1209
1210 friend constexpr
1211 bool operator>(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1212 basic_string_view rhs) noexcept
1213 {
1214 return rhs < lhs;
1215 }
1216
1217 friend constexpr
1219 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs)
1220 noexcept
1221 {
1222 return !(rhs < lhs);
1223 }
1224
1225 friend constexpr
1226 bool operator<=(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1228 noexcept
1229 {
1230 return !(rhs < lhs);
1231 }
1232
1233 friend constexpr
1235 std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> rhs)
1236 noexcept
1237 {
1238 return !(lhs < rhs);
1239 }
1240
1241 friend constexpr
1242 bool operator>=(std::basic_string_view<CHAR_TYPE, CHAR_TRAITS> lhs,
1244 noexcept
1245 {
1246 return !(lhs < rhs);
1247 }
1248#endif // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1249#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1250};
1251
1252// TYPEDEFS
1255
1256#if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
1257typedef basic_string_view<char8_t> u8string_view;
1258#endif
1259
1260#if defined(BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES)
1261typedef basic_string_view<char16_t> u16string_view;
1262typedef basic_string_view<char32_t> u32string_view;
1263#endif
1264
1265// FREE FUNCTIONS
1266
1267/// Exchange the value of the specified `a` object with the value of the
1268/// specified `b` object.
1269template <class CHAR_TYPE, class CHAR_TRAITS>
1272
1273} // close namespace bsl
1274
1275
1277
1278 // =============================
1279 // struct StringView_CompareUtil
1280 // =============================
1281
1282/// This component-private utility `struct` contains functions for comparing
1283/// two @ref string_view objects. This functionality is needed to implement
1284/// the comparison operators operating on string_view objects without
1285/// resorting to code duplication or delegating directly between different
1286/// overloads of the same operator. The need to avoid delegation to
1287/// overloads stems from a bug in xlC 12 on AIX leading to incorrect
1288/// overload resolution and infinite recursion.
1289///
1290/// See @ref bslstl_stringview
1291template <class CHAR_TYPE, class CHAR_TRAITS>
1293
1294 // TYPES
1296
1297 // CLASS METHODS
1298
1299 /// Return `true` if `lhs == rhs` and `false` otherwise.
1300 static
1303
1304 /// Return `true` if `lhs < rhs` and `false` otherwise.
1305 static
1308};
1309
1310// FREE OPERATORS
1311
1312/// Return `true` if the specified `lhs` view has the same value as the
1313/// specified `rhs` view, and `false` otherwise. Two views have the same
1314/// value if they have the same length, and the characters at each
1315/// respective position have the same value according to `CHAR_TRAITS::eq`.
1316template <class CHAR_TYPE, class CHAR_TRAITS>
1321template <class CHAR_TYPE, class CHAR_TRAITS>
1323bool operator==(
1324 typename BloombergLP::bslstl::StringView_Identity<
1328template <class CHAR_TYPE, class CHAR_TRAITS>
1330bool operator==(
1332 typename BloombergLP::bslstl::StringView_Identity<
1335
1336/// Return `true` if the specified `lhs` view has a different value from the
1337/// specified `rhs` view, and `false` otherwise. Two views have the same
1338/// value if they have the same length, and the characters at each
1339/// respective position have the same value according to `CHAR_TRAITS::eq`.
1340template <class CHAR_TYPE, class CHAR_TRAITS>
1345template <class CHAR_TYPE, class CHAR_TRAITS>
1347bool operator!=(
1348 typename BloombergLP::bslstl::StringView_Identity<
1352template <class CHAR_TYPE, class CHAR_TRAITS>
1354bool operator!=(
1356 typename BloombergLP::bslstl::StringView_Identity<
1359
1360/// Return `true` if the specified `lhs` view has a lexicographically
1361/// smaller value than the specified `rhs` view, and `false` otherwise. See
1362/// {Lexicographical Comparisons}.
1363template <class CHAR_TYPE, class CHAR_TRAITS>
1368template <class CHAR_TYPE, class CHAR_TRAITS>
1370bool operator<(
1371 typename BloombergLP::bslstl::StringView_Identity<
1375template <class CHAR_TYPE, class CHAR_TRAITS>
1377bool operator<(
1379 typename BloombergLP::bslstl::StringView_Identity<
1382
1383/// Return `true` if the specified `lhs` view has a lexicographically larger
1384/// value than the specified `rhs` view, and `false` otherwise. See
1385/// {Lexicographical Comparisons}.
1386template <class CHAR_TYPE, class CHAR_TRAITS>
1391template <class CHAR_TYPE, class CHAR_TRAITS>
1393bool operator>(
1394 typename BloombergLP::bslstl::StringView_Identity<
1398template <class CHAR_TYPE, class CHAR_TRAITS>
1400bool operator>(
1402 typename BloombergLP::bslstl::StringView_Identity<
1405
1406/// Return `true` if the specified `lhs` view has a value lexicographically
1407/// smaller than or or equal to the specified `rhs` view, and `false`
1408/// otherwise. See {Lexicographical Comparisons}.
1409template <class CHAR_TYPE, class CHAR_TRAITS>
1414template <class CHAR_TYPE, class CHAR_TRAITS>
1416bool operator<=(
1417 typename BloombergLP::bslstl::StringView_Identity<
1421template <class CHAR_TYPE, class CHAR_TRAITS>
1423bool operator<=(
1425 typename BloombergLP::bslstl::StringView_Identity<
1428
1429/// Return `true` if the specified `lhs` view has a value lexicographically
1430/// larger than or equal to the specified `rhs` view, and `false` otherwise.
1431/// See {Lexicographical Comparisons}.
1432template <class CHAR_TYPE, class CHAR_TRAITS>
1437template <class CHAR_TYPE, class CHAR_TRAITS>
1439bool operator>=(
1440 typename BloombergLP::bslstl::StringView_Identity<
1444template <class CHAR_TYPE, class CHAR_TRAITS>
1446bool operator>=(
1448 typename BloombergLP::bslstl::StringView_Identity<
1451
1452} // close namespace bslstl_stringview_relops
1453
1454
1455namespace bsl {
1456
1457/// Write the value of the string bound to the specified `stringView` to the
1458/// specified output `stream` and return a reference to the modifiable
1459/// `stream`.
1460template <class CHAR_TYPE, class CHAR_TRAITS>
1461std::basic_ostream<CHAR_TYPE>&
1462operator<<(std::basic_ostream<CHAR_TYPE>& stream,
1463 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView);
1464
1465// HASH SPECIALIZATIONS
1466
1467/// Pass the specified `input` string to the specified `hashAlg` hashing
1468/// algorithm of the (template parameter) type `HASHALG`.
1469template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
1470void hashAppend(HASHALG& hashAlg,
1472
1473/// Specialize `bsl::hash` for strings, including an overload for pointers
1474/// to allow character arrays to be hashed without converting them first.
1475template <class CHAR_TYPE, class CHAR_TRAITS>
1477 : ::BloombergLP::bslh::Hash<>
1478{
1479 // PUBLIC ACCESSORS
1480
1481 /// Compute and return the hash value of the specified `input`.
1482 std::size_t operator()(
1484
1485 /// Compute and return the hash value of the contents of the specified
1486 /// null-terminated `input`. This value will be the same as the hash
1487 /// value of a @ref basic_string_view constructed from `input`.
1488 std::size_t operator()(const CHAR_TYPE *input) const;
1489};
1490
1491#if defined(BSLS_PLATFORM_CMP_SUN) // {DRQS 132030795}
1492
1493// Sun CC 12.3 has trouble with the partial specializations above in certain
1494// circumstances (see {DRQS 132030795}). Adding these explicit specializations
1495// for @ref string_view and @ref wstring_view makes the problematic cases work.
1496
1497template <>
1498struct hash<string_view> : ::BloombergLP::bslh::Hash<>
1499{
1500 // PUBLIC ACCESSORS
1501
1502 /// Compute and return the hash value of the specified `input`.
1503 std::size_t operator()(const string_view& input) const;
1504
1505 /// Compute and return the hash value of the contents of the specified
1506 /// null-terminated `input`. This value will be the same as the hash
1507 /// value of a @ref basic_string_view constructed from `input`.
1508 std::size_t operator()(const char *input) const;
1509};
1510
1511template <>
1512struct hash<wstring_view> : ::BloombergLP::bslh::Hash<>
1513{
1514 // PUBLIC ACCESSORS
1515
1516 /// Compute and return the hash value of the specified `input`.
1517 std::size_t operator()(const wstring_view& input) const;
1518
1519 /// Compute and return the hash value of the contents of the specified
1520 /// null-terminated `input`. This value will be the same as the hash
1521 /// value of a @ref basic_string_view constructed from `input`.
1522 std::size_t operator()(const wchar_t *input) const;
1523};
1524
1525#endif // defined(BSLS_PLATFORM_CMP_SUN)
1526
1527} // close namespace bsl
1528
1529#endif // BSLSTL_STRING_VIEW_IS_ALIASED
1530
1531#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) && \
1532 defined (BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE)
1533namespace bsl {
1534inline namespace literals {
1535inline namespace string_view_literals {
1536
1537// FREE OPERATORS
1538
1539/// Convert a character sequence of the specified `length` excluding the
1540/// terminating null character starting at the beginning of the specified
1541/// `characterString` to a string_view object of the indicated return type.
1542/// (See the "User-Defined Literals" section in the component-level
1543/// documentation.)
1544///
1545/// Example:
1546/// @code
1547/// using namespace bsl::string_view_literals;
1548/// bsl::string_view sv1 = "123\0abc";
1549/// bsl::string_view sv2 = "123\0abc"_sv;
1550/// assert(3 == sv1.size());
1551/// assert(7 == sv2.size());
1552///
1553/// bsl::wstring_view sv3 = L"123\0abc"_sv;
1554/// assert(7 == sv3.size());
1555/// @endcode
1556 string_view operator ""_sv(const char *characterString,
1557 std::size_t length);
1558wstring_view operator ""_sv(const wchar_t *characterString,
1559 std::size_t length);
1560
1561} // close namespace string_view_literals
1562} // close namespace literals
1563} // close namespace bsl
1564#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY &&
1565 // BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE
1566
1567#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
1568
1569namespace bslh {
1570
1571/// Pass the specified `input` string to the specified `hashAlg` hashing algorithm of the (template parameter) type `HASHALG`.
1572///
1573/// \note Note that this
1574/// function violates the BDE coding standard, adding a function for a
1575/// namespace for a different package, and none of the function parameters
1576/// are from this package either. This is necessary in order to provide an
1577/// implementation of `bslh::hashAppend` for the (native) standard library
1578/// @ref string_view type as we are not allowed to add overloads directly into
1579/// namespace `std`, and this component essentially provides the interface
1580/// between `bsl` and `std` string types.
1581template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
1583void hashAppend(HASHALG& hashAlg,
1584 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input);
1585
1586} // close namespace bslh
1587
1588#endif // BSLSTL_STRING_VIEW_IS_ALIASED
1589
1590// ============================================================================
1591// INLINE FUNCTION DEFINITIONS
1592// ============================================================================
1593
1594#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
1595
1596#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
1597
1598
1599namespace bslstl {
1600
1601template <class TYPE>
1602template <class ARG_TYPE>
1603inline
1604StringView_Identity<TYPE>::type::type(
1605 const ARG_TYPE& argument,
1607 int>::type)
1608: d_value(argument)
1609{}
1610
1611// MANIPULATORS
1612template <class TYPE>
1613inline
1614TYPE& StringView_Identity<TYPE>::type::operator=(const TYPE& rhs)
1615{
1616 d_value = rhs;
1617
1618 return d_value;
1619}
1620
1621template <class TYPE>
1622inline
1623StringView_Identity<TYPE>::type::operator TYPE&()
1624{
1625 return d_value;
1626}
1627
1628// ACCESSOR
1629template <class TYPE>
1630inline
1631StringView_Identity<TYPE>::type::operator const TYPE&() const
1632{
1633 return d_value;
1634}
1635
1636} // close package namespace
1637
1638
1639#endif
1640
1641namespace bsl {
1642
1643 // -----------------------
1644 // class basic_string_view
1645 // -----------------------
1646
1647// CLASS DATA
1648template <class CHAR_TYPE, class CHAR_TRAITS>
1651
1652// PRIVATE ACCESSORS
1653template <class CHAR_TYPE, class CHAR_TRAITS>
1655int basic_string_view<CHAR_TYPE,CHAR_TRAITS>::privateCompareRaw(
1656 size_type lhsPosition,
1657 size_type lhsNumChars,
1658 const CHAR_TYPE *other,
1659 size_type otherNumChars) const
1660{
1661 BSLS_ASSERT_SAFE(lhsPosition <= length());
1662
1663 size_type numChars = lhsNumChars < otherNumChars ? lhsNumChars
1664 : otherNumChars;
1665 int cmpResult = CHAR_TRAITS::compare(data() + lhsPosition,
1666 other,
1667 numChars);
1668 if (cmpResult) {
1669 return cmpResult; // RETURN
1670 }
1671 if (lhsNumChars < otherNumChars) {
1672 return -1; // RETURN
1673 }
1674 if (lhsNumChars > otherNumChars) {
1675 return 1; // RETURN
1676 }
1677 return 0;
1678}
1679
1680// CREATORS
1681template <class CHAR_TYPE, class CHAR_TRAITS>
1682inline
1689
1690template <class CHAR_TYPE, class CHAR_TRAITS>
1694 const CHAR_TYPE *characterString)
1695: d_start_p(characterString)
1696, d_length(characterString ? CHAR_TRAITS::length(characterString) : 0)
1697{
1698 BSLS_ASSERT_SAFE(characterString);
1699 BSLS_ASSERT_SAFE(d_length <= max_size());
1700}
1701
1702template <class CHAR_TYPE, class CHAR_TRAITS>
1706 const CHAR_TYPE *characterString,
1707 size_type numChars)
1708: d_start_p(characterString)
1709, d_length(numChars)
1710{
1711 BSLS_ASSERT_SAFE(characterString || (numChars == 0));
1712 BSLS_ASSERT_SAFE(numChars <= max_size());
1713}
1714
1715template <class CHAR_TYPE, class CHAR_TRAITS>
1716#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY)
1717template <class CONTIG_ITER, class SENTINEL>
1721 CONTIG_ITER first,
1722 SENTINEL last,
1723 typename
1726 decltype(&(*std::declval<CONTIG_ITER>())),
1727 const CHAR_TYPE*
1728 >::value
1730 >::type *)
1731#else
1732template <class CONTIG_ITER, class SENTINEL>
1736 CONTIG_ITER first,
1737 SENTINEL last,
1738 typename
1742 >::type *)
1743#endif
1744: d_start_p(
1745#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY
1746 std::to_address(first)
1747#else
1748 first
1749#endif
1750 )
1751, d_length(last - first)
1752{
1753 BSLS_ASSERT_SAFE(last - first >= 0);
1754
1755 // we test the computed values because we do not want to
1756 // impose additional requirements on our template parameters
1757 BSLS_ASSERT_SAFE(d_start_p || d_length == 0);
1758}
1759
1760template <class CHAR_TYPE, class CHAR_TRAITS>
1761template <class ALLOCATOR>
1764 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& str)
1765: d_start_p(str.data())
1766, d_length(str.size())
1767{
1768}
1769
1770#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1771template <class CHAR_TYPE, class CHAR_TRAITS>
1775 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view)
1776: d_start_p(view.data())
1777, d_length (view.size())
1778{
1779}
1780#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1781
1782// MANIPULATORS
1783template <class CHAR_TYPE, class CHAR_TRAITS>
1784template <class ALLOCATOR>
1787basic_string_view<CHAR_TYPE, CHAR_TRAITS>&
1789 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
1791{
1792 d_start_p = rhs.data();
1793 d_length = rhs.size();
1794 return *this;
1795}
1796
1797template <class CHAR_TYPE, class CHAR_TRAITS>
1799void
1801{
1802 BSLS_ASSERT_SAFE(d_length >= numChars);
1803 d_start_p += numChars;
1804 d_length -= numChars;
1805}
1806
1807template <class CHAR_TYPE, class CHAR_TRAITS>
1809void
1811{
1812 BSLS_ASSERT_SAFE(d_length >= numChars);
1813 d_length -= numChars;
1814}
1815
1816template <class CHAR_TYPE, class CHAR_TRAITS>
1817void
1820{
1821 BloombergLP::bslalg::ScalarPrimitives::swap(d_length, other.d_length);
1822 BloombergLP::bslalg::ScalarPrimitives::swap(d_start_p, other.d_start_p);
1823}
1824
1825// ACCESSORS
1826template <class CHAR_TYPE, class CHAR_TRAITS>
1827inline
1834
1835template <class CHAR_TYPE, class CHAR_TRAITS>
1836inline
1843
1844template <class CHAR_TYPE, class CHAR_TRAITS>
1845inline
1850{
1851 return begin() + d_length;
1852}
1853
1854template <class CHAR_TYPE, class CHAR_TRAITS>
1855inline
1862
1863template <class CHAR_TYPE, class CHAR_TRAITS>
1864inline
1871
1872template <class CHAR_TYPE, class CHAR_TRAITS>
1873inline
1881
1882template <class CHAR_TYPE, class CHAR_TRAITS>
1890
1891template <class CHAR_TYPE, class CHAR_TRAITS>
1899
1900template <class CHAR_TYPE, class CHAR_TRAITS>
1901inline
1908
1909template <class CHAR_TYPE, class CHAR_TRAITS>
1910inline
1917
1918template <class CHAR_TYPE, class CHAR_TRAITS>
1919inline
1924{
1925 return (npos - 1) / sizeof(CHAR_TYPE);
1926}
1927
1928template <class CHAR_TYPE, class CHAR_TRAITS>
1929inline
1933{
1934 return (0 == d_length);
1935}
1936
1937template <class CHAR_TYPE, class CHAR_TRAITS>
1938inline
1942{
1943 BSLS_ASSERT_SAFE(position < length());
1944
1945 return *(begin() + position);
1946}
1947
1948template <class CHAR_TYPE, class CHAR_TRAITS>
1953{
1954 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position >= length())) {
1956 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1957 "string_view::at(n): invalid position");
1958 }
1959 return *(begin() + position);
1960}
1961
1962template <class CHAR_TYPE, class CHAR_TRAITS>
1963inline
1967{
1969
1970 return *begin();
1971}
1972
1973template <class CHAR_TYPE, class CHAR_TRAITS>
1974inline
1978{
1980
1981 return *(end() - 1);
1982}
1983
1984template <class CHAR_TYPE, class CHAR_TRAITS>
1985inline
1992
1993template <class CHAR_TYPE, class CHAR_TRAITS>
1996 size_type numChars,
1997 size_type position) const
1998{
1999
2000 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position > length())) {
2002 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2003 "string_view::copy(str,pos,n): invalid position");
2004 }
2005
2006 BSLS_ASSERT_SAFE(characterString);
2007
2008 if (numChars > length() - position) {
2009 numChars = length() - position;
2010 }
2011
2012 // Check that the destination buffer start is not within the source.
2013 BSLS_ASSERT_SAFE(std::less<const CHAR_TYPE *>()(
2014 characterString, d_start_p + position) ||
2015 std::greater_equal<const CHAR_TYPE *>()(
2016 characterString, d_start_p + position + numChars));
2017
2018 CHAR_TRAITS::move(characterString, d_start_p + position, numChars);
2019
2020 return numChars;
2021}
2022
2023template <class CHAR_TYPE, class CHAR_TRAITS>
2028 size_type numChars) const
2029{
2030 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position > length())) {
2032 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2033 "string_view::substr(pos,n): invalid position");
2034 }
2035
2036 const size_type maxLen = length() - position;
2037
2039 data() + position,
2040 numChars < maxLen ? numChars : maxLen);
2041}
2042
2043template <class CHAR_TYPE, class CHAR_TRAITS>
2048{
2049 return privateCompareRaw(size_type(0),
2050 length(),
2051 other.data(),
2052 other.length());
2053}
2054
2055template <class CHAR_TYPE, class CHAR_TRAITS>
2059 size_type position,
2060 size_type numChars,
2061 basic_string_view other) const
2062{
2063 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < position)) {
2065 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2066 "const string_view<...>::compare(pos,n, other): invalid position");
2067 }
2068
2069 if (numChars > length() - position) {
2070 numChars = length() - position;
2071 }
2072 return privateCompareRaw(position, numChars, other.data(), other.length());
2073}
2074
2075template <class CHAR_TYPE, class CHAR_TRAITS>
2079 size_type lhsPosition,
2080 size_type lhsNumChars,
2081 basic_string_view other,
2082 size_type otherPosition,
2083 size_type otherNumChars) const
2084{
2085 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
2087 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2088 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
2089 ": invalid lhs position");
2090 }
2091
2092 if (lhsNumChars > length() - lhsPosition) {
2093 lhsNumChars = length() - lhsPosition;
2094 }
2095
2097 other.length() < otherPosition)) {
2099 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2100 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
2101 ": invalid rhs position");
2102 }
2103
2104 if (otherNumChars > other.length() - otherPosition) {
2105 otherNumChars = other.length() - otherPosition;
2106 }
2107 return privateCompareRaw(lhsPosition,
2108 lhsNumChars,
2109 other.data() + otherPosition,
2110 otherNumChars);
2111}
2112
2113template <class CHAR_TYPE, class CHAR_TRAITS>
2117 const CHAR_TYPE *other) const
2118{
2119 BSLS_ASSERT_SAFE(other);
2120
2121 size_type otherLength = CHAR_TRAITS::length(other);
2122
2123 return privateCompareRaw(size_type(0),
2124 length(),
2125 other,
2126 otherLength);
2127}
2128
2129template <class CHAR_TYPE, class CHAR_TRAITS>
2133 size_type lhsPosition,
2134 size_type lhsNumChars,
2135 const CHAR_TYPE *other) const
2136{
2137 BSLS_ASSERT_SAFE(other);
2138
2139 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
2141 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2142 "const string_view<...>::compare(pos,n,other): invalid position");
2143 }
2144
2145 size_type otherLength = CHAR_TRAITS::length(other);
2146
2147 if (lhsNumChars > length() - lhsPosition) {
2148 lhsNumChars = length() - lhsPosition;
2149 }
2150
2151 return compare(lhsPosition,
2152 lhsNumChars,
2153 other,
2154 otherLength);
2155}
2156
2157template <class CHAR_TYPE, class CHAR_TRAITS>
2161 size_type lhsPosition,
2162 size_type lhsNumChars,
2163 const CHAR_TYPE *other,
2164 size_type otherNumChars) const
2165{
2166 BSLS_ASSERT_SAFE(other || 0 == otherNumChars);
2167
2168 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(length() < lhsPosition)) {
2170 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2171 "const string_view<...>::compare(pos,n,other,other_pos)"
2172 ": invalid position");
2173 }
2174
2175 if (lhsNumChars > length() - lhsPosition) {
2176 lhsNumChars = length() - lhsPosition;
2177 }
2178 return privateCompareRaw(lhsPosition,
2179 lhsNumChars,
2180 other,
2181 otherNumChars);
2182}
2183
2184template <class CHAR_TYPE, class CHAR_TRAITS>
2189{
2190 return npos != find(subview);
2191}
2192
2193template <class CHAR_TYPE, class CHAR_TRAITS>
2197 CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT
2198{
2199 return npos != find(character);
2200}
2201
2202template <class CHAR_TYPE, class CHAR_TRAITS>
2206 const CHAR_TYPE* characterString) const
2207{
2208 BSLS_ASSERT_SAFE(characterString);
2209 return npos != find(characterString);
2210}
2211
2212template <class CHAR_TYPE, class CHAR_TRAITS>
2217{
2218 return (size() >= subview.size() &&
2219 0 == compare(0, subview.size(), subview));
2220}
2221
2222template <class CHAR_TYPE, class CHAR_TRAITS>
2226 CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT
2227{
2228 return (!empty() && CHAR_TRAITS::eq(front(), character));
2229}
2230
2231template <class CHAR_TYPE, class CHAR_TRAITS>
2235 const CHAR_TYPE* characterString) const
2236{
2237 BSLS_ASSERT_SAFE(characterString);
2238 for (size_type i = 0; i < d_length; ++i) {
2239 if (characterString[i] == 0) {
2240 // Ran out of characterString, so is prefix.
2241 return true; // RETURN
2242 }
2243 if (d_start_p[i] != characterString[i]) {
2244 // Mismatch.
2245 return false; // RETURN
2246 }
2247 }
2248 // Ran out of string_view, so check characterString is not longer.
2249 return characterString[d_length] == 0;
2250}
2251
2252template <class CHAR_TYPE, class CHAR_TRAITS>
2257{
2258 return (size() >= subview.size() &&
2259 0 == compare(size() - subview.size(), npos, subview));
2260}
2261
2262template <class CHAR_TYPE, class CHAR_TRAITS>
2266 CHAR_TYPE character) const BSLS_KEYWORD_NOEXCEPT
2267{
2268 return (!empty() && CHAR_TRAITS::eq(back(), character));
2269}
2270
2271template <class CHAR_TYPE, class CHAR_TRAITS>
2275 const CHAR_TYPE* characterString) const
2276{
2277 return ends_with(basic_string_view(characterString));
2278}
2279
2280template <class CHAR_TYPE, class CHAR_TRAITS>
2285 basic_string_view subview,
2286 size_type position) const BSLS_KEYWORD_NOEXCEPT
2287{
2288 return find(subview.data(), position, subview.length());
2289}
2290
2291template <class CHAR_TYPE, class CHAR_TRAITS>
2296 const CHAR_TYPE *substring,
2297 size_type position,
2298 size_type numChars) const
2299{
2300 BSLS_ASSERT_SAFE(substring || (numChars == 0));
2301
2302 size_type remChars = length() - position;
2303 if (position > length() || numChars > remChars) {
2304 return npos; // RETURN
2305 }
2306 if (0 == numChars) {
2307 return position; // RETURN
2308 }
2309 const CHAR_TYPE *thisString = data() + position;
2310 const CHAR_TYPE *nextString = 0;
2311 for (remChars -= numChars - 1;
2312 0 !=
2313 (nextString = CHAR_TRAITS::find(thisString, remChars, *substring));
2314 remChars -= ++nextString - thisString, thisString = nextString) {
2315 if (0 == CHAR_TRAITS::compare(nextString, substring, numChars)) {
2316 return nextString - data(); // RETURN
2317 }
2318 }
2319
2320 return npos;
2321}
2322
2323template <class CHAR_TYPE, class CHAR_TRAITS>
2328 const CHAR_TYPE *characterString,
2329 size_type position) const
2330{
2331 BSLS_ASSERT_SAFE(characterString);
2332
2333 return find(characterString,
2334 position,
2335 CHAR_TRAITS::length(characterString));
2336}
2337
2338template <class CHAR_TYPE, class CHAR_TRAITS>
2343 CHAR_TYPE character,
2344 size_type position) const BSLS_KEYWORD_NOEXCEPT
2345{
2346 if (position >= length()) {
2347 return npos; // RETURN
2348 }
2349 const CHAR_TYPE *result = CHAR_TRAITS::find(data() + position,
2350 length() - position,
2351 character);
2352 return result ? result - data() : npos;
2353}
2354
2355template <class CHAR_TYPE, class CHAR_TRAITS>
2360 basic_string_view subview,
2361 size_type position) const BSLS_KEYWORD_NOEXCEPT
2362{
2363 return rfind(subview.data(), position, subview.length());
2364}
2365
2366template <class CHAR_TYPE, class CHAR_TRAITS>
2371 const CHAR_TYPE *characterString,
2372 size_type position,
2373 size_type numChars) const
2374{
2375 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2376
2377 if (0 == numChars) {
2378 return position > length() ? length() : position; // RETURN
2379 }
2380 if (numChars <= length()) {
2381 if (position > length() - numChars) {
2382 position = length() - numChars;
2383 }
2384 const CHAR_TYPE *thisString = data() + position;
2385 for (; position != npos; --thisString, --position) {
2386 if (0 == CHAR_TRAITS::compare(thisString,
2387 characterString,
2388 numChars)) {
2389 return position; // RETURN
2390 }
2391 }
2392 }
2393 return npos;
2394}
2395
2396template <class CHAR_TYPE, class CHAR_TRAITS>
2401 const CHAR_TYPE *characterString,
2402 size_type position) const
2403{
2404 BSLS_ASSERT_SAFE(characterString);
2405
2406 return rfind(characterString,
2407 position,
2408 CHAR_TRAITS::length(characterString));
2409}
2410
2411template <class CHAR_TYPE, class CHAR_TRAITS>
2416 CHAR_TYPE character,
2417 size_type position) const BSLS_KEYWORD_NOEXCEPT
2418{
2419 return rfind(&character, position, size_type(1));
2420}
2421
2422template <class CHAR_TYPE, class CHAR_TRAITS>
2427 basic_string_view subview,
2428 size_type position) const BSLS_KEYWORD_NOEXCEPT
2429{
2430 return find_first_of(subview.data(), position, subview.length());
2431}
2432
2433template <class CHAR_TYPE, class CHAR_TRAITS>
2438 const CHAR_TYPE *characterString,
2439 size_type position) const
2440{
2441 BSLS_ASSERT_SAFE(characterString);
2442
2443 return find_first_of(characterString,
2444 position,
2445 CHAR_TRAITS::length(characterString));
2446}
2447
2448template <class CHAR_TYPE, class CHAR_TRAITS>
2453 const CHAR_TYPE *characterString,
2454 size_type position,
2455 size_type numChars) const
2456{
2457 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2458
2459 if (0 < numChars && position < length()) {
2460 for (const CHAR_TYPE *current = data() + position;
2461 current != end();
2462 ++current)
2463 {
2464 if (CHAR_TRAITS::find(characterString, numChars, *current) != 0) {
2465 return current - data(); // RETURN
2466 }
2467 }
2468 }
2469 return npos;
2470}
2471
2472template <class CHAR_TYPE, class CHAR_TRAITS>
2477 CHAR_TYPE character,
2478 size_type position) const BSLS_KEYWORD_NOEXCEPT
2479{
2480 return find_first_of(&character, position, size_type(1));
2481}
2482
2483template <class CHAR_TYPE, class CHAR_TRAITS>
2488 basic_string_view subview,
2489 size_type position) const BSLS_KEYWORD_NOEXCEPT
2490{
2491 return find_last_of(subview.data(), position, subview.length());
2492}
2493
2494template <class CHAR_TYPE, class CHAR_TRAITS>
2499 const CHAR_TYPE *characterString,
2500 size_type position) const
2501{
2502 BSLS_ASSERT_SAFE(characterString);
2503
2504 return find_last_of(characterString,
2505 position,
2506 CHAR_TRAITS::length(characterString));
2507}
2508
2509template <class CHAR_TYPE, class CHAR_TRAITS>
2514 const CHAR_TYPE *characterString,
2515 size_type position,
2516 size_type numChars) const
2517{
2518 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2519
2520 if (0 < numChars && 0 < length()) {
2521 size_type remChars = position < length() ? position : length() - 1;
2522 for (const CHAR_TYPE *current = data() + remChars;
2523 current >= data();
2524 --current)
2525 {
2526 if (CHAR_TRAITS::find(characterString, numChars, *current)) {
2527 return current - data(); // RETURN
2528 }
2529 }
2530 }
2531 return npos;
2532}
2533
2534template <class CHAR_TYPE, class CHAR_TRAITS>
2539 CHAR_TYPE character,
2540 size_type position) const BSLS_KEYWORD_NOEXCEPT
2541{
2542 return find_last_of(&character, position, size_type(1));
2543}
2544
2545template <class CHAR_TYPE, class CHAR_TRAITS>
2550 basic_string_view subview,
2551 size_type position) const BSLS_KEYWORD_NOEXCEPT
2552{
2553 return find_first_not_of(subview.data(), position, subview.length());
2554}
2555
2556template <class CHAR_TYPE, class CHAR_TRAITS>
2561 const CHAR_TYPE *characterString,
2562 size_type position) const
2563{
2564 BSLS_ASSERT_SAFE(characterString);
2565
2566 return find_first_not_of(characterString,
2567 position,
2568 CHAR_TRAITS::length(characterString));
2569}
2570
2571template <class CHAR_TYPE, class CHAR_TRAITS>
2576 const CHAR_TYPE *characterString,
2577 size_type position,
2578 size_type numChars) const
2579{
2580 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2581
2582 if (position < length()) {
2583 for (const CHAR_TYPE *current = data() + position;
2584 current != end();
2585 ++current)
2586 {
2587 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2588 return current - data(); // RETURN
2589 }
2590 }
2591 }
2592 return npos;
2593}
2594
2595template <class CHAR_TYPE, class CHAR_TRAITS>
2600 CHAR_TYPE character,
2601 size_type position) const BSLS_KEYWORD_NOEXCEPT
2602{
2603 return find_first_not_of(&character, position, size_type(1));
2604}
2605
2606template <class CHAR_TYPE, class CHAR_TRAITS>
2611 basic_string_view subview,
2612 size_type position) const BSLS_KEYWORD_NOEXCEPT
2613{
2614 return find_last_not_of(subview.data(), position, subview.length());
2615}
2616
2617template <class CHAR_TYPE, class CHAR_TRAITS>
2622 const CHAR_TYPE *characterString,
2623 size_type position) const
2624{
2625 BSLS_ASSERT_SAFE(characterString);
2626
2627 return find_last_not_of(characterString,
2628 position,
2629 CHAR_TRAITS::length(characterString));
2630}
2631
2632template <class CHAR_TYPE, class CHAR_TRAITS>
2637 const CHAR_TYPE *characterString,
2638 size_type position,
2639 size_type numChars) const
2640{
2641 BSLS_ASSERT_SAFE(characterString || 0 == numChars);
2642
2643 if (0 < length()) {
2644 size_type remChars = position < length() ? position : length() - 1;
2645 for (const CHAR_TYPE *current = data() + remChars;
2646 current >= data();
2647 --current)
2648 {
2649 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2650 return current - data(); // RETURN
2651 }
2652 }
2653 }
2654 return npos;
2655}
2656
2657template <class CHAR_TYPE, class CHAR_TRAITS>
2662 CHAR_TYPE character,
2663 size_type position) const BSLS_KEYWORD_NOEXCEPT
2664{
2665 return find_last_not_of(&character, position, size_type(1));
2666}
2667
2668#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
2669template <class CHAR_TYPE, class CHAR_TRAITS>
2670constexpr
2672operator std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>() const
2673{
2674 return {d_start_p, d_length};
2675}
2676#endif // BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
2677
2678// PUBLIC ACCESSORS
2679template <class CHAR_TYPE, class CHAR_TRAITS>
2682operator()(const basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input) const
2683{
2684 using ::BloombergLP::bslh::hashAppend;
2685 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2686 hashAlg(input.data(), sizeof(CHAR_TYPE) * input.size());
2687 hashAppend(hashAlg, input.size());
2688 return static_cast<std::size_t>(hashAlg.computeHash());
2689}
2690
2691template <class CHAR_TYPE, class CHAR_TRAITS>
2694operator()(const CHAR_TYPE *input) const
2695{
2696 BSLS_ASSERT_SAFE(input);
2697 using ::BloombergLP::bslh::hashAppend;
2698 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2699
2700 std::size_t length = CHAR_TRAITS::length(input);
2701
2702 hashAlg(input, sizeof(CHAR_TYPE) * length);
2703 hashAppend(hashAlg, length);
2704 return static_cast<std::size_t>(hashAlg.computeHash());
2705}
2706
2707#if defined(BSLS_PLATFORM_CMP_SUN) // {DRQS 132030795}
2708
2709inline
2710std::size_t hash<string_view>::operator()(const string_view& input) const
2711{
2712 using ::BloombergLP::bslh::hashAppend;
2713 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2714 hashAlg(input.data(), input.size());
2715 hashAppend(hashAlg, input.size());
2716 return static_cast<std::size_t>(hashAlg.computeHash());
2717}
2718
2719inline
2720std::size_t hash<string_view>::operator()(const char *input) const
2721{
2722 BSLS_ASSERT_SAFE(input);
2723 using ::BloombergLP::bslh::hashAppend;
2724 std::size_t length = char_traits<char>::length(input);
2725 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2726 hashAlg(input, length);
2727 hashAppend(hashAlg, length);
2728 return static_cast<std::size_t>(hashAlg.computeHash());
2729}
2730
2731inline
2732std::size_t hash<wstring_view>::operator()(const wstring_view& input) const
2733{
2734 using ::BloombergLP::bslh::hashAppend;
2735 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2736 hashAlg(input.data(), sizeof(wchar_t) * input.size());
2737 hashAppend(hashAlg, input.size());
2738 return static_cast<std::size_t>(hashAlg.computeHash());
2739}
2740
2741inline
2742std::size_t hash<wstring_view>::operator()(const wchar_t *input) const
2743{
2744 BSLS_ASSERT_SAFE(input);
2745 using ::BloombergLP::bslh::hashAppend;
2746 std::size_t length = char_traits<wchar_t>::length(input);
2747 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2748 hashAlg(input, sizeof(wchar_t) * length);
2749 hashAppend(hashAlg, length);
2750 return static_cast<std::size_t>(hashAlg.computeHash());
2751}
2752
2753#endif
2754
2755} // close namespace bsl
2756
2757
2758namespace bslstl_stringview_relops {
2759
2760 // ----------------------
2761 // StringView_CompareUtil
2762 // ----------------------
2763
2764template <class CHAR_TYPE, class CHAR_TRAITS>
2765inline
2769{
2770 return lhs.size() == rhs.size()
2771 && 0 == CHAR_TRAITS::compare(lhs.data(), rhs.data(), lhs.size());
2772}
2773
2774template <class CHAR_TYPE, class CHAR_TRAITS>
2775inline
2779{
2780 const std::size_t minLen = lhs.length() < rhs.length()
2781 ? lhs.length() : rhs.length();
2782
2783 int ret = CHAR_TRAITS::compare(lhs.data(), rhs.data(), minLen);
2784 if (0 == ret) {
2785 return lhs.length() < rhs.length(); // RETURN
2786 }
2787 return (ret < 0);
2788}
2789
2790} // close namespace bslstl_stringview_relops
2791
2792
2793// FREE FUNCTIONS
2794template <class CHAR_TYPE, class CHAR_TRAITS>
2795inline
2796void bsl::swap(
2797 basic_string_view<CHAR_TYPE, CHAR_TRAITS>& a,
2798 basic_string_view<CHAR_TYPE, CHAR_TRAITS>& b) BSLS_KEYWORD_NOEXCEPT
2799{
2800 a.swap(b);
2801}
2802
2803// FREE OPERATORS
2804template <class CHAR_TYPE, class CHAR_TRAITS>
2805inline
2807bool BloombergLP::bslstl_stringview_relops::
2811{
2812 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2813}
2814
2815template <class CHAR_TYPE, class CHAR_TRAITS>
2816inline
2818bool BloombergLP::bslstl_stringview_relops::
2819operator==(typename BloombergLP::bslstl::StringView_Identity<
2823{
2824 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2825}
2826
2827template <class CHAR_TYPE, class CHAR_TRAITS>
2828inline
2830bool BloombergLP::bslstl_stringview_relops::
2832 typename BloombergLP::bslstl::StringView_Identity<
2835{
2836 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2837}
2838
2839template <class CHAR_TYPE, class CHAR_TRAITS>
2840inline
2842bool BloombergLP::bslstl_stringview_relops::
2846{
2847 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2848}
2849
2850template <class CHAR_TYPE, class CHAR_TRAITS>
2851inline
2853bool BloombergLP::bslstl_stringview_relops::
2854operator!=(typename BloombergLP::bslstl::StringView_Identity<
2858{
2859 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2860}
2861
2862template <class CHAR_TYPE, class CHAR_TRAITS>
2863inline
2865bool BloombergLP::bslstl_stringview_relops::
2867 typename BloombergLP::bslstl::StringView_Identity<
2870{
2871 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2872}
2873
2874template <class CHAR_TYPE, class CHAR_TRAITS>
2875inline
2877bool BloombergLP::bslstl_stringview_relops::
2881{
2882 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2883}
2884
2885template <class CHAR_TYPE, class CHAR_TRAITS>
2886inline
2888bool BloombergLP::bslstl_stringview_relops::
2889operator<(typename BloombergLP::bslstl::StringView_Identity<
2893{
2894 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2895}
2896
2897template <class CHAR_TYPE, class CHAR_TRAITS>
2898inline
2900bool BloombergLP::bslstl_stringview_relops::
2902 typename BloombergLP::bslstl::StringView_Identity<
2905{
2906 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2907}
2908
2909template <class CHAR_TYPE, class CHAR_TRAITS>
2910inline
2912bool BloombergLP::bslstl_stringview_relops::
2916{
2917 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2918}
2919
2920template <class CHAR_TYPE, class CHAR_TRAITS>
2921inline
2923bool BloombergLP::bslstl_stringview_relops::
2924operator>(typename BloombergLP::bslstl::StringView_Identity<
2928{
2929 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2930}
2931
2932template <class CHAR_TYPE, class CHAR_TRAITS>
2933inline
2935bool BloombergLP::bslstl_stringview_relops::
2937 typename BloombergLP::bslstl::StringView_Identity<
2940{
2941 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2942}
2943
2944template <class CHAR_TYPE, class CHAR_TRAITS>
2945inline
2947bool BloombergLP::bslstl_stringview_relops::
2951{
2952 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2953}
2954
2955template <class CHAR_TYPE, class CHAR_TRAITS>
2956inline
2958bool BloombergLP::bslstl_stringview_relops::
2959operator<=(typename BloombergLP::bslstl::StringView_Identity<
2963{
2964 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2965}
2966
2967template <class CHAR_TYPE, class CHAR_TRAITS>
2968inline
2970bool BloombergLP::bslstl_stringview_relops::
2972 typename BloombergLP::bslstl::StringView_Identity<
2975{
2976 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2977}
2978
2979template <class CHAR_TYPE, class CHAR_TRAITS>
2980inline
2982bool BloombergLP::bslstl_stringview_relops::
2986{
2987 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2988}
2989
2990template <class CHAR_TYPE, class CHAR_TRAITS>
2991inline
2993bool BloombergLP::bslstl_stringview_relops::
2994operator>=(typename BloombergLP::bslstl::StringView_Identity<
2998{
2999 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
3000}
3001
3002template <class CHAR_TYPE, class CHAR_TRAITS>
3003inline
3005bool BloombergLP::bslstl_stringview_relops::
3007 typename BloombergLP::bslstl::StringView_Identity<
3010{
3011 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
3012}
3013
3014namespace bsl {
3015
3016using BloombergLP::bslstl_stringview_relops::operator==;
3017using BloombergLP::bslstl_stringview_relops::operator!=;
3018using BloombergLP::bslstl_stringview_relops::operator<;
3019using BloombergLP::bslstl_stringview_relops::operator>;
3020using BloombergLP::bslstl_stringview_relops::operator<=;
3021using BloombergLP::bslstl_stringview_relops::operator>=;
3022
3023} // close namespace bsl
3024
3025template <class CHAR_TYPE, class CHAR_TRAITS>
3026std::basic_ostream<CHAR_TYPE>&
3027bsl::operator<<(std::basic_ostream<CHAR_TYPE>& stream,
3028 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView)
3029{
3030 typedef CHAR_TYPE char_type;
3031 typedef typename std::basic_ostream<char_type>::ios_base ios_base;
3032 typedef typename basic_string_view<CHAR_TYPE, CHAR_TRAITS>::size_type
3033 size_type;
3034
3035 size_type width = static_cast<size_type>(stream.width());
3036 size_type len = stringView.length();
3037
3038 if (len < width) {
3039 bool leftAdjusted =
3040 (stream.flags() & ios_base::adjustfield) == ios_base::left;
3041
3042 char_type fillChar = stream.fill();
3043
3044 if (leftAdjusted) {
3045 if (stringView.data()) {
3046 stream.write(stringView.data(), stringView.length());
3047 }
3048 }
3049
3050 for (size_type n = 0; n != width - len; ++n) {
3051 stream.put(fillChar);
3052 }
3053
3054 if (!leftAdjusted) {
3055 if (stringView.data()) {
3056 stream.write(stringView.data(), stringView.length());
3057 }
3058 }
3059 }
3060 else {
3061 if (stringView.data()) {
3062 stream.write(stringView.data(), stringView.length());
3063 }
3064 }
3065
3066 stream.width(0);
3067
3068 return stream;
3069}
3070
3071// HASH SPECIALIZATIONS
3072template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
3073inline
3074void bsl::hashAppend(HASHALG& hashAlg,
3075 const basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
3076{
3077 using ::BloombergLP::bslh::hashAppend;
3078 hashAlg(input.data(), sizeof(CHAR_TYPE)*input.size());
3079 hashAppend(hashAlg, input.size());
3080}
3081
3082#endif // BSLSTL_STRING_VIEW_IS_ALIASED
3083
3084#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
3085
3086
3087template <class HASHALG, class CHAR_TYPE, class CHAR_TRAITS>
3089void bslh::hashAppend(
3090 HASHALG& hashAlg,
3091 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
3092{
3093 hashAlg(input.data(), sizeof(CHAR_TYPE)*input.size());
3094 hashAppend(hashAlg, input.size());
3095}
3096
3097
3098#endif // BSLSTL_STRING_VIEW_IS_ALIASED
3099
3100#endif
3101
3102// ----------------------------------------------------------------------------
3103// Copyright 2019 Bloomberg Finance L.P.
3104//
3105// Licensed under the Apache License, Version 2.0 (the "License");
3106// you may not use this file except in compliance with the License.
3107// You may obtain a copy of the License at
3108//
3109// http://www.apache.org/licenses/LICENSE-2.0
3110//
3111// Unless required by applicable law or agreed to in writing, software
3112// distributed under the License is distributed on an "AS IS" BASIS,
3113// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3114// See the License for the specific language governing permissions and
3115// limitations under the License.
3116// ----------------------------- END-OF-FILE ----------------------------------
3117
3118/** @} */
3119/** @} */
3120/** @} */
Definition bslstl_stringview.h:471
std::ptrdiff_t difference_type
Definition bslstl_stringview.h:488
std::size_t size_type
Definition bslstl_stringview.h:487
BSLS_KEYWORD_CONSTEXPR const_iterator end() const BSLS_KEYWORD_NOEXCEPT
Return the past-the-end iterator for this view.
Definition bslstl_stringview.h:1848
BSLS_KEYWORD_CONSTEXPR size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1922
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2284
BSLMF_NESTED_TRAIT_DECLARATION(basic_string_view, bsl::is_trivially_copyable)
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_first_of(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2426
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator rend() const BSLS_KEYWORD_NOEXCEPT
Return the past-the-end reverse iterator for this view.
Definition bslstl_stringview.h:1886
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_suffix(size_type numChars)
Definition bslstl_stringview.h:1810
const value_type & const_reference
Definition bslstl_stringview.h:480
const_iterator iterator
Definition bslstl_stringview.h:482
basic_string_view & operator=(const basic_string_view &rhs)=default
const value_type * const_pointer
Definition bslstl_stringview.h:478
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_last_not_of(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2610
CHAR_TRAITS traits_type
Definition bslstl_stringview.h:475
BSLS_KEYWORD_CONSTEXPR size_type length() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1913
CHAR_TYPE value_type
Definition bslstl_stringview.h:476
size_type copy(CHAR_TYPE *characterString, size_type numChars, size_type position=0) const
Definition bslstl_stringview.h:1995
BSLS_KEYWORD_CONSTEXPR const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1839
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view(const CHAR_TYPE *characterString, size_type numChars)
Definition bslstl_stringview.h:1705
BSLS_KEYWORD_CONSTEXPR const_pointer data() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1988
BSLS_KEYWORD_CONSTEXPR_CPP17 bool starts_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2215
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view(CONTIG_ITER first, SENTINEL last, typename bsl::enable_if< bsl::is_convertible< decltype(&(*std::declval< CONTIG_ITER >())), const CHAR_TYPE * >::value &&!bsl::is_convertible< SENTINEL, std::size_t >::value >::type *=0)
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_last_of(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2487
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view substr(size_type position=0, size_type numChars=npos) const
Definition bslstl_stringview.h:2027
value_type * pointer
Definition bslstl_stringview.h:477
BSLS_KEYWORD_CONSTEXPR const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1858
basic_string_view(const std::basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &str)
Create a view of the specified string.
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference back() const
Definition bslstl_stringview.h:1977
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_stringview.h:485
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator rbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1867
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_stringview.h:484
BSLS_KEYWORD_CONSTEXPR size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1904
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find_first_not_of(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2549
BSLS_KEYWORD_CONSTEXPR_CPP17 bool ends_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2255
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type rfind(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2359
value_type & reference
Definition bslstl_stringview.h:479
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference front() const
Definition bslstl_stringview.h:1966
BSLS_KEYWORD_CONSTEXPR_CPP17 int compare(basic_string_view other) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2046
void swap(basic_string_view &other) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1818
BSLS_KEYWORD_CONSTEXPR basic_string_view() BSLS_KEYWORD_NOEXCEPT
Create an empty view.
Definition bslstl_stringview.h:1684
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference at(size_type position) const
Definition bslstl_stringview.h:1952
static const size_type npos
Definition bslstl_stringview.h:495
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference operator[](size_type position) const
Definition bslstl_stringview.h:1941
const value_type * const_iterator
Definition bslstl_stringview.h:481
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1895
~basic_string_view()=default
Destroy this object.
BSLS_KEYWORD_CONSTEXPR const_iterator begin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1830
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1876
BSLS_KEYWORD_CONSTEXPR_CPP17 bool contains(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2187
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view & operator=(const std::basic_string< CHAR_TYPE, CHAR_TRAITS, ALLOCATOR > &rhs) BSLS_KEYWORD_NOEXCEPT
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_prefix(size_type numChars)
Definition bslstl_stringview.h:1800
BSLS_KEYWORD_CONSTEXPR bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this view has length 0, and false otherwise.
Definition bslstl_stringview.h:1931
Definition bslstl_string.h:1252
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:631
#define BSLS_KEYWORD_CONSTEXPR_CPP17
Definition bsls_keyword.h:639
#define BSLS_KEYWORD_EXPLICIT
Definition bsls_keyword.h:683
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
#define BSLS_PLATFORM_AGGRESSIVE_INLINE
Definition bsls_platform.h:737
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator<(const MetricId &lhs, const MetricId &rhs)
bool operator>=(const Guid &lhs, const Guid &rhs)
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
bool operator<=(const Guid &lhs, const Guid &rhs)
bool operator>(const Guid &lhs, const Guid &rhs)
Definition bdlat_valuetypefunctions.h:939
BloombergLP::bsls::Nullptr_Impl::Type nullptr_t
Definition bsls_nullptr.h:283
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const array< TYPE, SIZE > &input)
Pass the specified input to the specified hashAlgorithm
Definition bslstl_array.h:959
basic_string_view< char > string_view
Definition bslstl_stringview.h:1253
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
std::basic_ostream< CHAR_TYPE, TRAITS > & operator<<(std::basic_ostream< CHAR_TYPE, TRAITS > &os, const bitset< N > &x)
Definition bslstl_bitset.h:1417
ALLOCATOR & lhs
Definition bslstl_string.h:3917
CHAR_TRAITS
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
basic_string_view< wchar_t > wstring_view
Definition bslstl_stringview.h:1254
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1325
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1377
Definition bslh_defaulthashalgorithm.h:339
bsl::enable_if<(bsl::is_integral< TYPE >::value||bsl::is_pointer< TYPE >::value||bsl::is_enum< TYPE >::value)&&!bsl::is_same< TYPE, bool >::value >::type hashAppend(HASH_ALGORITHM &hashAlg, TYPE input)
Definition bslh_hash.h:643
Definition bslstl_stringview.h:1276
Definition bslstl_algorithm.h:84
Definition bdldfp_decimal.h:5549
Definition bslmf_enableif.h:530
Definition bslstl_hash.h:495
std::size_t operator()(const TYPE &value) const
Definition bslstl_hash.h:1067
Definition bslmf_isconvertible.h:875
Definition bslmf_istriviallycopyable.h:324
Definition bslstl_stringview.h:389
TYPE type
Definition bslstl_stringview.h:432
Definition bslstl_stringview.h:1292
bsl::basic_string_view< CHAR_TYPE, CHAR_TRAITS > StringView
Definition bslstl_stringview.h:1295
static BSLS_KEYWORD_CONSTEXPR_CPP17 bool equals(StringView lhs, StringView rhs) BSLS_KEYWORD_NOEXCEPT
Return true if lhs == rhs and false otherwise.
Definition bslstl_stringview.h:2767
static BSLS_KEYWORD_CONSTEXPR_CPP17 bool lessThan(StringView lhs, StringView rhs) BSLS_KEYWORD_NOEXCEPT
Return true if lhs < rhs and false otherwise.
Definition bslstl_stringview.h:2777