1 // Components for manipulating non-owning sequences of characters -*- C++ -*-
3 // Note: This file has been stolen from the gcc repo
4 // (libstdc++-v3/include/experimental/bits/string_view.tcc) and has local
7 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // Under Section 7 of GPL version 3, you are granted additional
21 // permissions described in the GCC Runtime Library Exception, version
22 // 3.1, as published by the Free Software Foundation.
24 // You should have received a copy of the GNU General Public License and
25 // a copy of the GCC Runtime Library Exception along with this program;
26 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27 // <http://www.gnu.org/licenses/>.
29 /** @file experimental/bits/string_view.tcc
30 * This is an internal header file, included by other library headers.
31 * Do not attempt to use it directly. @headername{experimental/string_view}
35 // N3762 basic_string_view library
38 #ifndef GDB_STRING_VIEW_TCC
39 #define GDB_STRING_VIEW_TCC 1
43 template<typename _CharT, typename _Traits>
44 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
45 basic_string_view<_CharT, _Traits>::
46 find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
48 gdb_assert (__str != nullptr || __n == 0);
51 return __pos <= this->_M_len ? __pos : npos;
53 if (__n <= this->_M_len)
55 for (; __pos <= this->_M_len - __n; ++__pos)
56 if (traits_type::eq(this->_M_str[__pos], __str[0])
57 && traits_type::compare(this->_M_str + __pos + 1,
58 __str + 1, __n - 1) == 0)
64 template<typename _CharT, typename _Traits>
65 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
66 basic_string_view<_CharT, _Traits>::
67 find(_CharT __c, size_type __pos) const noexcept
69 size_type __ret = npos;
70 if (__pos < this->_M_len)
72 const size_type __n = this->_M_len - __pos;
73 const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
75 __ret = __p - this->_M_str;
80 template<typename _CharT, typename _Traits>
81 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
82 basic_string_view<_CharT, _Traits>::
83 rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
85 gdb_assert (__str != nullptr || __n == 0);
87 if (__n <= this->_M_len)
89 __pos = std::min(size_type(this->_M_len - __n), __pos);
92 if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
100 template<typename _CharT, typename _Traits>
101 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
102 basic_string_view<_CharT, _Traits>::
103 rfind(_CharT __c, size_type __pos) const noexcept
105 size_type __size = this->_M_len;
108 if (--__size > __pos)
110 for (++__size; __size-- > 0; )
111 if (traits_type::eq(this->_M_str[__size], __c))
117 template<typename _CharT, typename _Traits>
118 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
119 basic_string_view<_CharT, _Traits>::
120 find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
122 gdb_assert (__str != nullptr || __n == 0);
123 for (; __n && __pos < this->_M_len; ++__pos)
125 const _CharT* __p = traits_type::find(__str, __n,
126 this->_M_str[__pos]);
133 template<typename _CharT, typename _Traits>
134 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
135 basic_string_view<_CharT, _Traits>::
136 find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
138 gdb_assert (__str != nullptr || __n == 0);
139 size_type __size = this->size();
142 if (--__size > __pos)
146 if (traits_type::find(__str, __n, this->_M_str[__size]))
149 while (__size-- != 0);
154 template<typename _CharT, typename _Traits>
155 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
156 basic_string_view<_CharT, _Traits>::
157 find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
159 gdb_assert (__str != nullptr || __n == 0);
160 for (; __pos < this->_M_len; ++__pos)
161 if (!traits_type::find(__str, __n, this->_M_str[__pos]))
166 template<typename _CharT, typename _Traits>
167 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
168 basic_string_view<_CharT, _Traits>::
169 find_first_not_of(_CharT __c, size_type __pos) const noexcept
171 for (; __pos < this->_M_len; ++__pos)
172 if (!traits_type::eq(this->_M_str[__pos], __c))
177 template<typename _CharT, typename _Traits>
178 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
179 basic_string_view<_CharT, _Traits>::
180 find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
182 gdb_assert (__str != nullptr || __n == 0);
183 size_type __size = this->_M_len;
186 if (--__size > __pos)
190 if (!traits_type::find(__str, __n, this->_M_str[__size]))
198 template<typename _CharT, typename _Traits>
199 /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
200 basic_string_view<_CharT, _Traits>::
201 find_last_not_of(_CharT __c, size_type __pos) const noexcept
203 size_type __size = this->_M_len;
206 if (--__size > __pos)
210 if (!traits_type::eq(this->_M_str[__size], __c))
219 #endif // GDB_STRING_VIEW_TCC