8#ifndef INCLUDED_BSLSTL_STRINGVIEW
9#define INCLUDED_BSLSTL_STRINGVIEW
238#include <bslscm_version.h>
267#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
271#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) \
272&& !defined(BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY)
273#define BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
279#ifndef BDE_DISABLE_CPP17_ABI
280# ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_BASELINE_LIBRARY
282# include <string_view>
286using std::basic_string_view;
287using std::string_view;
288using std::wstring_view;
290# if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
291using std::u8string_view;
294using std::u16string_view;
295using std::u32string_view;
299using std::operator==;
300using std::operator!=;
302using std::operator<=;
304using std::operator>=;
307# define BSLSTL_STRING_VIEW_IS_ALIASED
311#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
313#if defined(BSLS_PLATFORM_OS_WINDOWS) || \
314 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130) || \
315 (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION == 0x5150)
318# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 1
320# define BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER 0
332#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
345 template <
class ARG_TYPE>
346 type(
const ARG_TYPE& argument,
355 type& operator=(
const type&) =
default;
360 TYPE& operator=(
const TYPE& rhs);
370 operator const TYPE&()
const;
390template <
class CHAR_TYPE,
class CONTG_ITER>
393 typename bsl::add_pointer<
394 typename bsl::add_const<CHAR_TYPE>::type
405template <
class SENTINEL>
408 ! bsl::is_convertible<SENTINEL, std::size_t>::value>
415using std::char_traits;
440template <
class CHAR_TYPE,
class CHAR_TRAITS =
char_traits<CHAR_TYPE> >
469 const CHAR_TYPE *d_start_p;
484 int privateCompareRaw(
size_type lhsPosition,
486 const CHAR_TYPE *other,
527 template <class CONTG_ITER, class SENTINEL>
539 template <class ALLOCATOR>
544#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
548 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view);
564 template <
class ALLOCATOR>
567 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
679 size_type copy(CHAR_TYPE *characterString,
743 int compare(const CHAR_TYPE *other) const;
757 const CHAR_TYPE *other) const;
772 const CHAR_TYPE *other,
788 bool starts_with(const CHAR_TYPE* characterString) const;
803 bool ends_with(const CHAR_TYPE* characterString) const;
820 size_type find(const CHAR_TYPE *characterString,
830 size_type find(const CHAR_TYPE *characterString,
897 size_type find_first_of(const CHAR_TYPE *characterString,
906 size_type find_first_of(const CHAR_TYPE *characterString,
1031 CHAR_TYPE character,
1041 template <class ALLOCATOR>
1047 return std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>(d_start_p,
1056#if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
1060#if defined(BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES)
1069template <
class CHAR_TYPE,
class CHAR_TRAITS>
1089template <
class CHAR_TYPE,
class CHAR_TRAITS>
1114template <
class CHAR_TYPE,
class CHAR_TRAITS>
1119template <
class CHAR_TYPE,
class CHAR_TRAITS>
1122 typename BloombergLP::bslstl::StringView_Identity<
1126template <
class CHAR_TYPE,
class CHAR_TRAITS>
1130 typename BloombergLP::bslstl::StringView_Identity<
1138template <
class CHAR_TYPE,
class CHAR_TRAITS>
1143template <
class CHAR_TYPE,
class CHAR_TRAITS>
1146 typename BloombergLP::bslstl::StringView_Identity<
1150template <
class CHAR_TYPE,
class CHAR_TRAITS>
1154 typename BloombergLP::bslstl::StringView_Identity<
1161template <
class CHAR_TYPE,
class CHAR_TRAITS>
1166template <
class CHAR_TYPE,
class CHAR_TRAITS>
1169 typename BloombergLP::bslstl::StringView_Identity<
1173template <
class CHAR_TYPE,
class CHAR_TRAITS>
1177 typename BloombergLP::bslstl::StringView_Identity<
1184template <
class CHAR_TYPE,
class CHAR_TRAITS>
1189template <
class CHAR_TYPE,
class CHAR_TRAITS>
1192 typename BloombergLP::bslstl::StringView_Identity<
1196template <
class CHAR_TYPE,
class CHAR_TRAITS>
1200 typename BloombergLP::bslstl::StringView_Identity<
1207template <
class CHAR_TYPE,
class CHAR_TRAITS>
1212template <
class CHAR_TYPE,
class CHAR_TRAITS>
1215 typename BloombergLP::bslstl::StringView_Identity<
1219template <
class CHAR_TYPE,
class CHAR_TRAITS>
1223 typename BloombergLP::bslstl::StringView_Identity<
1230template <
class CHAR_TYPE,
class CHAR_TRAITS>
1235template <
class CHAR_TYPE,
class CHAR_TRAITS>
1238 typename BloombergLP::bslstl::StringView_Identity<
1242template <
class CHAR_TYPE,
class CHAR_TRAITS>
1246 typename BloombergLP::bslstl::StringView_Identity<
1258template <
class CHAR_TYPE,
class CHAR_TRAITS>
1259std::basic_ostream<CHAR_TYPE>&
1260operator<<(std::basic_ostream<CHAR_TYPE>& stream,
1261 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView);
1267template <
class HASHALG,
class CHAR_TYPE,
class CHAR_TRAITS>
1273template <
class CHAR_TYPE,
class CHAR_TRAITS>
1275 : ::BloombergLP::bslh::Hash<>
1286 std::size_t
operator()(
const CHAR_TYPE *input)
const;
1289#if defined(BSLS_PLATFORM_CMP_SUN)
1306 std::size_t
operator()(
const char *input)
const;
1320 std::size_t
operator()(
const wchar_t *input)
const;
1329#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) && \
1330 defined (BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE)
1332inline namespace literals {
1333inline namespace string_view_literals {
1354 string_view operator ""_sv(
const char *characterString,
1355 std::size_t length);
1356wstring_view operator ""_sv(
const wchar_t *characterString,
1357 std::size_t length);
1365#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
1378template <
class HASHALG,
class CHAR_TYPE,
class CHAR_TRAITS>
1381 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input);
1391#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
1393#if BSLSTL_STRINGVIEW_IDENTITY_USE_WRAPPER
1398template <
class TYPE>
1399template <
class ARG_TYPE>
1401StringView_Identity<TYPE>::type::type(
1402 const ARG_TYPE& argument,
1409template <
class TYPE>
1411TYPE& StringView_Identity<TYPE>::type::operator=(
const TYPE& rhs)
1418template <
class TYPE>
1420StringView_Identity<TYPE>::type::operator TYPE&()
1426template <
class TYPE>
1428StringView_Identity<TYPE>::type::operator
const TYPE&()
const
1445template <
class CHAR_TYPE,
class CHAR_TRAITS>
1450template <
class CHAR_TYPE,
class CHAR_TRAITS>
1452int basic_string_view<CHAR_TYPE,CHAR_TRAITS>::privateCompareRaw(
1453 size_type lhsPosition,
1454 size_type lhsNumChars,
1455 const CHAR_TYPE *other,
1456 size_type otherNumChars)
const
1460 size_type numChars = lhsNumChars < otherNumChars ? lhsNumChars
1462 int cmpResult = CHAR_TRAITS::compare(
data() + lhsPosition,
1468 if (lhsNumChars < otherNumChars) {
1471 if (lhsNumChars > otherNumChars) {
1478template <
class CHAR_TYPE,
class CHAR_TRAITS>
1487template <
class CHAR_TYPE,
class CHAR_TRAITS>
1491 const CHAR_TYPE *characterString)
1492: d_start_p(characterString)
1493, d_length(characterString ? CHAR_TRAITS::length(characterString) : 0)
1499template <
class CHAR_TYPE,
class CHAR_TRAITS>
1503 const CHAR_TYPE *characterString,
1505: d_start_p(characterString)
1512template <
class CHAR_TYPE,
class CHAR_TRAITS>
1513template <
class CONTG_ITER,
class SENTINEL>
1526, d_length(last - first)
1532template <
class CHAR_TYPE,
class CHAR_TRAITS>
1533template <
class ALLOCATOR>
1536 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& str)
1537: d_start_p(str.
data())
1538, d_length(str.
size())
1542#ifdef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
1543template <
class CHAR_TYPE,
class CHAR_TRAITS>
1547 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& view)
1548: d_start_p(view.
data())
1549, d_length (view.
size())
1555template <
class CHAR_TYPE,
class CHAR_TRAITS>
1556template <
class ALLOCATOR>
1559basic_string_view<CHAR_TYPE, CHAR_TRAITS>&
1561 const std::basic_string<CHAR_TYPE, CHAR_TRAITS, ALLOCATOR>& rhs)
1564 d_start_p = rhs.
data();
1565 d_length = rhs.size();
1569template <
class CHAR_TYPE,
class CHAR_TRAITS>
1575 d_start_p += numChars;
1576 d_length -= numChars;
1579template <
class CHAR_TYPE,
class CHAR_TRAITS>
1585 d_length -= numChars;
1588template <
class CHAR_TYPE,
class CHAR_TRAITS>
1593 BloombergLP::bslalg::ScalarPrimitives::swap(d_length, other.d_length);
1594 BloombergLP::bslalg::ScalarPrimitives::swap(d_start_p, other.d_start_p);
1598template <
class CHAR_TYPE,
class CHAR_TRAITS>
1607template <
class CHAR_TYPE,
class CHAR_TRAITS>
1616template <
class CHAR_TYPE,
class CHAR_TRAITS>
1623 return begin() + d_length;
1626template <
class CHAR_TYPE,
class CHAR_TRAITS>
1635template <
class CHAR_TYPE,
class CHAR_TRAITS>
1644template <
class CHAR_TYPE,
class CHAR_TRAITS>
1654template <
class CHAR_TYPE,
class CHAR_TRAITS>
1663template <
class CHAR_TYPE,
class CHAR_TRAITS>
1672template <
class CHAR_TYPE,
class CHAR_TRAITS>
1681template <
class CHAR_TYPE,
class CHAR_TRAITS>
1690template <
class CHAR_TYPE,
class CHAR_TRAITS>
1697 return (npos - 1) /
sizeof(CHAR_TYPE);
1700template <
class CHAR_TYPE,
class CHAR_TRAITS>
1706 return (0 == d_length);
1709template <
class CHAR_TYPE,
class CHAR_TRAITS>
1717 return *(
begin() + position);
1720template <
class CHAR_TYPE,
class CHAR_TRAITS>
1728 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1729 "string_view::at(n): invalid position");
1731 return *(
begin() + position);
1734template <
class CHAR_TYPE,
class CHAR_TRAITS>
1745template <
class CHAR_TYPE,
class CHAR_TRAITS>
1753 return *(
end() - 1);
1756template <
class CHAR_TYPE,
class CHAR_TRAITS>
1765template <
class CHAR_TYPE,
class CHAR_TRAITS>
1774 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1775 "string_view::copy(str,pos,n): invalid position");
1780 if (numChars > length() - position) {
1781 numChars = length() - position;
1786 characterString, d_start_p + position) ||
1787 std::greater_equal<const CHAR_TYPE *>()(
1788 characterString, d_start_p + position + numChars));
1790 CHAR_TRAITS::move(characterString, d_start_p + position, numChars);
1795template <
class CHAR_TYPE,
class CHAR_TRAITS>
1804 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1805 "string_view::substr(pos,n): invalid position");
1808 const size_type maxLen = length() - position;
1812 numChars < maxLen ? numChars : maxLen);
1815template <
class CHAR_TYPE,
class CHAR_TRAITS>
1827template <
class CHAR_TYPE,
class CHAR_TRAITS>
1837 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1838 "const string_view<...>::compare(pos,n, other): invalid position");
1841 if (numChars > length() - position) {
1842 numChars = length() - position;
1844 return privateCompareRaw(position, numChars, other.
data(), other.
length());
1847template <
class CHAR_TYPE,
class CHAR_TRAITS>
1859 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1860 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
1861 ": invalid lhs position");
1864 if (lhsNumChars > length() - lhsPosition) {
1865 lhsNumChars = length() - lhsPosition;
1869 other.
length() < otherPosition)) {
1871 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1872 "const string_view<...>::compare(pos,n,other,other_pos,other_n)"
1873 ": invalid rhs position");
1876 if (otherNumChars > other.
length() - otherPosition) {
1877 otherNumChars = other.
length() - otherPosition;
1879 return privateCompareRaw(lhsPosition,
1881 other.
data() + otherPosition,
1885template <
class CHAR_TYPE,
class CHAR_TRAITS>
1889 const CHAR_TYPE *other)
const
1893 size_type otherLength = CHAR_TRAITS::length(other);
1901template <
class CHAR_TYPE,
class CHAR_TRAITS>
1907 const CHAR_TYPE *other)
const
1913 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1914 "const string_view<...>::compare(pos,n,other): invalid position");
1917 size_type otherLength = CHAR_TRAITS::length(other);
1919 if (lhsNumChars > length() - lhsPosition) {
1920 lhsNumChars = length() - lhsPosition;
1923 return compare(lhsPosition,
1929template <
class CHAR_TYPE,
class CHAR_TRAITS>
1935 const CHAR_TYPE *other,
1942 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
1943 "const string_view<...>::compare(pos,n,other,other_pos)"
1944 ": invalid position");
1947 if (lhsNumChars > length() - lhsPosition) {
1948 lhsNumChars = length() - lhsPosition;
1950 return privateCompareRaw(lhsPosition,
1956template <
class CHAR_TYPE,
class CHAR_TRAITS>
1962 return (
size() >= subview.size() &&
1963 0 == compare(0, subview.size(), subview));
1966template <
class CHAR_TYPE,
class CHAR_TRAITS>
1972 return (!
empty() && CHAR_TRAITS::eq(front(), character));
1975template <
class CHAR_TYPE,
class CHAR_TRAITS>
1979 const CHAR_TYPE* characterString)
const
1982 for (
size_type i = 0; i < d_length; ++i) {
1983 if (characterString[i] == 0) {
1987 if (d_start_p[i] != characterString[i]) {
1993 return characterString[d_length] == 0;
1996template <
class CHAR_TYPE,
class CHAR_TRAITS>
2002 return (
size() >= subview.size() &&
2003 0 == compare(
size() - subview.size(), npos, subview));
2006template <
class CHAR_TYPE,
class CHAR_TRAITS>
2012 return (!
empty() && CHAR_TRAITS::eq(back(), character));
2015template <
class CHAR_TYPE,
class CHAR_TRAITS>
2019 const CHAR_TYPE* characterString)
const
2024template <
class CHAR_TYPE,
class CHAR_TRAITS>
2032 return find(subview.data(), position, subview.length());
2035template <
class CHAR_TYPE,
class CHAR_TRAITS>
2040 const CHAR_TYPE *substring,
2046 size_type remChars = length() - position;
2047 if (position > length() || numChars > remChars) {
2050 if (0 == numChars) {
2053 const CHAR_TYPE *thisString =
data() + position;
2054 const CHAR_TYPE *nextString = 0;
2055 for (remChars -= numChars - 1;
2057 (nextString = CHAR_TRAITS::find(thisString, remChars, *substring));
2058 remChars -= ++nextString - thisString, thisString = nextString) {
2059 if (0 == CHAR_TRAITS::compare(nextString, substring, numChars)) {
2060 return nextString -
data();
2067template <
class CHAR_TYPE,
class CHAR_TRAITS>
2072 const CHAR_TYPE *characterString,
2077 return find(characterString,
2079 CHAR_TRAITS::length(characterString));
2082template <
class CHAR_TYPE,
class CHAR_TRAITS>
2087 CHAR_TYPE character,
2090 if (position >= length()) {
2093 const CHAR_TYPE *result = CHAR_TRAITS::find(
data() + position,
2094 length() - position,
2096 return result ? result -
data() : npos;
2099template <
class CHAR_TYPE,
class CHAR_TRAITS>
2107 return rfind(subview.data(), position, subview.length());
2110template <
class CHAR_TYPE,
class CHAR_TRAITS>
2115 const CHAR_TYPE *characterString,
2121 if (0 == numChars) {
2122 return position > length() ? length() : position;
2124 if (numChars <= length()) {
2125 if (position > length() - numChars) {
2126 position = length() - numChars;
2128 const CHAR_TYPE *thisString =
data() + position;
2129 for (; position != npos; --thisString, --position) {
2130 if (0 == CHAR_TRAITS::compare(thisString,
2140template <
class CHAR_TYPE,
class CHAR_TRAITS>
2145 const CHAR_TYPE *characterString,
2150 return rfind(characterString,
2152 CHAR_TRAITS::length(characterString));
2155template <
class CHAR_TYPE,
class CHAR_TRAITS>
2160 CHAR_TYPE character,
2163 return rfind(&character, position,
size_type(1));
2166template <
class CHAR_TYPE,
class CHAR_TRAITS>
2174 return find_first_of(subview.data(), position, subview.length());
2177template <
class CHAR_TYPE,
class CHAR_TRAITS>
2182 const CHAR_TYPE *characterString,
2187 return find_first_of(characterString,
2189 CHAR_TRAITS::length(characterString));
2192template <
class CHAR_TYPE,
class CHAR_TRAITS>
2197 const CHAR_TYPE *characterString,
2203 if (0 < numChars && position < length()) {
2204 for (
const CHAR_TYPE *current =
data() + position;
2208 if (CHAR_TRAITS::find(characterString, numChars, *current) != 0) {
2209 return current -
data();
2216template <
class CHAR_TYPE,
class CHAR_TRAITS>
2221 CHAR_TYPE character,
2224 return find_first_of(&character, position,
size_type(1));
2227template <
class CHAR_TYPE,
class CHAR_TRAITS>
2235 return find_last_of(subview.data(), position, subview.length());
2238template <
class CHAR_TYPE,
class CHAR_TRAITS>
2243 const CHAR_TYPE *characterString,
2248 return find_last_of(characterString,
2250 CHAR_TRAITS::length(characterString));
2253template <
class CHAR_TYPE,
class CHAR_TRAITS>
2258 const CHAR_TYPE *characterString,
2264 if (0 < numChars && 0 < length()) {
2265 size_type remChars = position < length() ? position : length() - 1;
2266 for (
const CHAR_TYPE *current =
data() + remChars;
2270 if (CHAR_TRAITS::find(characterString, numChars, *current)) {
2271 return current -
data();
2278template <
class CHAR_TYPE,
class CHAR_TRAITS>
2283 CHAR_TYPE character,
2286 return find_last_of(&character, position,
size_type(1));
2289template <
class CHAR_TYPE,
class CHAR_TRAITS>
2297 return find_first_not_of(subview.data(), position, subview.length());
2300template <
class CHAR_TYPE,
class CHAR_TRAITS>
2305 const CHAR_TYPE *characterString,
2310 return find_first_not_of(characterString,
2312 CHAR_TRAITS::length(characterString));
2315template <
class CHAR_TYPE,
class CHAR_TRAITS>
2320 const CHAR_TYPE *characterString,
2326 if (position < length()) {
2327 for (
const CHAR_TYPE *current =
data() + position;
2331 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2332 return current -
data();
2339template <
class CHAR_TYPE,
class CHAR_TRAITS>
2344 CHAR_TYPE character,
2347 return find_first_not_of(&character, position,
size_type(1));
2350template <
class CHAR_TYPE,
class CHAR_TRAITS>
2358 return find_last_not_of(subview.data(), position, subview.length());
2361template <
class CHAR_TYPE,
class CHAR_TRAITS>
2366 const CHAR_TYPE *characterString,
2371 return find_last_not_of(characterString,
2373 CHAR_TRAITS::length(characterString));
2376template <
class CHAR_TYPE,
class CHAR_TRAITS>
2381 const CHAR_TYPE *characterString,
2388 size_type remChars = position < length() ? position : length() - 1;
2389 for (
const CHAR_TYPE *current =
data() + remChars;
2393 if (!CHAR_TRAITS::find(characterString, numChars, *current)) {
2394 return current -
data();
2401template <
class CHAR_TYPE,
class CHAR_TRAITS>
2406 CHAR_TYPE character,
2409 return find_last_not_of(&character, position,
size_type(1));
2413template <
class CHAR_TYPE,
class CHAR_TRAITS>
2418 using ::BloombergLP::bslh::hashAppend;
2419 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2420 hashAlg(input.data(),
sizeof(CHAR_TYPE) * input.size());
2422 return static_cast<std::size_t
>(hashAlg.computeHash());
2425template <
class CHAR_TYPE,
class CHAR_TRAITS>
2428operator()(
const CHAR_TYPE *input)
const
2431 using ::BloombergLP::bslh::hashAppend;
2432 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2434 std::size_t length = CHAR_TRAITS::length(input);
2436 hashAlg(input,
sizeof(CHAR_TYPE) * length);
2438 return static_cast<std::size_t
>(hashAlg.computeHash());
2441#if defined(BSLS_PLATFORM_CMP_SUN)
2446 using ::BloombergLP::bslh::hashAppend;
2447 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2448 hashAlg(input.
data(), input.
size());
2450 return static_cast<std::size_t
>(hashAlg.computeHash());
2457 using ::BloombergLP::bslh::hashAppend;
2458 std::size_t length = char_traits<char>::length(input);
2459 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2460 hashAlg(input, length);
2462 return static_cast<std::size_t
>(hashAlg.computeHash());
2468 using ::BloombergLP::bslh::hashAppend;
2469 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2470 hashAlg(input.data(),
sizeof(
wchar_t) * input.size());
2472 return static_cast<std::size_t
>(hashAlg.computeHash());
2479 using ::BloombergLP::bslh::hashAppend;
2480 std::size_t length = char_traits<wchar_t>::length(input);
2481 ::BloombergLP::bslh::Hash<>::HashAlgorithm hashAlg;
2482 hashAlg(input,
sizeof(
wchar_t) * length);
2484 return static_cast<std::size_t
>(hashAlg.computeHash());
2498template <
class CHAR_TYPE,
class CHAR_TRAITS>
2504 return lhs.size() == rhs.size()
2505 && 0 == CHAR_TRAITS::compare(lhs.data(), rhs.data(), lhs.size());
2508template <
class CHAR_TYPE,
class CHAR_TRAITS>
2514 const std::size_t minLen = lhs.length() < rhs.length()
2515 ? lhs.length() : rhs.length();
2517 int ret = CHAR_TRAITS::compare(lhs.data(), rhs.data(), minLen);
2519 return lhs.length() < rhs.length();
2528template <
class CHAR_TYPE,
class CHAR_TRAITS>
2531 basic_string_view<CHAR_TYPE, CHAR_TRAITS>& a,
2538template <
class CHAR_TYPE,
class CHAR_TRAITS>
2541bool BloombergLP::bslstl_stringview_relops::
2546 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2549template <
class CHAR_TYPE,
class CHAR_TRAITS>
2552bool BloombergLP::bslstl_stringview_relops::
2553operator==(
typename BloombergLP::bslstl::StringView_Identity<
2558 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2561template <
class CHAR_TYPE,
class CHAR_TRAITS>
2564bool BloombergLP::bslstl_stringview_relops::
2566 typename BloombergLP::bslstl::StringView_Identity<
2570 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2573template <
class CHAR_TYPE,
class CHAR_TRAITS>
2576bool BloombergLP::bslstl_stringview_relops::
2581 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2584template <
class CHAR_TYPE,
class CHAR_TRAITS>
2587bool BloombergLP::bslstl_stringview_relops::
2588operator!=(
typename BloombergLP::bslstl::StringView_Identity<
2593 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2596template <
class CHAR_TYPE,
class CHAR_TRAITS>
2599bool BloombergLP::bslstl_stringview_relops::
2601 typename BloombergLP::bslstl::StringView_Identity<
2605 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::equals(lhs, rhs);
2608template <
class CHAR_TYPE,
class CHAR_TRAITS>
2611bool BloombergLP::bslstl_stringview_relops::
2616 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2619template <
class CHAR_TYPE,
class CHAR_TRAITS>
2622bool BloombergLP::bslstl_stringview_relops::
2623operator<(
typename BloombergLP::bslstl::StringView_Identity<
2628 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2631template <
class CHAR_TYPE,
class CHAR_TRAITS>
2634bool BloombergLP::bslstl_stringview_relops::
2636 typename BloombergLP::bslstl::StringView_Identity<
2640 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2643template <
class CHAR_TYPE,
class CHAR_TRAITS>
2646bool BloombergLP::bslstl_stringview_relops::
2651 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2654template <
class CHAR_TYPE,
class CHAR_TRAITS>
2657bool BloombergLP::bslstl_stringview_relops::
2658operator>(
typename BloombergLP::bslstl::StringView_Identity<
2663 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2666template <
class CHAR_TYPE,
class CHAR_TRAITS>
2669bool BloombergLP::bslstl_stringview_relops::
2671 typename BloombergLP::bslstl::StringView_Identity<
2675 return StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2678template <
class CHAR_TYPE,
class CHAR_TRAITS>
2681bool BloombergLP::bslstl_stringview_relops::
2686 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2689template <
class CHAR_TYPE,
class CHAR_TRAITS>
2692bool BloombergLP::bslstl_stringview_relops::
2693operator<=(
typename BloombergLP::bslstl::StringView_Identity<
2698 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2701template <
class CHAR_TYPE,
class CHAR_TRAITS>
2704bool BloombergLP::bslstl_stringview_relops::
2706 typename BloombergLP::bslstl::StringView_Identity<
2710 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(rhs, lhs);
2713template <
class CHAR_TYPE,
class CHAR_TRAITS>
2716bool BloombergLP::bslstl_stringview_relops::
2721 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2724template <
class CHAR_TYPE,
class CHAR_TRAITS>
2727bool BloombergLP::bslstl_stringview_relops::
2728operator>=(
typename BloombergLP::bslstl::StringView_Identity<
2733 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2736template <
class CHAR_TYPE,
class CHAR_TRAITS>
2739bool BloombergLP::bslstl_stringview_relops::
2741 typename BloombergLP::bslstl::StringView_Identity<
2745 return !StringView_CompareUtil<CHAR_TYPE, CHAR_TRAITS>::lessThan(lhs, rhs);
2750using BloombergLP::bslstl_stringview_relops::operator==;
2751using BloombergLP::bslstl_stringview_relops::operator!=;
2752using BloombergLP::bslstl_stringview_relops::operator<;
2753using BloombergLP::bslstl_stringview_relops::operator>;
2754using BloombergLP::bslstl_stringview_relops::operator<=;
2755using BloombergLP::bslstl_stringview_relops::operator>=;
2759template <
class CHAR_TYPE,
class CHAR_TRAITS>
2760std::basic_ostream<CHAR_TYPE>&
2762 basic_string_view<CHAR_TYPE, CHAR_TRAITS> stringView)
2764 typedef CHAR_TYPE char_type;
2765 typedef typename std::basic_ostream<char_type>::ios_base ios_base;
2766 typedef typename basic_string_view<CHAR_TYPE, CHAR_TRAITS>::size_type
2769 size_type width =
static_cast<size_type
>(stream.width());
2770 size_type len = stringView.length();
2774 (stream.flags() & ios_base::adjustfield) == ios_base::left;
2776 char_type fillChar = stream.
fill();
2779 if (stringView.data()) {
2780 stream.write(stringView.data(), stringView.length());
2784 for (size_type n = 0; n != width - len; ++n) {
2785 stream.put(fillChar);
2788 if (!leftAdjusted) {
2789 if (stringView.data()) {
2790 stream.write(stringView.data(), stringView.length());
2795 if (stringView.data()) {
2796 stream.write(stringView.data(), stringView.length());
2806template <
class HASHALG,
class CHAR_TYPE,
class CHAR_TRAITS>
2809 const basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
2811 using ::BloombergLP::bslh::hashAppend;
2812 hashAlg(input.data(),
sizeof(CHAR_TYPE)*input.size());
2818#ifdef BSLSTL_STRING_VIEW_IS_ALIASED
2821template <
class HASHALG,
class CHAR_TYPE,
class CHAR_TRAITS>
2825 const std::basic_string_view<CHAR_TYPE, CHAR_TRAITS>& input)
2827 hashAlg(input.data(),
sizeof(CHAR_TYPE)*input.size());
2834#undef BSLSTL_STRING_VIEW_AND_STD_STRING_VIEW_COEXIST
Definition bslstl_stringview.h:441
std::ptrdiff_t difference_type
Definition bslstl_stringview.h:458
std::size_t size_type
Definition bslstl_stringview.h:457
BSLS_KEYWORD_CONSTEXPR const_iterator end() const BSLS_KEYWORD_NOEXCEPT
Return the past-the-end iterator for this view.
Definition bslstl_stringview.h:1620
BSLS_KEYWORD_CONSTEXPR size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1694
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type find(basic_string_view subview, size_type position=0) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2028
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:2170
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:1658
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_suffix(size_type numChars)
Definition bslstl_stringview.h:1582
const value_type & const_reference
Definition bslstl_stringview.h:450
const_iterator iterator
Definition bslstl_stringview.h:452
basic_string_view & operator=(const basic_string_view &rhs)=default
const value_type * const_pointer
Definition bslstl_stringview.h:448
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:2354
CHAR_TRAITS traits_type
Definition bslstl_stringview.h:445
BSLS_KEYWORD_CONSTEXPR size_type length() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1685
CHAR_TYPE value_type
Definition bslstl_stringview.h:446
size_type copy(CHAR_TYPE *characterString, size_type numChars, size_type position=0) const
Definition bslstl_stringview.h:1767
BSLS_KEYWORD_CONSTEXPR const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1611
BSLS_KEYWORD_CONSTEXPR const_pointer data() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1760
BSLS_KEYWORD_CONSTEXPR_CPP17 bool starts_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1959
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:2231
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view substr(size_type position=0, size_type numChars=npos) const
Definition bslstl_stringview.h:1799
value_type * pointer
Definition bslstl_stringview.h:447
BSLS_KEYWORD_CONSTEXPR const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1630
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference back() const
Definition bslstl_stringview.h:1749
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_stringview.h:455
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator rbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1639
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_stringview.h:454
BSLS_KEYWORD_CONSTEXPR size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1676
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:2293
BSLS_KEYWORD_CONSTEXPR_CPP17 bool ends_with(basic_string_view subview) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1999
BSLS_KEYWORD_CONSTEXPR_CPP14 size_type rfind(basic_string_view subview, size_type position=npos) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:2103
value_type & reference
Definition bslstl_stringview.h:449
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference front() const
Definition bslstl_stringview.h:1738
BSLS_KEYWORD_CONSTEXPR_CPP17 int compare(basic_string_view other) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1818
void swap(basic_string_view &other) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1590
BSLS_KEYWORD_CONSTEXPR basic_string_view() BSLS_KEYWORD_NOEXCEPT
Create an empty view.
Definition bslstl_stringview.h:1481
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference at(size_type position) const
Definition bslstl_stringview.h:1724
static const size_type npos
Definition bslstl_stringview.h:465
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference operator[](size_type position) const
Definition bslstl_stringview.h:1713
const value_type * const_iterator
Definition bslstl_stringview.h:451
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1667
~basic_string_view()=default
Destroy this object.
BSLS_KEYWORD_CONSTEXPR const_iterator begin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1602
BSLS_KEYWORD_CONSTEXPR_CPP17 const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1648
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:1572
BSLS_KEYWORD_CONSTEXPR bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this view has length 0, and false otherwise.
Definition bslstl_stringview.h:1703
Definition bslstl_string.h:1281
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR_CPP14
Definition bsls_keyword.h:595
#define BSLS_KEYWORD_CONSTEXPR_CPP17
Definition bsls_keyword.h:603
#define BSLS_KEYWORD_EXPLICIT
Definition bsls_keyword.h:641
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
Definition bdlb_printmethods.h:283
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const array< TYPE, SIZE > &input)
Pass the specified input to the specified hashAlgorithm
Definition bslstl_array.h:950
basic_string_view< char > string_view
Definition bslstl_stringview.h:1053
T::iterator begin(T &container)
Definition bslstl_iterator.h:1495
std::basic_ostream< CHAR_TYPE, TRAITS > & operator<<(std::basic_ostream< CHAR_TYPE, TRAITS > &os, const bitset< N > &x)
Definition bslstl_bitset.h:1402
BSLS_KEYWORD_CONSTEXPR size_t size(const TYPE(&)[DIMENSION]) BSLS_KEYWORD_NOEXCEPT
Return the dimension of the specified array argument.
Definition bslstl_iterator.h:1331
T::iterator end(T &container)
Definition bslstl_iterator.h:1523
basic_string_view< wchar_t > wstring_view
Definition bslstl_stringview.h:1054
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1231
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1279
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:638
Definition bslstl_stringview.h:1076
Definition bslstl_algorithm.h:82
Definition bdldfp_decimal.h:5188
void swap(TYPE &a, TYPE &b)
Definition bslstl_stringview.h:396
Definition bslstl_stringview.h:409
Definition bslmf_enableif.h:525
Definition bslstl_hash.h:498
std::size_t operator()(const TYPE &value) const
Definition bslstl_hash.h:1031
Definition bslmf_integralconstant.h:244
Definition bslmf_isconvertible.h:867
Definition bslmf_istriviallycopyable.h:329
Definition bslstl_stringview.h:331
TYPE type
Definition bslstl_stringview.h:374
Definition bslstl_stringview.h:1090
bsl::basic_string_view< CHAR_TYPE, CHAR_TRAITS > StringView
Definition bslstl_stringview.h:1093
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:2501
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:2511