17d62b00eSchristos // Components for manipulating non-owning sequences of characters -*- C++ -*- 27d62b00eSchristos 37d62b00eSchristos 47d62b00eSchristos #ifndef COMMON_GDB_STRING_VIEW_H 57d62b00eSchristos #define COMMON_GDB_STRING_VIEW_H 67d62b00eSchristos 77d62b00eSchristos // Note: This file has been stolen from the gcc repo 87d62b00eSchristos // (libstdc++-v3/include/experimental/string_view) and has local modifications. 97d62b00eSchristos 10*6881a400Schristos // Copyright (C) 2013-2023 Free Software Foundation, Inc. 117d62b00eSchristos // 127d62b00eSchristos // This file is part of the GNU ISO C++ Library. This library is free 137d62b00eSchristos // software; you can redistribute it and/or modify it under the 147d62b00eSchristos // terms of the GNU General Public License as published by the 157d62b00eSchristos // Free Software Foundation; either version 3, or (at your option) 167d62b00eSchristos // any later version. 177d62b00eSchristos 187d62b00eSchristos // This library is distributed in the hope that it will be useful, 197d62b00eSchristos // but WITHOUT ANY WARRANTY; without even the implied warranty of 207d62b00eSchristos // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 217d62b00eSchristos // GNU General Public License for more details. 227d62b00eSchristos 237d62b00eSchristos // Under Section 7 of GPL version 3, you are granted additional 247d62b00eSchristos // permissions described in the GCC Runtime Library Exception, version 257d62b00eSchristos // 3.1, as published by the Free Software Foundation. 267d62b00eSchristos 277d62b00eSchristos // You should have received a copy of the GNU General Public License and 287d62b00eSchristos // a copy of the GCC Runtime Library Exception along with this program; 297d62b00eSchristos // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 307d62b00eSchristos // <http://www.gnu.org/licenses/>. 317d62b00eSchristos 327d62b00eSchristos // 337d62b00eSchristos // N3762 basic_string_view library 347d62b00eSchristos // 357d62b00eSchristos 367d62b00eSchristos 377d62b00eSchristos #if __cplusplus >= 201703L 387d62b00eSchristos 397d62b00eSchristos #include <string_view> 407d62b00eSchristos 417d62b00eSchristos namespace gdb { 427d62b00eSchristos using string_view = std::string_view; 437d62b00eSchristos } /* namespace gdb */ 447d62b00eSchristos 457d62b00eSchristos #else /* __cplusplus < 201703L */ 467d62b00eSchristos 477d62b00eSchristos #include <string> 487d62b00eSchristos #include <limits> 497d62b00eSchristos #include "gdb_assert.h" 507d62b00eSchristos 517d62b00eSchristos namespace gdb { 527d62b00eSchristos 537d62b00eSchristos /** 547d62b00eSchristos * @class basic_string_view <experimental/string_view> 557d62b00eSchristos * @brief A non-owning reference to a string. 567d62b00eSchristos * 577d62b00eSchristos * @ingroup strings 587d62b00eSchristos * @ingroup sequences 597d62b00eSchristos * @ingroup experimental 607d62b00eSchristos * 617d62b00eSchristos * @tparam _CharT Type of character 627d62b00eSchristos * @tparam _Traits Traits for character type, defaults to 637d62b00eSchristos * char_traits<_CharT>. 647d62b00eSchristos * 657d62b00eSchristos * A basic_string_view looks like this: 667d62b00eSchristos * 677d62b00eSchristos * @code 687d62b00eSchristos * _CharT* _M_str 697d62b00eSchristos * size_t _M_len 707d62b00eSchristos * @endcode 717d62b00eSchristos */ 727d62b00eSchristos template<typename _CharT, typename _Traits = std::char_traits<_CharT>> 737d62b00eSchristos class basic_string_view 747d62b00eSchristos { 757d62b00eSchristos public: 767d62b00eSchristos 777d62b00eSchristos // types 787d62b00eSchristos using traits_type = _Traits; 797d62b00eSchristos using value_type = _CharT; 807d62b00eSchristos using pointer = const _CharT*; 817d62b00eSchristos using const_pointer = const _CharT*; 827d62b00eSchristos using reference = const _CharT&; 837d62b00eSchristos using const_reference = const _CharT&; 847d62b00eSchristos using const_iterator = const _CharT*; 857d62b00eSchristos using iterator = const_iterator; 867d62b00eSchristos using const_reverse_iterator = std::reverse_iterator<const_iterator>; 877d62b00eSchristos using reverse_iterator = const_reverse_iterator; 887d62b00eSchristos using size_type = size_t; 897d62b00eSchristos using difference_type = ptrdiff_t; 907d62b00eSchristos static constexpr size_type npos = size_type(-1); 917d62b00eSchristos 927d62b00eSchristos // [string.view.cons], construct/copy 937d62b00eSchristos 947d62b00eSchristos constexpr 957d62b00eSchristos basic_string_view() noexcept 967d62b00eSchristos : _M_len{0}, _M_str{nullptr} 977d62b00eSchristos { } 987d62b00eSchristos 997d62b00eSchristos constexpr basic_string_view(const basic_string_view&) noexcept = default; 1007d62b00eSchristos 1017d62b00eSchristos template<typename _Allocator> 1027d62b00eSchristos basic_string_view(const std::basic_string<_CharT, _Traits, 1037d62b00eSchristos _Allocator>& __str) noexcept 1047d62b00eSchristos : _M_len{__str.length()}, _M_str{__str.data()} 1057d62b00eSchristos { } 1067d62b00eSchristos 1077d62b00eSchristos /*constexpr*/ basic_string_view(const _CharT* __str) 1087d62b00eSchristos : _M_len{__str == nullptr ? 0 : traits_type::length(__str)}, 1097d62b00eSchristos _M_str{__str} 1107d62b00eSchristos { } 1117d62b00eSchristos 1127d62b00eSchristos constexpr basic_string_view(const _CharT* __str, size_type __len) 1137d62b00eSchristos : _M_len{__len}, 1147d62b00eSchristos _M_str{__str} 1157d62b00eSchristos { } 1167d62b00eSchristos 1177d62b00eSchristos basic_string_view& 1187d62b00eSchristos operator=(const basic_string_view&) noexcept = default; 1197d62b00eSchristos 1207d62b00eSchristos // [string.view.iterators], iterators 1217d62b00eSchristos 1227d62b00eSchristos constexpr const_iterator 1237d62b00eSchristos begin() const noexcept 1247d62b00eSchristos { return this->_M_str; } 1257d62b00eSchristos 1267d62b00eSchristos constexpr const_iterator 1277d62b00eSchristos end() const noexcept 1287d62b00eSchristos { return this->_M_str + this->_M_len; } 1297d62b00eSchristos 1307d62b00eSchristos constexpr const_iterator 1317d62b00eSchristos cbegin() const noexcept 1327d62b00eSchristos { return this->_M_str; } 1337d62b00eSchristos 1347d62b00eSchristos constexpr const_iterator 1357d62b00eSchristos cend() const noexcept 1367d62b00eSchristos { return this->_M_str + this->_M_len; } 1377d62b00eSchristos 1387d62b00eSchristos const_reverse_iterator 1397d62b00eSchristos rbegin() const noexcept 1407d62b00eSchristos { return const_reverse_iterator(this->end()); } 1417d62b00eSchristos 1427d62b00eSchristos const_reverse_iterator 1437d62b00eSchristos rend() const noexcept 1447d62b00eSchristos { return const_reverse_iterator(this->begin()); } 1457d62b00eSchristos 1467d62b00eSchristos const_reverse_iterator 1477d62b00eSchristos crbegin() const noexcept 1487d62b00eSchristos { return const_reverse_iterator(this->end()); } 1497d62b00eSchristos 1507d62b00eSchristos const_reverse_iterator 1517d62b00eSchristos crend() const noexcept 1527d62b00eSchristos { return const_reverse_iterator(this->begin()); } 1537d62b00eSchristos 1547d62b00eSchristos // [string.view.capacity], capacity 1557d62b00eSchristos 1567d62b00eSchristos constexpr size_type 1577d62b00eSchristos size() const noexcept 1587d62b00eSchristos { return this->_M_len; } 1597d62b00eSchristos 1607d62b00eSchristos constexpr size_type 1617d62b00eSchristos length() const noexcept 1627d62b00eSchristos { return _M_len; } 1637d62b00eSchristos 1647d62b00eSchristos constexpr size_type 1657d62b00eSchristos max_size() const noexcept 1667d62b00eSchristos { 1677d62b00eSchristos return (npos - sizeof(size_type) - sizeof(void*)) 1687d62b00eSchristos / sizeof(value_type) / 4; 1697d62b00eSchristos } 1707d62b00eSchristos 1717d62b00eSchristos constexpr bool 1727d62b00eSchristos empty() const noexcept 1737d62b00eSchristos { return this->_M_len == 0; } 1747d62b00eSchristos 1757d62b00eSchristos // [string.view.access], element access 1767d62b00eSchristos 1777d62b00eSchristos constexpr const _CharT& 1787d62b00eSchristos operator[](size_type __pos) const 1797d62b00eSchristos { 1807d62b00eSchristos // TODO: Assert to restore in a way compatible with the constexpr. 1817d62b00eSchristos // __glibcxx_assert(__pos < this->_M_len); 1827d62b00eSchristos return *(this->_M_str + __pos); 1837d62b00eSchristos } 1847d62b00eSchristos 1857d62b00eSchristos constexpr const _CharT& 1867d62b00eSchristos at(size_type __pos) const 1877d62b00eSchristos { 1887d62b00eSchristos return __pos < this->_M_len 1897d62b00eSchristos ? *(this->_M_str + __pos) 1907d62b00eSchristos : (error (_("basic_string_view::at: __pos " 1917d62b00eSchristos "(which is %zu) >= this->size() " 1927d62b00eSchristos "(which is %zu)"), 1937d62b00eSchristos __pos, this->size()), 1947d62b00eSchristos *this->_M_str); 1957d62b00eSchristos } 1967d62b00eSchristos 1977d62b00eSchristos constexpr const _CharT& 1987d62b00eSchristos front() const 1997d62b00eSchristos { 2007d62b00eSchristos // TODO: Assert to restore in a way compatible with the constexpr. 2017d62b00eSchristos // __glibcxx_assert(this->_M_len > 0); 2027d62b00eSchristos return *this->_M_str; 2037d62b00eSchristos } 2047d62b00eSchristos 2057d62b00eSchristos constexpr const _CharT& 2067d62b00eSchristos back() const 2077d62b00eSchristos { 2087d62b00eSchristos // TODO: Assert to restore in a way compatible with the constexpr. 2097d62b00eSchristos // __glibcxx_assert(this->_M_len > 0); 2107d62b00eSchristos return *(this->_M_str + this->_M_len - 1); 2117d62b00eSchristos } 2127d62b00eSchristos 2137d62b00eSchristos constexpr const _CharT* 2147d62b00eSchristos data() const noexcept 2157d62b00eSchristos { return this->_M_str; } 2167d62b00eSchristos 2177d62b00eSchristos // [string.view.modifiers], modifiers: 2187d62b00eSchristos 2197d62b00eSchristos /*constexpr*/ void 2207d62b00eSchristos remove_prefix(size_type __n) 2217d62b00eSchristos { 2227d62b00eSchristos gdb_assert (this->_M_len >= __n); 2237d62b00eSchristos this->_M_str += __n; 2247d62b00eSchristos this->_M_len -= __n; 2257d62b00eSchristos } 2267d62b00eSchristos 2277d62b00eSchristos /*constexpr*/ void 2287d62b00eSchristos remove_suffix(size_type __n) 2297d62b00eSchristos { this->_M_len -= __n; } 2307d62b00eSchristos 2317d62b00eSchristos /*constexpr*/ void 2327d62b00eSchristos swap(basic_string_view& __sv) noexcept 2337d62b00eSchristos { 2347d62b00eSchristos auto __tmp = *this; 2357d62b00eSchristos *this = __sv; 2367d62b00eSchristos __sv = __tmp; 2377d62b00eSchristos } 2387d62b00eSchristos 2397d62b00eSchristos 2407d62b00eSchristos // [string.view.ops], string operations: 2417d62b00eSchristos 2427d62b00eSchristos template<typename _Allocator> 2437d62b00eSchristos explicit operator std::basic_string<_CharT, _Traits, _Allocator>() const 2447d62b00eSchristos { 2457d62b00eSchristos return { this->_M_str, this->_M_len }; 2467d62b00eSchristos } 2477d62b00eSchristos 2487d62b00eSchristos size_type 2497d62b00eSchristos copy(_CharT* __str, size_type __n, size_type __pos = 0) const 2507d62b00eSchristos { 2517d62b00eSchristos gdb_assert (__str != nullptr || __n == 0); 2527d62b00eSchristos if (__pos > this->_M_len) 2537d62b00eSchristos error (_("basic_string_view::copy: __pos " 2547d62b00eSchristos "(which is %zu) > this->size() " 2557d62b00eSchristos "(which is %zu)"), 2567d62b00eSchristos __pos, this->size()); 2577d62b00eSchristos size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})}; 2587d62b00eSchristos for (auto __begin = this->_M_str + __pos, 2597d62b00eSchristos __end = __begin + __rlen; __begin != __end;) 2607d62b00eSchristos *__str++ = *__begin++; 2617d62b00eSchristos return __rlen; 2627d62b00eSchristos } 2637d62b00eSchristos 2647d62b00eSchristos 2657d62b00eSchristos // [string.view.ops], string operations: 2667d62b00eSchristos 2677d62b00eSchristos /*constexpr*/ basic_string_view 2687d62b00eSchristos substr(size_type __pos, size_type __n=npos) const 2697d62b00eSchristos { 2707d62b00eSchristos return __pos <= this->_M_len 2717d62b00eSchristos ? basic_string_view{this->_M_str + __pos, 2727d62b00eSchristos std::min(__n, size_type{this->_M_len - __pos})} 2737d62b00eSchristos : (error (_("basic_string_view::substr: __pos " 2747d62b00eSchristos "(which is %zu) > this->size() " 2757d62b00eSchristos "(which is %zu)"), 2767d62b00eSchristos __pos, this->size()), basic_string_view{}); 2777d62b00eSchristos } 2787d62b00eSchristos 2797d62b00eSchristos /*constexpr*/ int 2807d62b00eSchristos compare(basic_string_view __str) const noexcept 2817d62b00eSchristos { 2827d62b00eSchristos int __ret = traits_type::compare(this->_M_str, __str._M_str, 2837d62b00eSchristos std::min(this->_M_len, __str._M_len)); 2847d62b00eSchristos if (__ret == 0) 2857d62b00eSchristos __ret = _S_compare(this->_M_len, __str._M_len); 2867d62b00eSchristos return __ret; 2877d62b00eSchristos } 2887d62b00eSchristos 2897d62b00eSchristos /*constexpr*/ int 2907d62b00eSchristos compare(size_type __pos1, size_type __n1, basic_string_view __str) const 2917d62b00eSchristos { return this->substr(__pos1, __n1).compare(__str); } 2927d62b00eSchristos 2937d62b00eSchristos /*constexpr*/ int 2947d62b00eSchristos compare(size_type __pos1, size_type __n1, 2957d62b00eSchristos basic_string_view __str, size_type __pos2, size_type __n2) const 2967d62b00eSchristos { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); } 2977d62b00eSchristos 2987d62b00eSchristos /*constexpr*/ int 2997d62b00eSchristos compare(const _CharT* __str) const noexcept 3007d62b00eSchristos { return this->compare(basic_string_view{__str}); } 3017d62b00eSchristos 3027d62b00eSchristos /*constexpr*/ int 3037d62b00eSchristos compare(size_type __pos1, size_type __n1, const _CharT* __str) const 3047d62b00eSchristos { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); } 3057d62b00eSchristos 3067d62b00eSchristos /*constexpr*/ int 3077d62b00eSchristos compare(size_type __pos1, size_type __n1, 3087d62b00eSchristos const _CharT* __str, size_type __n2) const 3097d62b00eSchristos { 3107d62b00eSchristos return this->substr(__pos1, __n1) 3117d62b00eSchristos .compare(basic_string_view(__str, __n2)); 3127d62b00eSchristos } 3137d62b00eSchristos 3147d62b00eSchristos /*constexpr*/ size_type 3157d62b00eSchristos find(basic_string_view __str, size_type __pos = 0) const noexcept 3167d62b00eSchristos { return this->find(__str._M_str, __pos, __str._M_len); } 3177d62b00eSchristos 3187d62b00eSchristos /*constexpr*/ size_type 3197d62b00eSchristos find(_CharT __c, size_type __pos=0) const noexcept; 3207d62b00eSchristos 3217d62b00eSchristos /*constexpr*/ size_type 3227d62b00eSchristos find(const _CharT* __str, size_type __pos, size_type __n) const noexcept; 3237d62b00eSchristos 3247d62b00eSchristos /*constexpr*/ size_type 3257d62b00eSchristos find(const _CharT* __str, size_type __pos=0) const noexcept 3267d62b00eSchristos { return this->find(__str, __pos, traits_type::length(__str)); } 3277d62b00eSchristos 3287d62b00eSchristos /*constexpr*/ size_type 3297d62b00eSchristos rfind(basic_string_view __str, size_type __pos = npos) const noexcept 3307d62b00eSchristos { return this->rfind(__str._M_str, __pos, __str._M_len); } 3317d62b00eSchristos 3327d62b00eSchristos /*constexpr*/ size_type 3337d62b00eSchristos rfind(_CharT __c, size_type __pos = npos) const noexcept; 3347d62b00eSchristos 3357d62b00eSchristos /*constexpr*/ size_type 3367d62b00eSchristos rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept; 3377d62b00eSchristos 3387d62b00eSchristos /*constexpr*/ size_type 3397d62b00eSchristos rfind(const _CharT* __str, size_type __pos = npos) const noexcept 3407d62b00eSchristos { return this->rfind(__str, __pos, traits_type::length(__str)); } 3417d62b00eSchristos 3427d62b00eSchristos /*constexpr*/ size_type 3437d62b00eSchristos find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept 3447d62b00eSchristos { return this->find_first_of(__str._M_str, __pos, __str._M_len); } 3457d62b00eSchristos 3467d62b00eSchristos /*constexpr*/ size_type 3477d62b00eSchristos find_first_of(_CharT __c, size_type __pos = 0) const noexcept 3487d62b00eSchristos { return this->find(__c, __pos); } 3497d62b00eSchristos 3507d62b00eSchristos /*constexpr*/ size_type 3517d62b00eSchristos find_first_of(const _CharT* __str, size_type __pos, size_type __n) const; 3527d62b00eSchristos 3537d62b00eSchristos /*constexpr*/ size_type 3547d62b00eSchristos find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept 3557d62b00eSchristos { return this->find_first_of(__str, __pos, traits_type::length(__str)); } 3567d62b00eSchristos 3577d62b00eSchristos /*constexpr*/ size_type 3587d62b00eSchristos find_last_of(basic_string_view __str, 3597d62b00eSchristos size_type __pos = npos) const noexcept 3607d62b00eSchristos { return this->find_last_of(__str._M_str, __pos, __str._M_len); } 3617d62b00eSchristos 3627d62b00eSchristos size_type 3637d62b00eSchristos find_last_of(_CharT __c, size_type __pos=npos) const noexcept 3647d62b00eSchristos { return this->rfind(__c, __pos); } 3657d62b00eSchristos 3667d62b00eSchristos /*constexpr*/ size_type 3677d62b00eSchristos find_last_of(const _CharT* __str, size_type __pos, size_type __n) const; 3687d62b00eSchristos 3697d62b00eSchristos /*constexpr*/ size_type 3707d62b00eSchristos find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept 3717d62b00eSchristos { return this->find_last_of(__str, __pos, traits_type::length(__str)); } 3727d62b00eSchristos 3737d62b00eSchristos /*constexpr*/ size_type 3747d62b00eSchristos find_first_not_of(basic_string_view __str, 3757d62b00eSchristos size_type __pos = 0) const noexcept 3767d62b00eSchristos { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); } 3777d62b00eSchristos 3787d62b00eSchristos /*constexpr*/ size_type 3797d62b00eSchristos find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept; 3807d62b00eSchristos 3817d62b00eSchristos /*constexpr*/ size_type 3827d62b00eSchristos find_first_not_of(const _CharT* __str, 3837d62b00eSchristos size_type __pos, size_type __n) const; 3847d62b00eSchristos 3857d62b00eSchristos /*constexpr*/ size_type 3867d62b00eSchristos find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept 3877d62b00eSchristos { 3887d62b00eSchristos return this->find_first_not_of(__str, __pos, 3897d62b00eSchristos traits_type::length(__str)); 3907d62b00eSchristos } 3917d62b00eSchristos 3927d62b00eSchristos /*constexpr*/ size_type 3937d62b00eSchristos find_last_not_of(basic_string_view __str, 3947d62b00eSchristos size_type __pos = npos) const noexcept 3957d62b00eSchristos { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); } 3967d62b00eSchristos 3977d62b00eSchristos /*constexpr*/ size_type 3987d62b00eSchristos find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept; 3997d62b00eSchristos 4007d62b00eSchristos /*constexpr*/ size_type 4017d62b00eSchristos find_last_not_of(const _CharT* __str, 4027d62b00eSchristos size_type __pos, size_type __n) const; 4037d62b00eSchristos 4047d62b00eSchristos /*constexpr*/ size_type 4057d62b00eSchristos find_last_not_of(const _CharT* __str, 4067d62b00eSchristos size_type __pos = npos) const noexcept 4077d62b00eSchristos { 4087d62b00eSchristos return this->find_last_not_of(__str, __pos, 4097d62b00eSchristos traits_type::length(__str)); 4107d62b00eSchristos } 4117d62b00eSchristos 4127d62b00eSchristos private: 4137d62b00eSchristos 4147d62b00eSchristos static constexpr int 4157d62b00eSchristos _S_compare(size_type __n1, size_type __n2) noexcept 4167d62b00eSchristos { 4177d62b00eSchristos return difference_type(__n1 - __n2) > std::numeric_limits<int>::max() 4187d62b00eSchristos ? std::numeric_limits<int>::max() 4197d62b00eSchristos : difference_type(__n1 - __n2) < std::numeric_limits<int>::min() 4207d62b00eSchristos ? std::numeric_limits<int>::min() 4217d62b00eSchristos : static_cast<int>(difference_type(__n1 - __n2)); 4227d62b00eSchristos } 4237d62b00eSchristos 4247d62b00eSchristos size_t _M_len; 4257d62b00eSchristos const _CharT* _M_str; 4267d62b00eSchristos }; 4277d62b00eSchristos 4287d62b00eSchristos // [string.view.comparison], non-member basic_string_view comparison functions 4297d62b00eSchristos 4307d62b00eSchristos namespace __detail 4317d62b00eSchristos { 4327d62b00eSchristos // Identity transform to create a non-deduced context, so that only one 4337d62b00eSchristos // argument participates in template argument deduction and the other 4347d62b00eSchristos // argument gets implicitly converted to the deduced type. See n3766.html. 4357d62b00eSchristos template<typename _Tp> 4367d62b00eSchristos using __idt = typename std::common_type<_Tp>::type; 4377d62b00eSchristos } 4387d62b00eSchristos 4397d62b00eSchristos template<typename _CharT, typename _Traits> 4407d62b00eSchristos /*constexpr*/ bool 4417d62b00eSchristos operator==(basic_string_view<_CharT, _Traits> __x, 4427d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4437d62b00eSchristos { return __x.size() == __y.size() && __x.compare(__y) == 0; } 4447d62b00eSchristos 4457d62b00eSchristos template<typename _CharT, typename _Traits> 4467d62b00eSchristos /*constexpr*/ bool 4477d62b00eSchristos operator==(basic_string_view<_CharT, _Traits> __x, 4487d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 4497d62b00eSchristos { return __x.size() == __y.size() && __x.compare(__y) == 0; } 4507d62b00eSchristos 4517d62b00eSchristos template<typename _CharT, typename _Traits> 4527d62b00eSchristos /*constexpr*/ bool 4537d62b00eSchristos operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 4547d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4557d62b00eSchristos { return __x.size() == __y.size() && __x.compare(__y) == 0; } 4567d62b00eSchristos 4577d62b00eSchristos template<typename _CharT, typename _Traits> 4587d62b00eSchristos /*constexpr*/ bool 4597d62b00eSchristos operator!=(basic_string_view<_CharT, _Traits> __x, 4607d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4617d62b00eSchristos { return !(__x == __y); } 4627d62b00eSchristos 4637d62b00eSchristos template<typename _CharT, typename _Traits> 4647d62b00eSchristos /*constexpr*/ bool 4657d62b00eSchristos operator!=(basic_string_view<_CharT, _Traits> __x, 4667d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 4677d62b00eSchristos { return !(__x == __y); } 4687d62b00eSchristos 4697d62b00eSchristos template<typename _CharT, typename _Traits> 4707d62b00eSchristos /*constexpr*/ bool 4717d62b00eSchristos operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 4727d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4737d62b00eSchristos { return !(__x == __y); } 4747d62b00eSchristos 4757d62b00eSchristos template<typename _CharT, typename _Traits> 4767d62b00eSchristos /*constexpr*/ bool 4777d62b00eSchristos operator< (basic_string_view<_CharT, _Traits> __x, 4787d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4797d62b00eSchristos { return __x.compare(__y) < 0; } 4807d62b00eSchristos 4817d62b00eSchristos template<typename _CharT, typename _Traits> 4827d62b00eSchristos /*constexpr*/ bool 4837d62b00eSchristos operator< (basic_string_view<_CharT, _Traits> __x, 4847d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 4857d62b00eSchristos { return __x.compare(__y) < 0; } 4867d62b00eSchristos 4877d62b00eSchristos template<typename _CharT, typename _Traits> 4887d62b00eSchristos /*constexpr*/ bool 4897d62b00eSchristos operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 4907d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4917d62b00eSchristos { return __x.compare(__y) < 0; } 4927d62b00eSchristos 4937d62b00eSchristos template<typename _CharT, typename _Traits> 4947d62b00eSchristos /*constexpr*/ bool 4957d62b00eSchristos operator> (basic_string_view<_CharT, _Traits> __x, 4967d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 4977d62b00eSchristos { return __x.compare(__y) > 0; } 4987d62b00eSchristos 4997d62b00eSchristos template<typename _CharT, typename _Traits> 5007d62b00eSchristos /*constexpr*/ bool 5017d62b00eSchristos operator> (basic_string_view<_CharT, _Traits> __x, 5027d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 5037d62b00eSchristos { return __x.compare(__y) > 0; } 5047d62b00eSchristos 5057d62b00eSchristos template<typename _CharT, typename _Traits> 5067d62b00eSchristos /*constexpr*/ bool 5077d62b00eSchristos operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 5087d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 5097d62b00eSchristos { return __x.compare(__y) > 0; } 5107d62b00eSchristos 5117d62b00eSchristos template<typename _CharT, typename _Traits> 5127d62b00eSchristos /*constexpr*/ bool 5137d62b00eSchristos operator<=(basic_string_view<_CharT, _Traits> __x, 5147d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 5157d62b00eSchristos { return __x.compare(__y) <= 0; } 5167d62b00eSchristos 5177d62b00eSchristos template<typename _CharT, typename _Traits> 5187d62b00eSchristos /*constexpr*/ bool 5197d62b00eSchristos operator<=(basic_string_view<_CharT, _Traits> __x, 5207d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 5217d62b00eSchristos { return __x.compare(__y) <= 0; } 5227d62b00eSchristos 5237d62b00eSchristos template<typename _CharT, typename _Traits> 5247d62b00eSchristos /*constexpr*/ bool 5257d62b00eSchristos operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 5267d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 5277d62b00eSchristos { return __x.compare(__y) <= 0; } 5287d62b00eSchristos 5297d62b00eSchristos template<typename _CharT, typename _Traits> 5307d62b00eSchristos /*constexpr*/ bool 5317d62b00eSchristos operator>=(basic_string_view<_CharT, _Traits> __x, 5327d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 5337d62b00eSchristos { return __x.compare(__y) >= 0; } 5347d62b00eSchristos 5357d62b00eSchristos template<typename _CharT, typename _Traits> 5367d62b00eSchristos /*constexpr*/ bool 5377d62b00eSchristos operator>=(basic_string_view<_CharT, _Traits> __x, 5387d62b00eSchristos __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 5397d62b00eSchristos { return __x.compare(__y) >= 0; } 5407d62b00eSchristos 5417d62b00eSchristos template<typename _CharT, typename _Traits> 5427d62b00eSchristos /*constexpr*/ bool 5437d62b00eSchristos operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 5447d62b00eSchristos basic_string_view<_CharT, _Traits> __y) noexcept 5457d62b00eSchristos { return __x.compare(__y) >= 0; } 5467d62b00eSchristos 5477d62b00eSchristos // basic_string_view typedef names 5487d62b00eSchristos 5497d62b00eSchristos using string_view = basic_string_view<char>; 5507d62b00eSchristos } /* namespace gdb */ 5517d62b00eSchristos 5527d62b00eSchristos #include "gdb_string_view.tcc" 5537d62b00eSchristos 5547d62b00eSchristos #endif // __cplusplus < 201703L 5557d62b00eSchristos 5567d62b00eSchristos namespace gdb { 5577d62b00eSchristos 5587d62b00eSchristos static inline std::string 5597d62b00eSchristos to_string(const gdb::string_view &view) 5607d62b00eSchristos { 5617d62b00eSchristos return { view.data (), view.size () }; 5627d62b00eSchristos } 5637d62b00eSchristos 5647d62b00eSchristos } 5657d62b00eSchristos 5667d62b00eSchristos #endif /* COMMON_GDB_STRING_VIEW_H */ 567