diff options
Diffstat (limited to 'libstdc++-v3/include/bits/basic_string.h')
| -rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index d25d9def39b..5756e9eac44 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -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 @@ -551,7 +552,7 @@ namespace std const size_type __size = this->size(); if (__pos > __size) __throw_out_of_range("basic_string::insert"); - if (__n + __size > this->max_size()) + 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)) @@ -626,10 +627,7 @@ namespace std basic_string& replace(size_type __pos, size_type __n, const basic_string& __str) - { - return this->replace(_M_check(__pos), _M_fold(__pos, __n), - __str.begin(), __str.end()); - } + { return this->replace(__pos, __n, __str._M_data(), __str.size()); } basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, @@ -639,36 +637,41 @@ namespace std replace(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) { - return this->replace(_M_check(__pos), _M_fold(__pos, __n1), - __s, __s + __n2); + const size_type __size = this->size(); + if (__pos > __size) + __throw_out_of_range("basic_string::replace"); + if (__size - __n1 > this->max_size() - __n2) + __throw_length_error("basic_string::replace"); + const bool __testn1 = __n1 < __size - __pos; + const size_type __foldn1 = __testn1 ? __n1 : __size - __pos; + 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); + else return this->replace(_M_check(__pos), _M_fold(__pos, __n1), + __s, __s + __n2); } basic_string& replace(size_type __pos, size_type __n1, const _CharT* __s) - { - return this->replace(_M_check(__pos), _M_fold(__pos, __n1), - __s, __s + traits_type::length(__s)); - } + { return this->replace(__pos, __n1, __s, traits_type::length(__s)); } basic_string& replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) - { - return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c); - } + { return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c); } basic_string& replace(iterator __i1, iterator __i2, const basic_string& __str) - { return this->replace(__i1, __i2, __str.begin(), __str.end()); } + { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } basic_string& replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) - { return this->replace(__i1, __i2, __s, __s + __n); } + { return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); } basic_string& replace(iterator __i1, iterator __i2, const _CharT* __s) - { return this->replace(__i1, __i2, __s, - __s + traits_type::length(__s)); } + { return this->replace(__i1, __i2, __s, traits_type::length(__s)); } basic_string& replace(iterator __i1, iterator __i2, size_type __n, _CharT __c); |

