basic_string.h: Tweaks.
2001-10-30 Paolo Carlini <pcarlini@unitus.it> Benjamin Kosnik <bkoz@redhat.com> * include/bits/basic_string.h: Tweaks. * include/bits/basic_string.tcc (string::_M_replace(iterator, iterator, _ForwardIter, _ForwardIter, forward_iterator_tag): Fix. * src/string-inst.cc: Tweaks, add instantiation. * testsuite/21_strings/replace.cc (test02): Add test. * testsuite/21_strings/assign.cc (test01): New file. 0 Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com> From-SVN: r46674
This commit is contained in:
parent
8f32f3ab9c
commit
9a304d1766
@ -1,4 +1,14 @@
|
||||
2001-10-30 Jakub Jelinek <jakub@redhat.com>
|
||||
2001-10-30 Paolo Carlini <pcarlini@unitus.it>
|
||||
Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* include/bits/basic_string.h: Tweaks.
|
||||
* include/bits/basic_string.tcc (string::_M_replace(iterator,
|
||||
iterator, _ForwardIter, _ForwardIter, forward_iterator_tag): Fix.
|
||||
* src/string-inst.cc: Tweaks, add instantiation.
|
||||
* testsuite/21_strings/replace.cc (test02): Add test.
|
||||
* testsuite/21_strings/assign.cc (test01): New file.
|
||||
|
||||
001-10-30 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* include/bits/stl_deque.h (_M_new_elements_at_front): Use
|
||||
__throw_exception_again.
|
||||
|
@ -40,7 +40,6 @@
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
// Documentation? What's that?
|
||||
// Nathan Myers <ncm@cantrip.org>.
|
||||
//
|
||||
@ -284,7 +283,7 @@ namespace std
|
||||
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
|
||||
{
|
||||
for (; __k1 != __k2; ++__k1, ++__p)
|
||||
traits_type::assign(*__p, *__k1); //these types are off
|
||||
traits_type::assign(*__p, *__k1); // These types are off.
|
||||
}
|
||||
|
||||
static void
|
||||
@ -337,7 +336,7 @@ namespace std
|
||||
basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
|
||||
|
||||
template<class _InputIterator>
|
||||
basic_string(_InputIterator __begin, _InputIterator __end,
|
||||
basic_string(_InputIterator __beg, _InputIterator __end,
|
||||
const _Alloc& __a = _Alloc());
|
||||
|
||||
~basic_string()
|
||||
|
@ -130,7 +130,7 @@ namespace std
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
template <class _InIter>
|
||||
_CharT*
|
||||
basic_string<_CharT,_Traits,_Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
|
||||
forward_iterator_tag)
|
||||
{
|
||||
@ -156,7 +156,7 @@ namespace std
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
_CharT*
|
||||
basic_string<_CharT,_Traits, _Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
_S_construct(size_type __n, _CharT __c, const _Alloc& __a)
|
||||
{
|
||||
if (__n == 0 && __a == _Alloc())
|
||||
@ -446,18 +446,24 @@ namespace std
|
||||
_M_replace(iterator __i1, iterator __i2, _ForwardIter __k1,
|
||||
_ForwardIter __k2, forward_iterator_tag)
|
||||
{
|
||||
size_type __dnew = static_cast<size_type>(distance(__k1, __k2));
|
||||
size_type __dold = __i2 - __i1;
|
||||
size_type __dmax = this->max_size();
|
||||
size_type __dnew = static_cast<size_type>(distance(__k1, __k2));
|
||||
|
||||
if (__dmax <= __dnew)
|
||||
__throw_length_error("basic_string::_M_replace");
|
||||
size_type __off = __i1 - _M_ibegin();
|
||||
|
||||
// Save concerned source string data in a temporary.
|
||||
basic_string __temp(__k1, __k2);
|
||||
_M_mutate(__off, __dold, __dnew);
|
||||
// Invalidated __i1, __i2
|
||||
if (__dnew)
|
||||
_S_copy_chars(_M_data() + __off, __k1, __k2);
|
||||
|
||||
// Invalidated __i1, __i2 (and clobbered original source string
|
||||
// data when destination string == source string and the string
|
||||
// is unshared).
|
||||
if (__dnew)
|
||||
_S_copy_chars(_M_data() + __off, __temp.begin(), __temp.end());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -473,8 +479,8 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>&
|
||||
basic_string<_CharT,_Traits,_Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>&
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
append(const basic_string& __str)
|
||||
{
|
||||
// Iff appending itself, string needs to pre-reserve the
|
||||
@ -489,8 +495,8 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>&
|
||||
basic_string<_CharT,_Traits,_Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>&
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
append(const basic_string& __str, size_type __pos, size_type __n)
|
||||
{
|
||||
// Iff appending itself, string needs to pre-reserve the
|
||||
@ -504,8 +510,8 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>&
|
||||
basic_string<_CharT,_Traits,_Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>&
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
append(const _CharT* __s, size_type __n)
|
||||
{
|
||||
size_type __len = __n + this->size();
|
||||
@ -515,8 +521,8 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>&
|
||||
basic_string<_CharT,_Traits,_Alloc>::
|
||||
basic_string<_CharT, _Traits, _Alloc>&
|
||||
basic_string<_CharT, _Traits, _Alloc>::
|
||||
append(size_type __n, _CharT __c)
|
||||
{
|
||||
size_type __len = __n + this->size();
|
||||
@ -526,11 +532,11 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>
|
||||
basic_string<_CharT, _Traits, _Alloc>
|
||||
operator+(const _CharT* __lhs,
|
||||
const basic_string<_CharT,_Traits,_Alloc>& __rhs)
|
||||
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
|
||||
{
|
||||
typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
|
||||
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
|
||||
typedef typename __string_type::size_type __size_type;
|
||||
__size_type __len = _Traits::length(__lhs);
|
||||
__string_type __str;
|
||||
@ -541,10 +547,10 @@ namespace std
|
||||
}
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
basic_string<_CharT,_Traits,_Alloc>
|
||||
operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
|
||||
basic_string<_CharT, _Traits, _Alloc>
|
||||
operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
|
||||
{
|
||||
typedef basic_string<_CharT,_Traits,_Alloc> __string_type;
|
||||
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
|
||||
typedef typename __string_type::size_type __size_type;
|
||||
__string_type __str;
|
||||
__size_type __len = __rhs.size();
|
||||
@ -627,7 +633,7 @@ namespace std
|
||||
size_type __size = this->size();
|
||||
if (__n <= __size)
|
||||
{
|
||||
__pos = std::min(__size - __n ,__pos);
|
||||
__pos = std::min(__size - __n, __pos);
|
||||
const _CharT* __data = _M_data();
|
||||
do
|
||||
{
|
||||
@ -811,7 +817,7 @@ namespace std
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
int
|
||||
basic_string <_CharT,_Traits,_Alloc>::
|
||||
basic_string <_CharT, _Traits, _Alloc>::
|
||||
compare(size_type __pos, size_type __n1, const _CharT* __s) const
|
||||
{
|
||||
size_type __size = this->size();
|
||||
@ -829,7 +835,7 @@ namespace std
|
||||
|
||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||
int
|
||||
basic_string <_CharT,_Traits,_Alloc>::
|
||||
basic_string <_CharT, _Traits, _Alloc>::
|
||||
compare(size_type __pos, size_type __n1, const _CharT* __s,
|
||||
size_type __n2) const
|
||||
{
|
||||
|
@ -56,22 +56,6 @@ namespace std
|
||||
// Only one template keyword allowed here.
|
||||
// See core issue #46 (NAD)
|
||||
// http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#46
|
||||
template
|
||||
S&
|
||||
S::_M_replace<S::iterator>
|
||||
(S::iterator, S::iterator, S::iterator, S::iterator, forward_iterator_tag);
|
||||
|
||||
template
|
||||
S&
|
||||
S::_M_replace<S::const_iterator>
|
||||
(S::iterator, S::iterator,
|
||||
S::const_iterator, S::const_iterator, forward_iterator_tag);
|
||||
|
||||
template
|
||||
C*
|
||||
S::_S_construct<S::iterator>
|
||||
(S::iterator, S::iterator, const allocator<C>&, forward_iterator_tag);
|
||||
|
||||
template
|
||||
S::basic_string(C*, C*, const allocator<C>&);
|
||||
|
||||
@ -81,24 +65,46 @@ namespace std
|
||||
template
|
||||
S::basic_string(S::iterator, S::iterator, const allocator<C>&);
|
||||
|
||||
template
|
||||
S::basic_string(S::const_iterator, S::const_iterator, const allocator<C>&);
|
||||
|
||||
template
|
||||
S&
|
||||
S::_M_replace(S::iterator, S::iterator, S::iterator, S::iterator,
|
||||
forward_iterator_tag);
|
||||
|
||||
template
|
||||
S&
|
||||
S::_M_replace(S::iterator, S::iterator, S::const_iterator,
|
||||
S::const_iterator, forward_iterator_tag);
|
||||
|
||||
template
|
||||
S&
|
||||
S::_M_replace(S::iterator, S::iterator, C*, C*, forward_iterator_tag);
|
||||
S::_M_replace(S::iterator, S::iterator, C*, C*, forward_iterator_tag);
|
||||
|
||||
template
|
||||
S&
|
||||
S::_M_replace(S::iterator, S::iterator, const C*, const C*,
|
||||
forward_iterator_tag);
|
||||
|
||||
template
|
||||
C*
|
||||
S::_S_construct(const C*, const C*, const allocator<C>&,
|
||||
forward_iterator_tag);
|
||||
template
|
||||
C*
|
||||
S::_S_construct(S::iterator, S::iterator,
|
||||
const allocator<C>&, forward_iterator_tag);
|
||||
|
||||
template
|
||||
C*
|
||||
S::_S_construct(S::const_iterator, S::const_iterator,
|
||||
const allocator<C>&, forward_iterator_tag);
|
||||
|
||||
template
|
||||
C*
|
||||
S::_S_construct (C*, C*, const allocator<C>&,
|
||||
forward_iterator_tag);
|
||||
S::_S_construct(C*, C*, const allocator<C>&, forward_iterator_tag);
|
||||
|
||||
template
|
||||
C*
|
||||
S::_S_construct(const C*, const C*, const allocator<C>&,
|
||||
forward_iterator_tag);
|
||||
|
||||
template
|
||||
void
|
||||
|
46
libstdc++-v3/testsuite/21_strings/assign.cc
Normal file
46
libstdc++-v3/testsuite/21_strings/assign.cc
Normal file
@ -0,0 +1,46 @@
|
||||
// 2001-10-30 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
// Copyright (C) 2001 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 2, 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.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 21.3.5 string modifiers
|
||||
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
bool test = true;
|
||||
|
||||
using namespace std;
|
||||
|
||||
const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii";
|
||||
string aux = strlit;
|
||||
string::size_type i = aux.rfind("/");
|
||||
if (i != string::npos)
|
||||
aux.assign(aux, i + 1, string::npos);
|
||||
VERIFY(aux == "Hawaii");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -52,7 +52,6 @@ bool test01(void)
|
||||
// template<typename InputIter>
|
||||
// string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2)
|
||||
|
||||
#if 1
|
||||
// with mods, from tstring.cc, from jason merrill, et. al.
|
||||
std::string X = "Hello";
|
||||
std::string x = X;
|
||||
@ -75,7 +74,6 @@ bool test01(void)
|
||||
std::find(x.rbegin(), x.rend(), 'l').base(), ar,
|
||||
ar + sizeof(ar) / sizeof(ar[0]));
|
||||
VERIFY( x == "jeHelloo" );
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ASSERT
|
||||
assert(test);
|
||||
@ -83,8 +81,24 @@ bool test01(void)
|
||||
return test;
|
||||
}
|
||||
|
||||
void
|
||||
test02()
|
||||
{
|
||||
const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii";
|
||||
std::string aux = strlit;
|
||||
aux.replace(aux.begin()+5, aux.begin()+20,
|
||||
aux.begin()+10, aux.begin()+15);
|
||||
VERIFY(aux == "../thg piealei Bay/Kauai/Hawaii");
|
||||
|
||||
aux = strlit;
|
||||
aux.replace(aux.begin() + 10, aux.begin() + 15,
|
||||
aux.begin() + 5, aux.begin() + 20);
|
||||
VERIFY(aux == "../the lone long pier/Hanr/Hanalei Bay/Kauai/Hawaii");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user