1 // Components for manipulating non-owning sequences of characters -*- C++ -*-
3 // Copyright (C) 2013 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>
51 basic_string_view<_CharT, _Traits>::_S_empty_str[1];
53 template<typename _CharT, typename _Traits>
54 typename basic_string_view<_CharT, _Traits>::size_type
55 basic_string_view<_CharT, _Traits>::
56 find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
58 __glibcxx_requires_string_len(__str, __n);
61 return __pos <= this->_M_len ? __pos : npos;
63 if (__n <= this->_M_len)
65 for (; __pos <= this->_M_len - __n; ++__pos)
66 if (traits_type::eq(this->_M_str[__pos], __str[0])
67 && traits_type::compare(this->_M_str + __pos + 1,
68 __str + 1, __n - 1) == 0)
74 template<typename _CharT, typename _Traits>
75 typename basic_string_view<_CharT, _Traits>::size_type
76 basic_string_view<_CharT, _Traits>::
77 find(_CharT __c, size_type __pos) const noexcept
79 size_type __ret = npos;
80 if (__pos < this->_M_len)
82 const size_type __n = this->_M_len - __pos;
83 const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
85 __ret = __p - this->_M_str;
90 template<typename _CharT, typename _Traits>
91 typename basic_string_view<_CharT, _Traits>::size_type
92 basic_string_view<_CharT, _Traits>::
93 rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
95 __glibcxx_requires_string_len(__str, __n);
97 if (__n <= this->_M_len)
99 __pos = std::min(size_type(this->_M_len - __n), __pos);
102 if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
110 template<typename _CharT, typename _Traits>
111 typename basic_string_view<_CharT, _Traits>::size_type
112 basic_string_view<_CharT, _Traits>::
113 rfind(_CharT __c, size_type __pos) const noexcept
115 size_type __size = this->_M_len;
118 if (--__size > __pos)
120 for (++__size; __size-- > 0; )
121 if (traits_type::eq(this->_M_str[__size], __c))
127 template<typename _CharT, typename _Traits>
128 typename basic_string_view<_CharT, _Traits>::size_type
129 basic_string_view<_CharT, _Traits>::
130 find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
132 __glibcxx_requires_string_len(__str, __n);
133 for (; __n && __pos < this->_M_len; ++__pos)
135 const _CharT* __p = traits_type::find(__str, __n,
136 this->_M_str[__pos]);
143 template<typename _CharT, typename _Traits>
144 typename basic_string_view<_CharT, _Traits>::size_type
145 basic_string_view<_CharT, _Traits>::
146 find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
148 __glibcxx_requires_string_len(__str, __n);
149 size_type __size = this->size();
152 if (--__size > __pos)
156 if (traits_type::find(__str, __n, this->_M_str[__size]))
159 while (__size-- != 0);
164 template<typename _CharT, typename _Traits>
165 typename basic_string_view<_CharT, _Traits>::size_type
166 basic_string_view<_CharT, _Traits>::
167 find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
169 __glibcxx_requires_string_len(__str, __n);
170 for (; __pos < this->_M_len; ++__pos)
171 if (!traits_type::find(__str, __n, this->_M_str[__pos]))
176 template<typename _CharT, typename _Traits>
177 typename basic_string_view<_CharT, _Traits>::size_type
178 basic_string_view<_CharT, _Traits>::
179 find_first_not_of(_CharT __c, size_type __pos) const noexcept
181 for (; __pos < this->_M_len; ++__pos)
182 if (!traits_type::eq(this->_M_str[__pos], __c))
187 template<typename _CharT, typename _Traits>
188 typename basic_string_view<_CharT, _Traits>::size_type
189 basic_string_view<_CharT, _Traits>::
190 find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
192 __glibcxx_requires_string_len(__str, __n);
193 size_type __size = this->_M_len;
196 if (--__size > __pos)
200 if (!traits_type::find(__str, __n, this->_M_str[__size]))
208 template<typename _CharT, typename _Traits>
209 typename basic_string_view<_CharT, _Traits>::size_type
210 basic_string_view<_CharT, _Traits>::
211 find_last_not_of(_CharT __c, size_type __pos) const noexcept
213 size_type __size = this->_M_len;
216 if (--__size > __pos)
220 if (!traits_type::eq(this->_M_str[__size], __c))
228 _GLIBCXX_END_NAMESPACE_VERSION
229 } // namespace experimental
232 #endif // __cplusplus <= 201103L
234 #endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC