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 include/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{string_view}
31 // N3762 basic_string_view library
34 #ifndef _GLIBCXX_STRING_VIEW_TCC
35 #define _GLIBCXX_STRING_VIEW_TCC 1
37 #pragma GCC system_header
39 #if __cplusplus <= 201402L
40 # include <bits/c++17_warning.h>
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<typename _CharT, typename _Traits>
48 constexpr typename basic_string_view<_CharT, _Traits>::size_type
49 basic_string_view<_CharT, _Traits>::
50 find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
52 __glibcxx_requires_string_len(__str, __n);
55 return __pos <= this->_M_len ? __pos : npos;
57 if (__n <= this->_M_len)
59 for (; __pos <= this->_M_len - __n; ++__pos)
60 if (traits_type::eq(this->_M_str[__pos], __str[0])
61 && traits_type::compare(this->_M_str + __pos + 1,
62 __str + 1, __n - 1) == 0)
68 template<typename _CharT, typename _Traits>
69 constexpr typename basic_string_view<_CharT, _Traits>::size_type
70 basic_string_view<_CharT, _Traits>::
71 find(_CharT __c, size_type __pos) const noexcept
73 size_type __ret = npos;
74 if (__pos < this->_M_len)
76 const size_type __n = this->_M_len - __pos;
77 const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
79 __ret = __p - this->_M_str;
84 template<typename _CharT, typename _Traits>
85 constexpr typename basic_string_view<_CharT, _Traits>::size_type
86 basic_string_view<_CharT, _Traits>::
87 rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
89 __glibcxx_requires_string_len(__str, __n);
91 if (__n <= this->_M_len)
93 __pos = std::min(size_type(this->_M_len - __n), __pos);
96 if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
104 template<typename _CharT, typename _Traits>
105 constexpr typename basic_string_view<_CharT, _Traits>::size_type
106 basic_string_view<_CharT, _Traits>::
107 rfind(_CharT __c, size_type __pos) const noexcept
109 size_type __size = this->_M_len;
112 if (--__size > __pos)
114 for (++__size; __size-- > 0; )
115 if (traits_type::eq(this->_M_str[__size], __c))
121 template<typename _CharT, typename _Traits>
122 constexpr typename basic_string_view<_CharT, _Traits>::size_type
123 basic_string_view<_CharT, _Traits>::
124 find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
126 __glibcxx_requires_string_len(__str, __n);
127 for (; __n && __pos < this->_M_len; ++__pos)
129 const _CharT* __p = traits_type::find(__str, __n,
130 this->_M_str[__pos]);
137 template<typename _CharT, typename _Traits>
138 constexpr typename basic_string_view<_CharT, _Traits>::size_type
139 basic_string_view<_CharT, _Traits>::
140 find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
142 __glibcxx_requires_string_len(__str, __n);
143 size_type __size = this->size();
146 if (--__size > __pos)
150 if (traits_type::find(__str, __n, this->_M_str[__size]))
153 while (__size-- != 0);
158 template<typename _CharT, typename _Traits>
159 constexpr typename basic_string_view<_CharT, _Traits>::size_type
160 basic_string_view<_CharT, _Traits>::
161 find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
163 __glibcxx_requires_string_len(__str, __n);
164 for (; __pos < this->_M_len; ++__pos)
165 if (!traits_type::find(__str, __n, this->_M_str[__pos]))
170 template<typename _CharT, typename _Traits>
171 constexpr typename basic_string_view<_CharT, _Traits>::size_type
172 basic_string_view<_CharT, _Traits>::
173 find_first_not_of(_CharT __c, size_type __pos) const noexcept
175 for (; __pos < this->_M_len; ++__pos)
176 if (!traits_type::eq(this->_M_str[__pos], __c))
181 template<typename _CharT, typename _Traits>
182 constexpr typename basic_string_view<_CharT, _Traits>::size_type
183 basic_string_view<_CharT, _Traits>::
184 find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
186 __glibcxx_requires_string_len(__str, __n);
187 size_type __size = this->_M_len;
190 if (--__size > __pos)
194 if (!traits_type::find(__str, __n, this->_M_str[__size]))
202 template<typename _CharT, typename _Traits>
203 constexpr typename basic_string_view<_CharT, _Traits>::size_type
204 basic_string_view<_CharT, _Traits>::
205 find_last_not_of(_CharT __c, size_type __pos) const noexcept
207 size_type __size = this->_M_len;
210 if (--__size > __pos)
214 if (!traits_type::eq(this->_M_str[__size], __c))
222 _GLIBCXX_END_NAMESPACE_VERSION
225 #endif // __cplusplus <= 201402L
227 #endif // _GLIBCXX_STRING_VIEW_TCC