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
|
* include/bits/stl_deque.h (_M_new_elements_at_front): Use
|
||||||
__throw_exception_again.
|
__throw_exception_again.
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
|
|
||||||
// Documentation? What's that?
|
// Documentation? What's that?
|
||||||
// Nathan Myers <ncm@cantrip.org>.
|
// Nathan Myers <ncm@cantrip.org>.
|
||||||
//
|
//
|
||||||
|
@ -284,7 +283,7 @@ namespace std
|
||||||
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
|
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
|
||||||
{
|
{
|
||||||
for (; __k1 != __k2; ++__k1, ++__p)
|
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
|
static void
|
||||||
|
@ -337,7 +336,7 @@ namespace std
|
||||||
basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
|
basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
|
||||||
|
|
||||||
template<class _InputIterator>
|
template<class _InputIterator>
|
||||||
basic_string(_InputIterator __begin, _InputIterator __end,
|
basic_string(_InputIterator __beg, _InputIterator __end,
|
||||||
const _Alloc& __a = _Alloc());
|
const _Alloc& __a = _Alloc());
|
||||||
|
|
||||||
~basic_string()
|
~basic_string()
|
||||||
|
|
|
@ -446,17 +446,23 @@ namespace std
|
||||||
_M_replace(iterator __i1, iterator __i2, _ForwardIter __k1,
|
_M_replace(iterator __i1, iterator __i2, _ForwardIter __k1,
|
||||||
_ForwardIter __k2, forward_iterator_tag)
|
_ForwardIter __k2, forward_iterator_tag)
|
||||||
{
|
{
|
||||||
|
size_type __dnew = static_cast<size_type>(distance(__k1, __k2));
|
||||||
size_type __dold = __i2 - __i1;
|
size_type __dold = __i2 - __i1;
|
||||||
size_type __dmax = this->max_size();
|
size_type __dmax = this->max_size();
|
||||||
size_type __dnew = static_cast<size_type>(distance(__k1, __k2));
|
|
||||||
|
|
||||||
if (__dmax <= __dnew)
|
if (__dmax <= __dnew)
|
||||||
__throw_length_error("basic_string::_M_replace");
|
__throw_length_error("basic_string::_M_replace");
|
||||||
size_type __off = __i1 - _M_ibegin();
|
size_type __off = __i1 - _M_ibegin();
|
||||||
|
|
||||||
|
// Save concerned source string data in a temporary.
|
||||||
|
basic_string __temp(__k1, __k2);
|
||||||
_M_mutate(__off, __dold, __dnew);
|
_M_mutate(__off, __dold, __dnew);
|
||||||
// Invalidated __i1, __i2
|
|
||||||
|
// Invalidated __i1, __i2 (and clobbered original source string
|
||||||
|
// data when destination string == source string and the string
|
||||||
|
// is unshared).
|
||||||
if (__dnew)
|
if (__dnew)
|
||||||
_S_copy_chars(_M_data() + __off, __k1, __k2);
|
_S_copy_chars(_M_data() + __off, __temp.begin(), __temp.end());
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,22 +56,6 @@ namespace std
|
||||||
// Only one template keyword allowed here.
|
// Only one template keyword allowed here.
|
||||||
// See core issue #46 (NAD)
|
// See core issue #46 (NAD)
|
||||||
// http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#46
|
// 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
|
template
|
||||||
S::basic_string(C*, C*, const allocator<C>&);
|
S::basic_string(C*, C*, const allocator<C>&);
|
||||||
|
|
||||||
|
@ -81,6 +65,19 @@ namespace std
|
||||||
template
|
template
|
||||||
S::basic_string(S::iterator, S::iterator, const allocator<C>&);
|
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
|
template
|
||||||
S&
|
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);
|
||||||
|
@ -92,12 +89,21 @@ namespace std
|
||||||
|
|
||||||
template
|
template
|
||||||
C*
|
C*
|
||||||
S::_S_construct(const C*, const C*, const allocator<C>&,
|
S::_S_construct(S::iterator, S::iterator,
|
||||||
forward_iterator_tag);
|
const allocator<C>&, forward_iterator_tag);
|
||||||
|
|
||||||
template
|
template
|
||||||
C*
|
C*
|
||||||
S::_S_construct (C*, C*, const allocator<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);
|
||||||
|
|
||||||
|
template
|
||||||
|
C*
|
||||||
|
S::_S_construct(const C*, const C*, const allocator<C>&,
|
||||||
forward_iterator_tag);
|
forward_iterator_tag);
|
||||||
|
|
||||||
template
|
template
|
||||||
|
|
|
@ -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>
|
// template<typename InputIter>
|
||||||
// string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2)
|
// string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2)
|
||||||
|
|
||||||
#if 1
|
|
||||||
// with mods, from tstring.cc, from jason merrill, et. al.
|
// with mods, from tstring.cc, from jason merrill, et. al.
|
||||||
std::string X = "Hello";
|
std::string X = "Hello";
|
||||||
std::string x = X;
|
std::string x = X;
|
||||||
|
@ -75,7 +74,6 @@ bool test01(void)
|
||||||
std::find(x.rbegin(), x.rend(), 'l').base(), ar,
|
std::find(x.rbegin(), x.rend(), 'l').base(), ar,
|
||||||
ar + sizeof(ar) / sizeof(ar[0]));
|
ar + sizeof(ar) / sizeof(ar[0]));
|
||||||
VERIFY( x == "jeHelloo" );
|
VERIFY( x == "jeHelloo" );
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG_ASSERT
|
#ifdef DEBUG_ASSERT
|
||||||
assert(test);
|
assert(test);
|
||||||
|
@ -83,8 +81,24 @@ bool test01(void)
|
||||||
return test;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
test01();
|
test01();
|
||||||
|
test02();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue