1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
// Components for manipulating non-owning sequences of characters -*- C++ -*-
// Copyright (C) 2013-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/bits/string_view.tcc
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{experimental/string_view}
*/
//
// N3762 basic_string_view library
//
#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC 1
#pragma GCC system_header
#if __cplusplus <= 201103L
# include <bits/c++14_warning.h>
#else
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace experimental
{
inline namespace fundamentals_v1
{
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
__glibcxx_requires_string_len(__str, __n);
if (__n == 0)
return __pos <= this->_M_len ? __pos : npos;
if (__n <= this->_M_len)
{
for (; __pos <= this->_M_len - __n; ++__pos)
if (traits_type::eq(this->_M_str[__pos], __str[0])
&& traits_type::compare(this->_M_str + __pos + 1,
__str + 1, __n - 1) == 0)
return __pos;
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(_CharT __c, size_type __pos) const noexcept
{
size_type __ret = npos;
if (__pos < this->_M_len)
{
const size_type __n = this->_M_len - __pos;
const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
if (__p)
__ret = __p - this->_M_str;
}
return __ret;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
__glibcxx_requires_string_len(__str, __n);
if (__n <= this->_M_len)
{
__pos = std::min(size_type(this->_M_len - __n), __pos);
do
{
if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
return __pos;
}
while (__pos-- > 0);
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(_CharT __c, size_type __pos) const noexcept
{
size_type __size = this->_M_len;
if (__size > 0)
{
if (--__size > __pos)
__size = __pos;
for (++__size; __size-- > 0; )
if (traits_type::eq(this->_M_str[__size], __c))
return __size;
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
{
__glibcxx_requires_string_len(__str, __n);
for (; __n && __pos < this->_M_len; ++__pos)
{
const _CharT* __p = traits_type::find(__str, __n,
this->_M_str[__pos]);
if (__p)
return __pos;
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
{
__glibcxx_requires_string_len(__str, __n);
size_type __size = this->size();
if (__size && __n)
{
if (--__size > __pos)
__size = __pos;
do
{
if (traits_type::find(__str, __n, this->_M_str[__size]))
return __size;
}
while (__size-- != 0);
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
__glibcxx_requires_string_len(__str, __n);
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::find(__str, __n, this->_M_str[__pos]))
return __pos;
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(_CharT __c, size_type __pos) const noexcept
{
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::eq(this->_M_str[__pos], __c))
return __pos;
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
__glibcxx_requires_string_len(__str, __n);
size_type __size = this->_M_len;
if (__size)
{
if (--__size > __pos)
__size = __pos;
do
{
if (!traits_type::find(__str, __n, this->_M_str[__size]))
return __size;
}
while (__size--);
}
return npos;
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(_CharT __c, size_type __pos) const noexcept
{
size_type __size = this->_M_len;
if (__size)
{
if (--__size > __pos)
__size = __pos;
do
{
if (!traits_type::eq(this->_M_str[__size], __c))
return __size;
}
while (__size--);
}
return npos;
}
} // namespace fundamentals_v1
} // namespace experimental
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __cplusplus <= 201103L
#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
|