1 // Components for manipulating non-owning sequences of characters -*- C++ -*-
3 // Copyright (C) 2013-2014 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/string_view.tcc
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{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 namespace experimental
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<typename _CharT, typename _Traits>
50 typename basic_string_view<_CharT, _Traits>::size_type
51 basic_string_view<_CharT, _Traits>::
52 find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
54 __glibcxx_requires_string_len(__str, __n);
57 return __pos <= this->_M_len ? __pos : npos;
59 if (__n <= this->_M_len)
61 for (; __pos <= this->_M_len - __n; ++__pos)
62 if (traits_type::eq(this->_M_str[__pos], __str[0])
63 && traits_type::compare(this->_M_str + __pos + 1,
64 __str + 1, __n - 1) == 0)
70 template<typename _CharT, typename _Traits>
71 typename basic_string_view<_CharT, _Traits>::size_type
72 basic_string_view<_CharT, _Traits>::
73 find(_CharT __c, size_type __pos) const noexcept
75 size_type __ret = npos;
76 if (__pos < this->_M_len)
78 const size_type __n = this->_M_len - __pos;
79 const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
81 __ret = __p - this->_M_str;
86 template<typename _CharT, typename _Traits>
87 typename basic_string_view<_CharT, _Traits>::size_type
88 basic_string_view<_CharT, _Traits>::
89 rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
91 __glibcxx_requires_string_len(__str, __n);
93 if (__n <= this->_M_len)
95 __pos = std::min(size_type(this->_M_len - __n), __pos);
98 if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
106 template<typename _CharT, typename _Traits>
107 typename basic_string_view<_CharT, _Traits>::size_type
108 basic_string_view<_CharT, _Traits>::
109 rfind(_CharT __c, size_type __pos) const noexcept
111 size_type __size = this->_M_len;
114 if (--__size > __pos)
116 for (++__size; __size-- > 0; )
117 if (traits_type::eq(this->_M_str[__size], __c))
123 template<typename _CharT, typename _Traits>
124 typename basic_string_view<_CharT, _Traits>::size_type
125 basic_string_view<_CharT, _Traits>::
126 find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
128 __glibcxx_requires_string_len(__str, __n);
129 for (; __n && __pos < this->_M_len; ++__pos)
131 const _CharT* __p = traits_type::find(__str, __n,
132 this->_M_str[__pos]);
139 template<typename _CharT, typename _Traits>
140 typename basic_string_view<_CharT, _Traits>::size_type
141 basic_string_view<_CharT, _Traits>::
142 find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
144 __glibcxx_requires_string_len(__str, __n);
145 size_type __size = this->size();
148 if (--__size > __pos)
152 if (traits_type::find(__str, __n, this->_M_str[__size]))
155 while (__size-- != 0);
160 template<typename _CharT, typename _Traits>
161 typename basic_string_view<_CharT, _Traits>::size_type
162 basic_string_view<_CharT, _Traits>::
163 find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
165 __glibcxx_requires_string_len(__str, __n);
166 for (; __pos < this->_M_len; ++__pos)
167 if (!traits_type::find(__str, __n, this->_M_str[__pos]))
172 template<typename _CharT, typename _Traits>
173 typename basic_string_view<_CharT, _Traits>::size_type
174 basic_string_view<_CharT, _Traits>::
175 find_first_not_of(_CharT __c, size_type __pos) const noexcept
177 for (; __pos < this->_M_len; ++__pos)
178 if (!traits_type::eq(this->_M_str[__pos], __c))
183 template<typename _CharT, typename _Traits>
184 typename basic_string_view<_CharT, _Traits>::size_type
185 basic_string_view<_CharT, _Traits>::
186 find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
188 __glibcxx_requires_string_len(__str, __n);
189 size_type __size = this->_M_len;
192 if (--__size > __pos)
196 if (!traits_type::find(__str, __n, this->_M_str[__size]))
204 template<typename _CharT, typename _Traits>
205 typename basic_string_view<_CharT, _Traits>::size_type
206 basic_string_view<_CharT, _Traits>::
207 find_last_not_of(_CharT __c, size_type __pos) const noexcept
209 size_type __size = this->_M_len;
212 if (--__size > __pos)
216 if (!traits_type::eq(this->_M_str[__size], __c))
224 _GLIBCXX_END_NAMESPACE_VERSION
225 } // namespace experimental
228 #endif // __cplusplus <= 201103L
230 #endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC