1 // Components for manipulating non-owning sequences of characters -*- C++ -*-
3 // Copyright (C) 2013-2017 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file experimental/bits/string_view.tcc
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{experimental/string_view}
31 // N3762 basic_string_view library
34 #ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
35 #define _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC 1
37 #pragma GCC system_header
39 #if __cplusplus <= 201103L
40 # include <bits/c++14_warning.h>
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 namespace experimental
49 inline namespace fundamentals_v1
51 template<typename _CharT, typename _Traits>
52 constexpr typename basic_string_view<_CharT, _Traits>::size_type
53 basic_string_view<_CharT, _Traits>::
54 find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
56 __glibcxx_requires_string_len(__str, __n);
59 return __pos <= this->_M_len ? __pos : npos;
61 if (__n <= this->_M_len)
63 for (; __pos <= this->_M_len - __n; ++__pos)
64 if (traits_type::eq(this->_M_str[__pos], __str[0])
65 && traits_type::compare(this->_M_str + __pos + 1,
66 __str + 1, __n - 1) == 0)
72 template<typename _CharT, typename _Traits>
73 constexpr typename basic_string_view<_CharT, _Traits>::size_type
74 basic_string_view<_CharT, _Traits>::
75 find(_CharT __c, size_type __pos) const noexcept
77 size_type __ret = npos;
78 if (__pos < this->_M_len)
80 const size_type __n = this->_M_len - __pos;
81 const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
83 __ret = __p - this->_M_str;
88 template<typename _CharT, typename _Traits>
89 constexpr typename basic_string_view<_CharT, _Traits>::size_type
90 basic_string_view<_CharT, _Traits>::
91 rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
93 __glibcxx_requires_string_len(__str, __n);
95 if (__n <= this->_M_len)
97 __pos = std::min(size_type(this->_M_len - __n), __pos);
100 if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
108 template<typename _CharT, typename _Traits>
109 constexpr typename basic_string_view<_CharT, _Traits>::size_type
110 basic_string_view<_CharT, _Traits>::
111 rfind(_CharT __c, size_type __pos) const noexcept
113 size_type __size = this->_M_len;
116 if (--__size > __pos)
118 for (++__size; __size-- > 0; )
119 if (traits_type::eq(this->_M_str[__size], __c))
125 template<typename _CharT, typename _Traits>
126 constexpr typename basic_string_view<_CharT, _Traits>::size_type
127 basic_string_view<_CharT, _Traits>::
128 find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
130 __glibcxx_requires_string_len(__str, __n);
131 for (; __n && __pos < this->_M_len; ++__pos)
133 const _CharT* __p = traits_type::find(__str, __n,
134 this->_M_str[__pos]);
141 template<typename _CharT, typename _Traits>
142 constexpr typename basic_string_view<_CharT, _Traits>::size_type
143 basic_string_view<_CharT, _Traits>::
144 find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
146 __glibcxx_requires_string_len(__str, __n);
147 size_type __size = this->size();
150 if (--__size > __pos)
154 if (traits_type::find(__str, __n, this->_M_str[__size]))
157 while (__size-- != 0);
162 template<typename _CharT, typename _Traits>
163 constexpr typename basic_string_view<_CharT, _Traits>::size_type
164 basic_string_view<_CharT, _Traits>::
165 find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
167 __glibcxx_requires_string_len(__str, __n);
168 for (; __pos < this->_M_len; ++__pos)
169 if (!traits_type::find(__str, __n, this->_M_str[__pos]))
174 template<typename _CharT, typename _Traits>
175 constexpr typename basic_string_view<_CharT, _Traits>::size_type
176 basic_string_view<_CharT, _Traits>::
177 find_first_not_of(_CharT __c, size_type __pos) const noexcept
179 for (; __pos < this->_M_len; ++__pos)
180 if (!traits_type::eq(this->_M_str[__pos], __c))
185 template<typename _CharT, typename _Traits>
186 constexpr typename basic_string_view<_CharT, _Traits>::size_type
187 basic_string_view<_CharT, _Traits>::
188 find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
190 __glibcxx_requires_string_len(__str, __n);
191 size_type __size = this->_M_len;
194 if (--__size > __pos)
198 if (!traits_type::find(__str, __n, this->_M_str[__size]))
206 template<typename _CharT, typename _Traits>
207 constexpr typename basic_string_view<_CharT, _Traits>::size_type
208 basic_string_view<_CharT, _Traits>::
209 find_last_not_of(_CharT __c, size_type __pos) const noexcept
211 size_type __size = this->_M_len;
214 if (--__size > __pos)
218 if (!traits_type::eq(this->_M_str[__size], __c))
225 } // namespace fundamentals_v1
226 } // namespace experimental
228 _GLIBCXX_END_NAMESPACE_VERSION
231 #endif // __cplusplus <= 201103L
233 #endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC