2000-10-05 13:27:02 +02:00
|
|
|
// Components for manipulating sequences of characters -*- C++ -*-
|
|
|
|
|
2003-02-13 22:39:03 +01:00
|
|
|
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
2002-01-14 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
* include/bits/basic_string.h
(replace(__pos, __n1, __s, __n2)): Optimize by avoiding
temporaries (i.e., call _M_replace_safe) when possible.
(replace(__pos, __n, __str)): Call replace(__pos, __n1, __s, __n2).
(replace(__pos, __n1, __s)): Call replace(__pos, __n1, __s , __n2).
(replace(__i1, __i2, __str)): Call replace(__i1, __i2, __s, __n).
(replace(__i1, __i2, __s)): Call replace(__i1, __i2, __s, __n).
(replace(__i1, __i2, __s, __n)): Call replace(__pos1, __n1, __s, __n2).
* include/bits/basic_string.tcc
(replace(__pos1, __n1, __str, __pos2, __n2)): Call
replace(__pos, __n1, __s, __n2).
* testsuite/21_strings/replace.cc (test03): New testcases.
* include/bits/basic_string.h (insert(__pos, __s, __n)):
Adjust comparison wrt overflow.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r48834
2002-01-14 20:04:15 +01:00
|
|
|
// Free Software Foundation, Inc.
|
2000-10-05 13:27:02 +02:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// As a special exception, you may use this file as part of a free software
|
|
|
|
// library without restriction. Specifically, if other files instantiate
|
|
|
|
// templates or use macros or inline functions from this file, or you compile
|
|
|
|
// this file and link it with other files to produce an executable, this
|
|
|
|
// file does not by itself cause the resulting executable to be covered by
|
|
|
|
// the GNU General Public License. This exception does not however
|
|
|
|
// invalidate any other reasons why the executable file might be covered by
|
|
|
|
// the GNU General Public License.
|
|
|
|
|
|
|
|
//
|
|
|
|
// ISO C++ 14882: 21 Strings library
|
|
|
|
//
|
|
|
|
|
|
|
|
// This file is included by <string>. It is not meant to be included
|
|
|
|
// separately.
|
|
|
|
|
|
|
|
// Written by Jason Merrill based upon the specification by Takanori Adachi
|
|
|
|
// in ANSI X3J16/94-0013R2. Rewritten by Nathan Myers to ISO-14882.
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifndef _BASIC_STRING_TCC
|
|
|
|
#define _BASIC_STRING_TCC 1
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2002-02-16 20:33:43 +01:00
|
|
|
#pragma GCC system_header
|
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2002-02-12 05:35:58 +01:00
|
|
|
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
_Rep::_S_max_size = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4;
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2002-02-12 05:35:58 +01:00
|
|
|
const _CharT
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2002-02-12 05:35:58 +01:00
|
|
|
_Rep::_S_terminal = _CharT();
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2000-11-16 02:03:20 +01:00
|
|
|
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::npos;
|
|
|
|
|
|
|
|
// Linker sets _S_empty_rep_storage to all 0s (one reference, empty string)
|
|
|
|
// at static init time (before static ctors are run).
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2000-11-16 02:03:20 +01:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
|
|
|
|
(sizeof(_Rep_base) + sizeof(_CharT) + sizeof(size_type) - 1) /
|
|
|
|
sizeof(size_type)];
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
// NB: This is the special case for Input Iterators, used in
|
|
|
|
// istreambuf_iterators, etc.
|
|
|
|
// Input Iterators have a cost structure very different from
|
|
|
|
// pointers, calling for a different coding style.
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
template<typename _InIterator>
|
2000-10-05 13:27:02 +02:00
|
|
|
_CharT*
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
_S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
|
2000-10-05 13:27:02 +02:00
|
|
|
input_iterator_tag)
|
|
|
|
{
|
|
|
|
if (__beg == __end && __a == _Alloc())
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
return _S_empty_rep()._M_refdata();
|
2000-10-05 13:27:02 +02:00
|
|
|
// Avoid reallocation for common case.
|
|
|
|
_CharT __buf[100];
|
|
|
|
size_type __i = 0;
|
|
|
|
while (__beg != __end && __i < sizeof(__buf) / sizeof(_CharT))
|
|
|
|
{
|
|
|
|
__buf[__i++] = *__beg;
|
|
|
|
++__beg;
|
|
|
|
}
|
|
|
|
_Rep* __r = _Rep::_S_create(__i, __a);
|
|
|
|
traits_type::copy(__r->_M_refdata(), __buf, __i);
|
|
|
|
__r->_M_length = __i;
|
2001-02-16 01:44:44 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// NB: this loop looks precisely this way because
|
|
|
|
// it avoids comparing __beg != __end any more
|
|
|
|
// than strictly necessary; != might be expensive!
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
_CharT* __p = __r->_M_refdata() + __r->_M_length;
|
|
|
|
_CharT* __last = __r->_M_refdata() + __r->_M_capacity;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (__beg == __end)
|
|
|
|
{
|
|
|
|
__r->_M_length = __p - __r->_M_refdata();
|
|
|
|
*__p = _Rep::_S_terminal; // grrr.
|
|
|
|
return __r->_M_refdata();
|
|
|
|
}
|
|
|
|
if (__p == __last)
|
|
|
|
break;
|
|
|
|
*__p++ = *__beg;
|
|
|
|
++__beg;
|
|
|
|
}
|
|
|
|
// Allocate more space.
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __len = __p - __r->_M_refdata();
|
2001-02-16 01:44:44 +01:00
|
|
|
_Rep* __another = _Rep::_S_create(__len + 1, __a);
|
|
|
|
traits_type::copy(__another->_M_refdata(),
|
|
|
|
__r->_M_refdata(), __len);
|
|
|
|
__r->_M_destroy(__a);
|
|
|
|
__r = __another;
|
|
|
|
__r->_M_length = __len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
2000-10-05 13:27:02 +02:00
|
|
|
__r->_M_destroy(__a);
|
2001-02-16 01:44:44 +01:00
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2001-02-16 01:44:44 +01:00
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
template <class _InIterator>
|
2000-10-05 13:27:02 +02:00
|
|
|
_CharT*
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
_S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
|
2000-10-05 13:27:02 +02:00
|
|
|
forward_iterator_tag)
|
|
|
|
{
|
2002-10-27 08:35:06 +01:00
|
|
|
if (__beg == __end && __a == _Alloc())
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
return _S_empty_rep()._M_refdata();
|
2002-10-27 08:35:06 +01:00
|
|
|
|
2002-03-12 23:10:34 +01:00
|
|
|
// NB: Not required, but considered best practice.
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
if (__builtin_expect(__beg == _InIterator(), 0))
|
2003-04-29 01:05:57 +02:00
|
|
|
__throw_logic_error("basic_string::_S_construct NULL not valid");
|
basic_string.tcc (basic_string::append(const basic_string&, size_type, size_type), [...]): Fully qualify min() with std::.
2002-12-02 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.tcc
(basic_string::append(const basic_string&, size_type,
size_type), basic_string::compare(size_type, size_type,
const basic_string&), basic_string::compare(size_type,
size_type, const basic_string&, size_type, size_type),
basic_string::compare(const _CharT*), basic_string::
compare(size_type, size_type, const _CharT*),
basic_string::compare(size_type, size_type, const _CharT*,
size_type), _S_string_copy(const basic_string&, _CharT*,
typename _Alloc::size_type)): Fully qualify min() with std::.
2002-12-02 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.tcc
(basic_string::_S_construct(_InIter, _InIter, const _Alloc&,
forward_iterator_tag)): Delay the declaration of __dnew,
fully qualify distance() with std::.
(basic_string::_M_replace_safe): Fully qualify distance()
with std::.
From-SVN: r59726
2002-12-02 19:53:41 +01:00
|
|
|
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __dnew = static_cast<size_type>(std::distance(__beg, __end));
|
2002-03-12 23:10:34 +01:00
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
// Check for out_of_range and length_error exceptions.
|
|
|
|
_Rep* __r = _Rep::_S_create(__dnew, __a);
|
2001-02-16 01:44:44 +01:00
|
|
|
try
|
|
|
|
{ _S_copy_chars(__r->_M_refdata(), __beg, __end); }
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
__r->_M_destroy(__a);
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
__r->_M_length = __dnew;
|
|
|
|
|
|
|
|
__r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr.
|
|
|
|
return __r->_M_refdata();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
_CharT*
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
_S_construct(size_type __n, _CharT __c, const _Alloc& __a)
|
|
|
|
{
|
|
|
|
if (__n == 0 && __a == _Alloc())
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
return _S_empty_rep()._M_refdata();
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
// Check for out_of_range and length_error exceptions.
|
|
|
|
_Rep* __r = _Rep::_S_create(__n, __a);
|
2001-02-16 01:44:44 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (__n)
|
|
|
|
traits_type::assign(__r->_M_refdata(), __n, __c);
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
__r->_M_destroy(__a);
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
__r->_M_length = __n;
|
|
|
|
__r->_M_refdata()[__n] = _Rep::_S_terminal; // grrr
|
|
|
|
return __r->_M_refdata();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const basic_string& __str)
|
|
|
|
: _M_dataplus(__str._M_rep()->_M_grab(_Alloc(), __str.get_allocator()),
|
|
|
|
__str.get_allocator())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const _Alloc& __a)
|
|
|
|
: _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const basic_string& __str, size_type __pos, size_type __n)
|
|
|
|
: _M_dataplus(_S_construct(__str._M_check(__pos),
|
|
|
|
__str._M_fold(__pos, __n), _Alloc()), _Alloc())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const basic_string& __str, size_type __pos,
|
|
|
|
size_type __n, const _Alloc& __a)
|
|
|
|
: _M_dataplus(_S_construct(__str._M_check(__pos),
|
|
|
|
__str._M_fold(__pos, __n), __a), __a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const _CharT* __s, size_type __n, const _Alloc& __a)
|
|
|
|
: _M_dataplus(_S_construct(__s, __s + __n, __a), __a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(const _CharT* __s, const _Alloc& __a)
|
2002-10-27 08:35:06 +01:00
|
|
|
: _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
|
|
|
|
__s + npos, __a), __a)
|
2000-10-05 13:27:02 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
basic_string(size_type __n, _CharT __c, const _Alloc& __a)
|
|
|
|
: _M_dataplus(_S_construct(__n, __c, __a), __a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
template<typename _InputIterator>
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a)
|
2000-10-05 13:27:02 +02:00
|
|
|
: _M_dataplus(_S_construct(__beg, __end, __a), __a)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
assign(const basic_string& __str)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
|
|
|
if (_M_rep() != __str._M_rep())
|
|
|
|
{
|
|
|
|
// XXX MT
|
|
|
|
allocator_type __a = this->get_allocator();
|
|
|
|
_CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator());
|
|
|
|
_M_rep()->_M_dispose(__a);
|
|
|
|
_M_data(__tmp);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
Move some basic_string members out of line because they are too big to reasonably be inline.
2003-04-27 Nathan Myers <ncm@cantrip.org>
Move some basic_string members out of line because
they are too big to reasonably be inline.
* include/bits/basic_string.h
(assign(const basic_string&, size_type, size_type),
assign(const _CharT*, size_type),
insert(size_type, const basic_string&, size_type, size_type),
insert(size_type, const _CharT*, size_type),
replace(size_type, size_type, const _CharT*, size_type)):
Move from here to...
* include/bits/basic_string.tcc: ...here.
From-SVN: r66132
2003-04-27 19:20:42 +02:00
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
assign(const basic_string& __str, size_type __pos, size_type __n)
|
|
|
|
{
|
|
|
|
const size_type __strsize = __str.size();
|
|
|
|
if (__pos > __strsize)
|
|
|
|
__throw_out_of_range("basic_string::assign");
|
|
|
|
const bool __testn = __n < __strsize - __pos;
|
|
|
|
const size_type __newsize = __testn ? __n : __strsize - __pos;
|
|
|
|
return this->assign(__str._M_data() + __pos, __newsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
assign(const _CharT* __s, size_type __n)
|
|
|
|
{
|
|
|
|
if (__n > this->max_size())
|
|
|
|
__throw_length_error("basic_string::assign");
|
|
|
|
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
|
|
|
|| less<const _CharT*>()(_M_data() + this->size(), __s))
|
|
|
|
return _M_replace_safe(_M_ibegin(), _M_iend(), __s, __s + __n);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Work in-place
|
|
|
|
const size_type __pos = __s - _M_data();
|
|
|
|
if (__pos >= __n)
|
|
|
|
traits_type::copy(_M_data(), __s, __n);
|
|
|
|
else if (__pos)
|
|
|
|
traits_type::move(_M_data(), __s, __n);
|
|
|
|
_M_rep()->_M_length = __n;
|
|
|
|
_M_data()[__n] = _Rep::_S_terminal; // grr.
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
insert(size_type __pos1, const basic_string& __str,
|
|
|
|
size_type __pos2, size_type __n)
|
|
|
|
{
|
|
|
|
const size_type __strsize = __str.size();
|
|
|
|
if (__pos2 > __strsize)
|
|
|
|
__throw_out_of_range("basic_string::insert");
|
|
|
|
const bool __testn = __n < __strsize - __pos2;
|
|
|
|
const size_type __newsize = __testn ? __n : __strsize - __pos2;
|
|
|
|
return this->insert(__pos1, __str._M_data() + __pos2, __newsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
insert(size_type __pos, const _CharT* __s, size_type __n)
|
|
|
|
{
|
|
|
|
const size_type __size = this->size();
|
|
|
|
if (__pos > __size)
|
|
|
|
__throw_out_of_range("basic_string::insert");
|
|
|
|
if (__size > this->max_size() - __n)
|
|
|
|
__throw_length_error("basic_string::insert");
|
|
|
|
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
|
|
|
|| less<const _CharT*>()(_M_data() + __size, __s))
|
|
|
|
return _M_replace_safe(_M_ibegin() + __pos, _M_ibegin() + __pos,
|
|
|
|
__s, __s + __n);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Work in-place. If _M_mutate reallocates the string, __s
|
|
|
|
// does not point anymore to valid data, therefore we save its
|
|
|
|
// offset, then we restore it.
|
|
|
|
const size_type __off = __s - _M_data();
|
|
|
|
_M_mutate(__pos, 0, __n);
|
|
|
|
__s = _M_data() + __off;
|
|
|
|
_CharT* __p = _M_data() + __pos;
|
|
|
|
if (__s + __n <= __p)
|
|
|
|
traits_type::copy(__p, __s, __n);
|
|
|
|
else if (__s >= __p)
|
|
|
|
traits_type::copy(__p, __s + __n, __n);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
traits_type::copy(__p, __s, __p - __s);
|
|
|
|
traits_type::copy(__p + (__p-__s), __p + __n, __n - (__p-__s));
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
replace(size_type __pos, size_type __n1, const _CharT* __s,
|
|
|
|
size_type __n2)
|
|
|
|
{
|
|
|
|
const size_type __size = this->size();
|
|
|
|
if (__pos > __size)
|
|
|
|
__throw_out_of_range("basic_string::replace");
|
|
|
|
const bool __testn1 = __n1 < __size - __pos;
|
|
|
|
const size_type __foldn1 = __testn1 ? __n1 : __size - __pos;
|
|
|
|
if (__size - __foldn1 > this->max_size() - __n2)
|
|
|
|
__throw_length_error("basic_string::replace");
|
|
|
|
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
|
|
|
|| less<const _CharT*>()(_M_data() + __size, __s))
|
|
|
|
return _M_replace_safe(_M_ibegin() + __pos,
|
|
|
|
_M_ibegin() + __pos + __foldn1, __s, __s + __n2);
|
|
|
|
// Todo: optimized in-place replace.
|
|
|
|
else
|
|
|
|
return _M_replace(_M_ibegin() + __pos, _M_ibegin() + __pos + __foldn1,
|
|
|
|
__s, __s + __n2,
|
|
|
|
typename iterator_traits<const _CharT*>::iterator_category());
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::_Rep::
|
|
|
|
_M_destroy(const _Alloc& __a) throw ()
|
|
|
|
{
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
if (this == &_S_empty_rep())
|
|
|
|
return;
|
|
|
|
const size_type __size = sizeof(_Rep_base) +
|
|
|
|
(this->_M_capacity + 1) * sizeof(_CharT);
|
2000-10-05 13:27:02 +02:00
|
|
|
_Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard()
|
|
|
|
{
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
if (_M_rep() == &_S_empty_rep())
|
|
|
|
return;
|
2000-10-05 13:27:02 +02:00
|
|
|
if (_M_rep()->_M_is_shared())
|
|
|
|
_M_mutate(0, 0, 0);
|
|
|
|
_M_rep()->_M_set_leaked();
|
|
|
|
}
|
|
|
|
|
2001-12-07 10:07:55 +01:00
|
|
|
// _M_mutate and, below, _M_clone, include, in the same form, an exponential
|
|
|
|
// growth policy, necessary to meet amortized linear time requirements of
|
|
|
|
// the library: see http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html.
|
|
|
|
// The policy is active for allocations requiring an amount of memory above
|
|
|
|
// system pagesize. This is consistent with the requirements of the standard:
|
|
|
|
// see, f.i., http://gcc.gnu.org/ml/libstdc++/2001-07/msg00130.html
|
2000-10-05 13:27:02 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
_M_mutate(size_type __pos, size_type __len1, size_type __len2)
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __old_size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
const size_type __new_size = __old_size + __len2 - __len1;
|
|
|
|
const _CharT* __src = _M_data() + __pos + __len1;
|
|
|
|
const size_type __how_much = __old_size - __pos - __len1;
|
|
|
|
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
if (_M_rep() == &_S_empty_rep()
|
|
|
|
|| _M_rep()->_M_is_shared() || __new_size > capacity())
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
|
|
|
// Must reallocate.
|
|
|
|
allocator_type __a = get_allocator();
|
2001-12-07 10:07:55 +01:00
|
|
|
// See below (_S_create) for the meaning and value of these
|
|
|
|
// constants.
|
|
|
|
const size_type __pagesize = 4096;
|
|
|
|
const size_type __malloc_header_size = 4 * sizeof (void*);
|
|
|
|
// The biggest string which fits in a memory page
|
2001-12-07 13:25:51 +01:00
|
|
|
const size_type __page_capacity = (__pagesize - __malloc_header_size
|
|
|
|
- sizeof(_Rep) - sizeof(_CharT))
|
|
|
|
/ sizeof(_CharT);
|
2001-12-07 10:07:55 +01:00
|
|
|
_Rep* __r;
|
|
|
|
if (__new_size > capacity() && __new_size > __page_capacity)
|
|
|
|
// Growing exponentially.
|
|
|
|
__r = _Rep::_S_create(__new_size > 2*capacity() ?
|
|
|
|
__new_size : 2*capacity(), __a);
|
|
|
|
else
|
|
|
|
__r = _Rep::_S_create(__new_size, __a);
|
2001-02-16 01:44:44 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (__pos)
|
|
|
|
traits_type::copy(__r->_M_refdata(), _M_data(), __pos);
|
|
|
|
if (__how_much)
|
|
|
|
traits_type::copy(__r->_M_refdata() + __pos + __len2,
|
|
|
|
__src, __how_much);
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
__r->_M_dispose(get_allocator());
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
_M_rep()->_M_dispose(__a);
|
|
|
|
_M_data(__r->_M_refdata());
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
else if (__how_much && __len1 != __len2)
|
|
|
|
{
|
|
|
|
// Work in-place
|
|
|
|
traits_type::move(_M_data() + __pos + __len2, __src, __how_much);
|
|
|
|
}
|
|
|
|
_M_rep()->_M_set_sharable();
|
|
|
|
_M_rep()->_M_length = __new_size;
|
|
|
|
_M_data()[__new_size] = _Rep::_S_terminal; // grrr. (per 21.3.4)
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
// You cannot leave those LWG people alone for a second.
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res)
|
|
|
|
{
|
|
|
|
if (__res > this->capacity() || _M_rep()->_M_is_shared())
|
|
|
|
{
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__res > this->max_size())
|
|
|
|
__throw_length_error("basic_string::reserve");
|
2001-11-21 23:04:53 +01:00
|
|
|
// Make sure we don't shrink below the current size
|
|
|
|
if (__res < this->size())
|
|
|
|
__res = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
allocator_type __a = get_allocator();
|
|
|
|
_CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
|
|
|
|
_M_rep()->_M_dispose(__a);
|
|
|
|
_M_data(__tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void basic_string<_CharT, _Traits, _Alloc>::swap(basic_string& __s)
|
|
|
|
{
|
|
|
|
if (_M_rep()->_M_is_leaked())
|
|
|
|
_M_rep()->_M_set_sharable();
|
|
|
|
if (__s._M_rep()->_M_is_leaked())
|
|
|
|
__s._M_rep()->_M_set_sharable();
|
|
|
|
if (this->get_allocator() == __s.get_allocator())
|
|
|
|
{
|
|
|
|
_CharT* __tmp = _M_data();
|
|
|
|
_M_data(__s._M_data());
|
|
|
|
__s._M_data(__tmp);
|
|
|
|
}
|
|
|
|
// The code below can usually be optimized away.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
basic_string __tmp1(_M_ibegin(), _M_iend(), __s.get_allocator());
|
|
|
|
basic_string __tmp2(__s._M_ibegin(), __s._M_iend(),
|
|
|
|
this->get_allocator());
|
|
|
|
*this = __tmp2;
|
|
|
|
__s = __tmp1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::_Rep*
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::_Rep::
|
|
|
|
_S_create(size_t __capacity, const _Alloc& __alloc)
|
|
|
|
{
|
2001-02-16 01:44:44 +01:00
|
|
|
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
|
2000-10-05 13:27:02 +02:00
|
|
|
// 83. String::npos vs. string::max_size()
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__capacity > _S_max_size)
|
2000-10-05 13:27:02 +02:00
|
|
|
#else
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__capacity == npos)
|
2000-10-05 13:27:02 +02:00
|
|
|
#endif
|
2001-02-16 01:44:44 +01:00
|
|
|
__throw_length_error("basic_string::_S_create");
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
// NB: Need an array of char_type[__capacity], plus a
|
|
|
|
// terminating null char_type() element, plus enough for the
|
|
|
|
// _Rep data structure. Whew. Seemingly so needy, yet so elemental.
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
size_t __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep_base);
|
2001-11-28 06:17:59 +01:00
|
|
|
|
|
|
|
// The standard places no restriction on allocating more memory
|
|
|
|
// than is strictly needed within this layer at the moment or as
|
|
|
|
// requested by an explicit application call to reserve(). Many
|
|
|
|
// malloc implementations perform quite poorly when an
|
|
|
|
// application attempts to allocate memory in a stepwise fashion
|
|
|
|
// growing each allocation size by only 1 char. Additionally,
|
|
|
|
// it makes little sense to allocate less linear memory than the
|
|
|
|
// natural blocking size of the malloc implementation.
|
|
|
|
// Unfortunately, we would need a somewhat low-level calculation
|
|
|
|
// with tuned parameters to get this perfect for any particular
|
|
|
|
// malloc implementation. Fortunately, generalizations about
|
|
|
|
// common features seen among implementations seems to suffice.
|
|
|
|
|
|
|
|
// __pagesize need not match the actual VM page size for good
|
|
|
|
// results in practice, thus we pick a common value on the low
|
|
|
|
// side. __malloc_header_size is an estimate of the amount of
|
|
|
|
// overhead per memory allocation (in practice seen N * sizeof
|
|
|
|
// (void*) where N is 0, 2 or 4). According to folklore,
|
|
|
|
// picking this value on the high side is better than
|
|
|
|
// low-balling it (especially when this algorithm is used with
|
|
|
|
// malloc implementations that allocate memory blocks rounded up
|
|
|
|
// to a size which is a power of 2).
|
|
|
|
const size_t __pagesize = 4096; // must be 2^i * __subpagesize
|
|
|
|
const size_t __subpagesize = 128; // should be >> __malloc_header_size
|
|
|
|
const size_t __malloc_header_size = 4 * sizeof (void*);
|
|
|
|
if ((__size + __malloc_header_size) > __pagesize)
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_t __extra =
|
2001-11-28 06:17:59 +01:00
|
|
|
(__pagesize - ((__size + __malloc_header_size) % __pagesize))
|
|
|
|
% __pagesize;
|
|
|
|
__capacity += __extra / sizeof(_CharT);
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
__size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep_base);
|
2001-11-28 06:17:59 +01:00
|
|
|
}
|
|
|
|
else if (__size > __subpagesize)
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_t __extra =
|
2001-11-28 06:17:59 +01:00
|
|
|
(__subpagesize - ((__size + __malloc_header_size) % __subpagesize))
|
|
|
|
% __subpagesize;
|
|
|
|
__capacity += __extra / sizeof(_CharT);
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
__size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep_base);
|
2001-11-28 06:17:59 +01:00
|
|
|
}
|
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
// NB: Might throw, but no worries about a leak, mate: _Rep()
|
|
|
|
// does not throw.
|
|
|
|
void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
|
|
|
|
_Rep *__p = new (__place) _Rep;
|
|
|
|
__p->_M_capacity = __capacity;
|
2002-04-16 02:45:36 +02:00
|
|
|
__p->_M_set_sharable(); // One reference.
|
2000-10-05 13:27:02 +02:00
|
|
|
__p->_M_length = 0;
|
|
|
|
return __p;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
_CharT*
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::_Rep::
|
|
|
|
_M_clone(const _Alloc& __alloc, size_type __res)
|
|
|
|
{
|
2001-12-07 10:07:55 +01:00
|
|
|
// Requested capacity of the clone.
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
const size_type __requested_cap = this->_M_length + __res;
|
2001-12-07 10:07:55 +01:00
|
|
|
// See above (_S_create) for the meaning and value of these constants.
|
|
|
|
const size_type __pagesize = 4096;
|
|
|
|
const size_type __malloc_header_size = 4 * sizeof (void*);
|
|
|
|
// The biggest string which fits in a memory page.
|
|
|
|
const size_type __page_capacity =
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
(__pagesize - __malloc_header_size - sizeof(_Rep_base) - sizeof(_CharT))
|
2001-12-07 10:07:55 +01:00
|
|
|
/ sizeof(_CharT);
|
|
|
|
_Rep* __r;
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
if (__requested_cap > this->_M_capacity
|
|
|
|
&& __requested_cap > __page_capacity)
|
2001-12-07 10:07:55 +01:00
|
|
|
// Growing exponentially.
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
__r = _Rep::_S_create(__requested_cap > 2*this->_M_capacity ?
|
|
|
|
__requested_cap : 2*this->_M_capacity, __alloc);
|
2001-12-07 10:07:55 +01:00
|
|
|
else
|
|
|
|
__r = _Rep::_S_create(__requested_cap, __alloc);
|
|
|
|
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
if (this->_M_length)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
2001-02-16 01:44:44 +01:00
|
|
|
try
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
{
|
|
|
|
traits_type::copy(__r->_M_refdata(), _M_refdata(),
|
|
|
|
this->_M_length);
|
|
|
|
}
|
2001-02-16 01:44:44 +01:00
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
__r->_M_destroy(__alloc);
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
Avoid multi-processor bus contention on increment/decrement-and- test of the reference count in the empty-string object...
2003-06-13 Nathan C. Myers <ncm-nospam@cantrip.org>
Avoid multi-processor bus contention on increment/decrement-and-
test of the reference count in the empty-string object, by comparing
addresses first, and never touching the reference count of the empty-
string object.
* include/bits/basic_string.h:
(_S_empty_rep_storage): Move into basic_string<>::_Rep for use by its
members.
(_Rep::_S_empty_rep()): New accessor.
(_Rep::_M_length, _Rep::_M_capacity, _Rep::_M_references): Move to
a base class _Rep_base.
(_Rep::_M_dispose, _Rep::_M_refcopy): Check for the empty string.
(basic_string()): Change to use _M_refdata() in place of _M_refcopy(),
since no longer must increment its refcount.
* include/bits/basic_string.tcc:
(_Rep::_M_destroy, _M_leak_hard): Check for the empty string and
return immediately. The former might be unnecessary. The latter
prevents begin() and end() from cloning it unnecessarily.
(_S_construct(_InIterator, _InIterator, const _Alloc&,
input_iterator_tag), _S_construct(_InIterator, _InIterator,
const _Alloc&, forward_iterator_tag), _S_construct(size_type, _CharT,
const _Alloc&)): Change to use _M_refdata() in place of _M_refcopy().
(_M_mutate): Check for the empty string and treat it as shared.
This is necessary here because _M_mutate is sometimes called with
all-zero arguments; in all other uses of _M_is_shared, the test comes
out right anyhow.
From-SVN: r67912
2003-06-13 22:59:42 +02:00
|
|
|
__r->_M_length = this->_M_length;
|
2000-10-05 13:27:02 +02:00
|
|
|
return __r->_M_refdata();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
void
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)
|
|
|
|
{
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__n > max_size())
|
|
|
|
__throw_length_error("basic_string::resize");
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__size < __n)
|
|
|
|
this->append(__n - __size, __c);
|
|
|
|
else if (__n < __size)
|
|
|
|
this->erase(__n);
|
|
|
|
// else nothing (in particular, avoid calling _M_mutate() unnecessarily.)
|
|
|
|
}
|
basic_string.h (replace(i1, i2, _CharT* k1, _CharT* k2), [...]): New specializations to optimize for the common cases of pointers and iterators.
2002-04-02 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
Philip Martin <philip@codematters.co.uk>
* include/bits/basic_string.h
(replace(i1, i2, _CharT* k1, _CharT* k2),
replace(i2, i2, const _CharT* k1, const _CharT* k2),
replace(i1, i2, iterator k1, iterator k2,
replace(i1, i2, const_iterator k1, const_iterator k2):
New specializations to optimize for the common cases of
pointers and iterators.
(replace(pos, n1, s, n2)): Tweak.
* include/bits/basic_string.tcc: Tweak comments.
* testsuite/21_strings/replace.cc (test04): New tests.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
Co-Authored-By: Philip Martin <philip@codematters.co.uk>
From-SVN: r51746
2002-04-02 14:07:07 +02:00
|
|
|
|
2003-06-21 00:12:18 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
_M_replace_aux(iterator __i1, iterator __i2, size_type __n2, _CharT __c)
|
|
|
|
{
|
2003-07-02 21:36:40 +02:00
|
|
|
const size_type __n1 = __i2 - __i1;
|
|
|
|
const size_type __off1 = __i1 - _M_ibegin();
|
2003-06-21 00:12:18 +02:00
|
|
|
if (max_size() - (this->size() - __n1) <= __n2)
|
|
|
|
__throw_length_error("basic_string::replace");
|
|
|
|
_M_mutate (__off1, __n1, __n2);
|
|
|
|
// Invalidated __i1, __i2
|
|
|
|
if (__n2)
|
|
|
|
traits_type::assign(_M_data() + __off1, __n2, __c);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
basic_string.h (replace(i1, i2, _CharT* k1, _CharT* k2), [...]): New specializations to optimize for the common cases of pointers and iterators.
2002-04-02 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
Philip Martin <philip@codematters.co.uk>
* include/bits/basic_string.h
(replace(i1, i2, _CharT* k1, _CharT* k2),
replace(i2, i2, const _CharT* k1, const _CharT* k2),
replace(i1, i2, iterator k1, iterator k2,
replace(i1, i2, const_iterator k1, const_iterator k2):
New specializations to optimize for the common cases of
pointers and iterators.
(replace(pos, n1, s, n2)): Tweak.
* include/bits/basic_string.tcc: Tweak comments.
* testsuite/21_strings/replace.cc (test04): New tests.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
Co-Authored-By: Philip Martin <philip@codematters.co.uk>
From-SVN: r51746
2002-04-02 14:07:07 +02:00
|
|
|
// This is the general replace helper, which currently gets instantiated both
|
|
|
|
// for input iterators and reverse iterators. It buffers internally and then
|
|
|
|
// calls _M_replace_safe.
|
2000-10-05 13:27:02 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
template<typename _InputIterator>
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
_M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
|
|
|
|
_InputIterator __k2, input_iterator_tag)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
2001-12-10 14:42:01 +01:00
|
|
|
// Save concerned source string data in a temporary.
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const basic_string __s(__k1, __k2);
|
2001-12-10 14:42:01 +01:00
|
|
|
return _M_replace_safe(__i1, __i2, __s._M_ibegin(), __s._M_iend());
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
2001-12-10 14:42:01 +01:00
|
|
|
// This is a special replace helper, which does not buffer internally
|
basic_string.h (replace(i1, i2, _CharT* k1, _CharT* k2), [...]): New specializations to optimize for the common cases of pointers and iterators.
2002-04-02 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
Philip Martin <philip@codematters.co.uk>
* include/bits/basic_string.h
(replace(i1, i2, _CharT* k1, _CharT* k2),
replace(i2, i2, const _CharT* k1, const _CharT* k2),
replace(i1, i2, iterator k1, iterator k2,
replace(i1, i2, const_iterator k1, const_iterator k2):
New specializations to optimize for the common cases of
pointers and iterators.
(replace(pos, n1, s, n2)): Tweak.
* include/bits/basic_string.tcc: Tweak comments.
* testsuite/21_strings/replace.cc (test04): New tests.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
Co-Authored-By: Philip Martin <philip@codematters.co.uk>
From-SVN: r51746
2002-04-02 14:07:07 +02:00
|
|
|
// and can be used in "safe" situations involving forward iterators,
|
2001-12-10 14:42:01 +01:00
|
|
|
// i.e., when source and destination ranges are known to not overlap.
|
2000-10-05 13:27:02 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
template<typename _ForwardIterator>
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
BUGS: Update from 2.90.8 snapshot.
2003-06-10 Phil Edwards <pme@gcc.gnu.org>
* docs/html/17_intro/BUGS: Update from 2.90.8 snapshot.
* docs/html/17_intro/CHECKLIST: Bring up to date with respect to
correctness of container::iterator typedefs. Fix whitespace.
* docs/html/20_util/howto.html, docs/html/ext/howto.html: Add links
to allocator docs.
* docs/html/documentation.html: Regenerate.
* include/bits/basic_string.h, include/bits/basic_string.tcc,
include/bits/deque.tcc, include/bits/list.tcc, include/bits/stl_algo.h,
include/bits/stl_algobase.h, include/bits/stl_bvector.h,
include/bits/stl_deque.h, include/bits/stl_iterator_base_funcs.h,
include/bits/stl_list.h, include/bits/stl_uninitialized.h,
include/bits/stl_vector.h, include/bits/vector.tcc,
include/ext/algorithm, include/ext/slist, include/std/std_bitset.h:
Change _Iter names to _Iterator, and __pos to __position.
* include/bits/stl_relops.h, include/bits/stl_numeric.h,
include/bits/stl_multiset.h, include/bits/stl_set.h:
Remove emacs markers.
* include/bits/stl_threads.h (_STL_auto_lock): Add __unused__.
From-SVN: r67736
2003-06-10 23:52:25 +02:00
|
|
|
_M_replace_safe(iterator __i1, iterator __i2, _ForwardIterator __k1,
|
|
|
|
_ForwardIterator __k2)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __dnew = static_cast<size_type>(std::distance(__k1, __k2));
|
|
|
|
const size_type __dold = __i2 - __i1;
|
|
|
|
const size_type __dmax = this->max_size();
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__dmax <= __dnew)
|
|
|
|
__throw_length_error("basic_string::_M_replace");
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __off = __i1 - _M_ibegin();
|
2000-10-05 13:27:02 +02:00
|
|
|
_M_mutate(__off, __dold, __dnew);
|
2001-12-10 14:42:01 +01:00
|
|
|
|
|
|
|
// Invalidated __i1, __i2
|
2001-10-31 09:27:20 +01:00
|
|
|
if (__dnew)
|
2001-12-10 14:42:01 +01:00
|
|
|
_S_copy_chars(_M_data() + __off, __k1, __k2);
|
2001-10-31 09:27:20 +01:00
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
replace(size_type __pos1, size_type __n1, const basic_string& __str,
|
|
|
|
size_type __pos2, size_type __n2)
|
|
|
|
{
|
2002-01-14 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
* include/bits/basic_string.h
(replace(__pos, __n1, __s, __n2)): Optimize by avoiding
temporaries (i.e., call _M_replace_safe) when possible.
(replace(__pos, __n, __str)): Call replace(__pos, __n1, __s, __n2).
(replace(__pos, __n1, __s)): Call replace(__pos, __n1, __s , __n2).
(replace(__i1, __i2, __str)): Call replace(__i1, __i2, __s, __n).
(replace(__i1, __i2, __s)): Call replace(__i1, __i2, __s, __n).
(replace(__i1, __i2, __s, __n)): Call replace(__pos1, __n1, __s, __n2).
* include/bits/basic_string.tcc
(replace(__pos1, __n1, __str, __pos2, __n2)): Call
replace(__pos, __n1, __s, __n2).
* testsuite/21_strings/replace.cc (test03): New testcases.
* include/bits/basic_string.h (insert(__pos, __s, __n)):
Adjust comparison wrt overflow.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r48834
2002-01-14 20:04:15 +01:00
|
|
|
const size_type __strsize = __str.size();
|
|
|
|
if (__pos2 > __strsize)
|
|
|
|
__throw_out_of_range("basic_string::replace");
|
|
|
|
const bool __testn2 = __n2 < __strsize - __pos2;
|
|
|
|
const size_type __foldn2 = __testn2 ? __n2 : __strsize - __pos2;
|
|
|
|
return this->replace(__pos1, __n1,
|
|
|
|
__str._M_data() + __pos2, __foldn2);
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
append(const basic_string& __str)
|
|
|
|
{
|
|
|
|
// Iff appending itself, string needs to pre-reserve the
|
|
|
|
// correct size so that _M_mutate does not clobber the
|
|
|
|
// iterators formed here.
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = __str.size();
|
|
|
|
const size_type __len = __size + this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__len > this->capacity())
|
|
|
|
this->reserve(__len);
|
2001-12-10 14:42:01 +01:00
|
|
|
return _M_replace_safe(_M_iend(), _M_iend(), __str._M_ibegin(),
|
|
|
|
__str._M_iend());
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
append(const basic_string& __str, size_type __pos, size_type __n)
|
|
|
|
{
|
|
|
|
// Iff appending itself, string needs to pre-reserve the
|
|
|
|
// correct size so that _M_mutate does not clobber the
|
|
|
|
// iterators formed here.
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __len = std::min(size_type(__str.size() - __pos),
|
|
|
|
__n) + this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__len > this->capacity())
|
|
|
|
this->reserve(__len);
|
2001-12-10 14:42:01 +01:00
|
|
|
return _M_replace_safe(_M_iend(), _M_iend(), __str._M_check(__pos),
|
|
|
|
__str._M_fold(__pos, __n));
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
append(const _CharT* __s, size_type __n)
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __len = __n + this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__len > this->capacity())
|
|
|
|
this->reserve(__len);
|
2001-12-10 14:42:01 +01:00
|
|
|
return _M_replace_safe(_M_iend(), _M_iend(), __s, __s + __n);
|
2000-10-05 13:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>&
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
append(size_type __n, _CharT __c)
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __len = __n + this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__len > this->capacity())
|
|
|
|
this->reserve(__len);
|
|
|
|
return this->replace(_M_iend(), _M_iend(), __n, __c);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>
|
2000-10-05 13:27:02 +02:00
|
|
|
operator+(const _CharT* __lhs,
|
2001-10-31 09:27:20 +01:00
|
|
|
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
2001-10-31 09:27:20 +01:00
|
|
|
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
|
2000-10-05 13:27:02 +02:00
|
|
|
typedef typename __string_type::size_type __size_type;
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const __size_type __len = _Traits::length(__lhs);
|
2000-10-05 13:27:02 +02:00
|
|
|
__string_type __str;
|
|
|
|
__str.reserve(__len + __rhs.size());
|
|
|
|
__str.append(__lhs, __lhs + __len);
|
|
|
|
__str.append(__rhs);
|
|
|
|
return __str;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>
|
|
|
|
operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
2001-10-31 09:27:20 +01:00
|
|
|
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
|
2000-10-05 13:27:02 +02:00
|
|
|
typedef typename __string_type::size_type __size_type;
|
|
|
|
__string_type __str;
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const __size_type __len = __rhs.size();
|
2000-10-05 13:27:02 +02:00
|
|
|
__str.reserve(__len + 1);
|
2001-03-15 09:46:23 +01:00
|
|
|
__str.append(__size_type(1), __lhs);
|
2000-10-05 13:27:02 +02:00
|
|
|
__str.append(__rhs);
|
|
|
|
return __str;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
copy(_CharT* __s, size_type __n, size_type __pos) const
|
|
|
|
{
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__pos > this->size())
|
|
|
|
__throw_out_of_range("basic_string::copy");
|
2000-10-05 13:27:02 +02:00
|
|
|
|
|
|
|
if (__n > this->size() - __pos)
|
|
|
|
__n = this->size() - __pos;
|
|
|
|
|
|
|
|
traits_type::copy(__s, _M_data() + __pos, __n);
|
|
|
|
// 21.3.5.7 par 3: do not append null. (good.)
|
|
|
|
return __n;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
size_t __xpos = __pos;
|
|
|
|
const _CharT* __data = _M_data();
|
2001-01-12 22:24:15 +01:00
|
|
|
for (; __xpos + __n <= __size; ++__xpos)
|
2000-10-05 13:27:02 +02:00
|
|
|
if (traits_type::compare(__data + __xpos, __s, __n) == 0)
|
|
|
|
return __xpos;
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find(_CharT __c, size_type __pos) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
size_type __ret = npos;
|
|
|
|
if (__pos < __size)
|
|
|
|
{
|
|
|
|
const _CharT* __data = _M_data();
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __n = __size - __pos;
|
2001-01-12 22:24:15 +01:00
|
|
|
const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
|
|
|
|
if (__p)
|
2000-10-05 13:27:02 +02:00
|
|
|
__ret = __p - __data;
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
rfind(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__n <= __size)
|
|
|
|
{
|
2003-03-05 23:24:56 +01:00
|
|
|
__pos = std::min(size_type(__size - __n), __pos);
|
2000-10-05 13:27:02 +02:00
|
|
|
const _CharT* __data = _M_data();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (traits_type::compare(__data + __pos, __s, __n) == 0)
|
|
|
|
return __pos;
|
|
|
|
}
|
|
|
|
while (__pos-- > 0);
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
rfind(_CharT __c, size_type __pos) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2000-10-05 13:27:02 +02:00
|
|
|
if (__size)
|
|
|
|
{
|
|
|
|
size_t __xpos = __size - 1;
|
|
|
|
if (__xpos > __pos)
|
|
|
|
__xpos = __pos;
|
|
|
|
|
|
|
|
for (++__xpos; __xpos-- > 0; )
|
|
|
|
if (traits_type::eq(_M_data()[__xpos], __c))
|
|
|
|
return __xpos;
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
|
|
|
for (; __n && __pos < this->size(); ++__pos)
|
|
|
|
{
|
2001-01-12 22:24:15 +01:00
|
|
|
const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]);
|
|
|
|
if (__p)
|
2000-10-05 13:27:02 +02:00
|
|
|
return __pos;
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
|
|
|
size_type __size = this->size();
|
|
|
|
if (__size && __n)
|
|
|
|
{
|
|
|
|
if (--__size > __pos)
|
|
|
|
__size = __pos;
|
|
|
|
do
|
|
|
|
{
|
2001-01-12 22:24:15 +01:00
|
|
|
if (traits_type::find(__s, __n, _M_data()[__size]))
|
2000-10-05 13:27:02 +02:00
|
|
|
return __size;
|
|
|
|
}
|
|
|
|
while (__size-- != 0);
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
|
|
|
size_t __xpos = __pos;
|
2001-10-19 20:39:00 +02:00
|
|
|
for (; __xpos < this->size(); ++__xpos)
|
2001-01-12 22:24:15 +01:00
|
|
|
if (!traits_type::find(__s, __n, _M_data()[__xpos]))
|
2000-10-05 13:27:02 +02:00
|
|
|
return __xpos;
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_first_not_of(_CharT __c, size_type __pos) const
|
|
|
|
{
|
|
|
|
size_t __xpos = __pos;
|
2001-01-12 22:24:15 +01:00
|
|
|
for (; __xpos < this->size(); ++__xpos)
|
2000-10-05 13:27:02 +02:00
|
|
|
if (!traits_type::eq(_M_data()[__xpos], __c))
|
|
|
|
return __xpos;
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
|
|
|
|
{
|
|
|
|
size_type __size = this->size();
|
2001-10-19 20:39:00 +02:00
|
|
|
if (__size)
|
2000-10-05 13:27:02 +02:00
|
|
|
{
|
|
|
|
if (--__size > __pos)
|
|
|
|
__size = __pos;
|
|
|
|
do
|
|
|
|
{
|
2001-01-12 22:24:15 +01:00
|
|
|
if (!traits_type::find(__s, __n, _M_data()[__size]))
|
2000-10-05 13:27:02 +02:00
|
|
|
return __size;
|
|
|
|
}
|
|
|
|
while (__size--);
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
2001-07-20 02:09:31 +02:00
|
|
|
typename basic_string<_CharT, _Traits, _Alloc>::size_type
|
2000-10-05 13:27:02 +02:00
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
find_last_not_of(_CharT __c, size_type __pos) const
|
|
|
|
{
|
|
|
|
size_type __size = this->size();
|
|
|
|
if (__size)
|
|
|
|
{
|
|
|
|
if (--__size > __pos)
|
|
|
|
__size = __pos;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!traits_type::eq(_M_data()[__size], __c))
|
|
|
|
return __size;
|
|
|
|
}
|
|
|
|
while (__size--);
|
|
|
|
}
|
|
|
|
return npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
int
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
compare(size_type __pos, size_type __n, const basic_string& __str) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
|
|
|
const size_type __osize = __str.size();
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__pos > __size)
|
|
|
|
__throw_out_of_range("basic_string::compare");
|
2000-10-05 13:27:02 +02:00
|
|
|
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __rsize= std::min(size_type(__size - __pos), __n);
|
|
|
|
const size_type __len = std::min(__rsize, __osize);
|
2000-10-05 13:27:02 +02:00
|
|
|
int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
|
|
|
|
if (!__r)
|
|
|
|
__r = __rsize - __osize;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
int
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
compare(size_type __pos1, size_type __n1, const basic_string& __str,
|
|
|
|
size_type __pos2, size_type __n2) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
|
|
|
const size_type __osize = __str.size();
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__pos1 > __size || __pos2 > __osize)
|
|
|
|
__throw_out_of_range("basic_string::compare");
|
2000-10-05 13:27:02 +02:00
|
|
|
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __rsize = std::min(size_type(__size - __pos1), __n1);
|
|
|
|
const size_type __rosize = std::min(size_type(__osize - __pos2), __n2);
|
|
|
|
const size_type __len = std::min(__rsize, __rosize);
|
2000-10-05 13:27:02 +02:00
|
|
|
int __r = traits_type::compare(_M_data() + __pos1,
|
|
|
|
__str.data() + __pos2, __len);
|
|
|
|
if (!__r)
|
|
|
|
__r = __rsize - __rosize;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
int
|
|
|
|
basic_string<_CharT, _Traits, _Alloc>::
|
|
|
|
compare(const _CharT* __s) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
|
|
|
const size_type __osize = traits_type::length(__s);
|
|
|
|
const size_type __len = std::min(__size, __osize);
|
2002-11-01 16:21:17 +01:00
|
|
|
int __r = traits_type::compare(_M_data(), __s, __len);
|
2000-10-05 13:27:02 +02:00
|
|
|
if (!__r)
|
2002-11-01 16:21:17 +01:00
|
|
|
__r = __size - __osize;
|
2000-10-05 13:27:02 +02:00
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-12 04:30:37 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
int
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string <_CharT, _Traits, _Alloc>::
|
2001-06-12 04:30:37 +02:00
|
|
|
compare(size_type __pos, size_type __n1, const _CharT* __s) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2001-06-12 04:30:37 +02:00
|
|
|
if (__pos > __size)
|
|
|
|
__throw_out_of_range("basic_string::compare");
|
|
|
|
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __osize = traits_type::length(__s);
|
|
|
|
const size_type __rsize = std::min(size_type(__size - __pos), __n1);
|
|
|
|
const size_type __len = std::min(__rsize, __osize);
|
2001-06-12 04:30:37 +02:00
|
|
|
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
|
|
|
|
if (!__r)
|
|
|
|
__r = __rsize - __osize;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
2000-10-05 13:27:02 +02:00
|
|
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
|
|
|
int
|
2001-10-31 09:27:20 +01:00
|
|
|
basic_string <_CharT, _Traits, _Alloc>::
|
2000-10-05 13:27:02 +02:00
|
|
|
compare(size_type __pos, size_type __n1, const _CharT* __s,
|
|
|
|
size_type __n2) const
|
|
|
|
{
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __size = this->size();
|
2001-02-16 01:44:44 +01:00
|
|
|
if (__pos > __size)
|
|
|
|
__throw_out_of_range("basic_string::compare");
|
2000-10-05 13:27:02 +02:00
|
|
|
|
basic_string.h (_M_fold, [...]): Constify various variables.
2003-06-04 Paolo Carlini <pcarlini@unitus.it>
* include/bits/basic_string.h (_M_fold, insert(iterator, _CharT),
erase(iterator), erase(iterator, iterator), c_str,
compare(const basic_string&)): Constify various variables.
* include/bits/basic_string.tcc (_S_construct(_InIter, _InIter,
const _Alloc&, input_iterator_tag), _M_destroy, _M_mutate,
_S_create, resize, _M_replace, _M_replace_safe,
append(const basic_string&), append(const basic_string&, size_type,
size_type), append(const _CharT*, size_type), append(size_type,
_CharT), operator+(const _CharT*, const basic_string&),
operator+(_CharT, const basic_string&), replace(iterator, iterator,
size_type, _CharT), find(const _CharT*, size_type, size_type),
find(_CharT, size_type), rfind(const _CharT*, size_type, size_type),
rfind(_CharT, size_type), compare(size_type, size_type,
const basic_string&), compare(size_type, size_type,
const basic_string&, size_type, size_type), compare(const _CharT*),
compare(size_type, size_type, const _CharT*), compare(size_type,
size_type, const _CharT*, size_type)): Likewise.
From-SVN: r67468
2003-06-05 00:53:05 +02:00
|
|
|
const size_type __osize = std::min(traits_type::length(__s), __n2);
|
|
|
|
const size_type __rsize = std::min(size_type(__size - __pos), __n1);
|
|
|
|
const size_type __len = std::min(__rsize, __osize);
|
2000-10-05 13:27:02 +02:00
|
|
|
int __r = traits_type::compare(_M_data() + __pos, __s, __len);
|
|
|
|
if (!__r)
|
|
|
|
__r = __rsize - __osize;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 01:19:13 +01:00
|
|
|
// Inhibit implicit instantiations for required instantiations,
|
|
|
|
// which are defined via explicit instantiations elsewhere.
|
|
|
|
// NB: This syntax is a GNU extension.
|
2003-07-05 06:05:45 +02:00
|
|
|
#if _GLIBCXX_EXTERN_TEMPLATE
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 01:19:13 +01:00
|
|
|
extern template class basic_string<char>;
|
2002-03-08 07:05:21 +01:00
|
|
|
extern template
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 01:19:13 +01:00
|
|
|
basic_istream<char>&
|
|
|
|
operator>>(basic_istream<char>&, string&);
|
|
|
|
extern template
|
|
|
|
basic_ostream<char>&
|
|
|
|
operator<<(basic_ostream<char>&, const string&);
|
|
|
|
extern template
|
|
|
|
basic_istream<char>&
|
|
|
|
getline(basic_istream<char>&, string&, char);
|
|
|
|
extern template
|
|
|
|
basic_istream<char>&
|
|
|
|
getline(basic_istream<char>&, string&);
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_USE_WCHAR_T
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 01:19:13 +01:00
|
|
|
extern template class basic_string<wchar_t>;
|
|
|
|
extern template
|
|
|
|
basic_istream<wchar_t>&
|
|
|
|
operator>>(basic_istream<wchar_t>&, wstring&);
|
|
|
|
extern template
|
|
|
|
basic_ostream<wchar_t>&
|
|
|
|
operator<<(basic_ostream<wchar_t>&, const wstring&);
|
|
|
|
extern template
|
|
|
|
basic_istream<wchar_t>&
|
|
|
|
getline(basic_istream<wchar_t>&, wstring&, wchar_t);
|
|
|
|
extern template
|
|
|
|
basic_istream<wchar_t>&
|
|
|
|
getline(basic_istream<wchar_t>&, wstring&);
|
2002-11-01 18:30:36 +01:00
|
|
|
#endif
|
2003-02-13 22:39:03 +01:00
|
|
|
#endif
|
2001-06-12 04:30:37 +02:00
|
|
|
} // namespace std
|
2000-10-05 13:27:02 +02:00
|
|
|
|
2001-06-12 04:30:37 +02:00
|
|
|
#endif
|