ca8f2cb137
Integrating std::string_view and std::string. * include/Makefile.am: Add string_view and string_view.tcc to the exported headers. * include/Makefile.in: Likewise. * include/bits/basic_string.h: Include <string_view> in C++17 mode. (__sv_type): New. (basic_string(__sv_type, const _Alloc&)): Likewise. (operator=(__sv_type)): Likewise. (operator __sv_type()): Likewise. (operator+=(__sv_type)): Likewise. (append(__sv_type __sv)): Likewise. (append(__sv_type, size_type, size_type)): Likewise. (assign(__sv_type)): Likewise. (assign(__sv_type, size_type, size_type)): Likewise. (insert(size_type, __sv_type)): Likewise. (insert(size_type, __sv_type, size_type, size_type)): Likewise. (replace(size_type, size_type, __sv_type)): Likewise. (replace(size_type, size_type, __sv_type, size_type, size_type)): Likewise. (replace(const_iterator, const_iterator, __sv_type)): Likewise. (find(__sv_type, size_type)): Likewise. (rfind(__sv_type, size_type)): Likewise. (find_first_of(__sv_type, size_type)): Likewise. (find_last_of(__sv_type, size_type)): Likewise. (find_first_not_of(__sv_type, size_type)): Likewise. (find_last_not_of(__sv_type, size_type)): Likewise. (compare(__sv_type)): Likewise. (compare(size_type, size_type, __sv_type)): Likewise. (compare(size_type, size_type, __sv_type, size_type, size_type)): Likewise. * include/bits/string_view.tcc: New. * include/std/string_view: Likewise. * testsuite/21_strings/basic_string/cons/char/7.cc: Likewise. * testsuite/21_strings/basic_string/cons/wchar_t/7.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/append/char/4.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/assign/char/4.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/insert/char/3.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/replace/char/7.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/char/5.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc: Likewise. * testsuite/21_strings/basic_string/operators/char/5.cc: Likewise. * testsuite/21_strings/basic_string/operators/wchar_t/5.cc: Likewise. * testsuite/21_strings/basic_string_view/capacity/1.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/char/3.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/cons/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/char/empty.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/char/front_back.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/wchar_t/empty.cc: Likewise. * testsuite/21_strings/basic_string_view/element_access/wchar_t/front_back.cc: Likewise. * testsuite/21_strings/basic_string_view/include.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/char/3.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/pod/10081-out.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/inserters/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/compare/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/compare/char/13650.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/compare/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/compare/wchar_t/13650.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/copy/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/copy/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/data/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/data/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/char/4.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/find/wchar_t/4.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/char/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/string_conversion/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/substr/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/operators/char/2.cc: Likewise. * testsuite/21_strings/basic_string_view/operators/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc: Likewise. * testsuite/21_strings/basic_string_view/requirements/typedefs.cc: Likewise. * testsuite/21_strings/basic_string_view/typedefs.cc: Likewise. * testsuite/21_strings/basic_string_view/types/1.cc: Likewise. From-SVN: r238823
228 lines
6.4 KiB
C++
228 lines
6.4 KiB
C++
// Components for manipulating non-owning sequences of characters -*- C++ -*-
|
|
|
|
// Copyright (C) 2013-2016 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 bits/string_view.tcc
|
|
* This is an internal header file, included by other library headers.
|
|
* Do not attempt to use it directly. @headername{string_view}
|
|
*/
|
|
|
|
//
|
|
// N3762 basic_string_view library
|
|
//
|
|
|
|
#ifndef _GLIBCXX_STRING_VIEW_TCC
|
|
#define _GLIBCXX_STRING_VIEW_TCC 1
|
|
|
|
#pragma GCC system_header
|
|
|
|
#if __cplusplus <= 201402L
|
|
# include <bits/c++17_warning.h>
|
|
#else
|
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
{
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
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;
|
|
}
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
} // namespace std
|
|
|
|
#endif // __cplusplus <= 201402L
|
|
|
|
#endif // _GLIBCXX_STRING_VIEW_TCC
|