diff options
| author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-01-14 19:04:15 +0000 |
|---|---|---|
| committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-01-14 19:04:15 +0000 |
| commit | ee73b234fecc4e51b3b5bbbcbd97127d78ea71f8 (patch) | |
| tree | caa42f7b432dd4506dde01e7d8c7e1563d243029 /libstdc++-v3/include/bits/basic_string.tcc | |
| parent | 9f4d041d17d18b6d53a0c5edd0a47f8db66ece85 (diff) | |
| download | ppe42-gcc-ee73b234fecc4e51b3b5bbbcbd97127d78ea71f8.tar.gz ppe42-gcc-ee73b234fecc4e51b3b5bbbcbd97127d78ea71f8.zip | |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@48834 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/basic_string.tcc')
| -rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 63a9864a9d0..b57c7f642f9 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -1,6 +1,7 @@ // Components for manipulating sequences of characters -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -543,9 +544,13 @@ namespace std replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) { - return this->replace(_M_check(__pos1), _M_fold(__pos1, __n1), - __str._M_check(__pos2), - __str._M_fold(__pos2, __n2)); + 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); } template<typename _CharT, typename _Traits, typename _Alloc> |

