Commit b11f91210acd30f6724b7189834c87f94ff94710
- Diff rendering mode:
- inline
- side by side
etc/ChangeLog-5.1
(7 / 0)
|   | |||
| 1 | 2008-03-18 Petr Ovtchenkov <complement@users.sourceforge.net> | ||
| 2 | |||
| 3 | * stlport/stl/_string.c: derived from patch #1914475, wrong | ||
| 4 | replace for selfreferencing string; thanks Farid Zaripov; | ||
| 5 | |||
| 6 | * test/unit/string_test.cpp: test for problem above. | ||
| 7 | |||
| 1 | 8 | 2008-01-29 Petr Ovtchenkov <complement@users.sourceforge.net> | |
| 2 | 9 | ||
| 3 | 10 | * build/Makefiles/gmake/gcc.mak, build/test/unit/gcc.mak: |
stlport/stl/_string.c
(15 / 23)
|   | |||
| 401 | 401 | basic_string<_CharT,_Traits,_Alloc>& | |
| 402 | 402 | basic_string<_CharT,_Traits,_Alloc> ::_M_replace(iterator __first, iterator __last, | |
| 403 | 403 | const _CharT* __f, const _CharT* __l, | |
| 404 | bool __self_ref) { | ||
| 404 | bool __self_ref) | ||
| 405 | { | ||
| 405 | 406 | const ptrdiff_t __n = __l - __f; | |
| 406 | 407 | const difference_type __len = __last - __first; | |
| 407 | 408 | if (__len >= __n) { | |
| … | … | ||
| 411 | 411 | else | |
| 412 | 412 | _M_move(__f, __l, __first); | |
| 413 | 413 | erase(__first + __n, __last); | |
| 414 | } | ||
| 415 | else { | ||
| 416 | if (!__self_ref || (__f >= __last) || (__l <= __first)) { | ||
| 417 | //no overlap: | ||
| 414 | } else if (!__self_ref || (__f >= __last) || (__l <= __first)) { // no overlap | ||
| 418 | 415 | const_iterator __m = __f + __len; | |
| 419 | 416 | _M_copy(__f, __m, __first); | |
| 420 | _M_insert(__last, __m, __l, false ); | ||
| 421 | } | ||
| 422 | else { | ||
| 423 | //we have to take care of overlaping | ||
| 424 | if (__f < __first) { | ||
| 425 | const_iterator __m = __f + __len; | ||
| 426 | //We have to deal with possible reallocation because we do insert first. | ||
| 427 | const difference_type __off_dest = __first - this->begin(); | ||
| 428 | const difference_type __off_src = __f - this->begin(); | ||
| 429 | _M_insert(__last, __m, __l, true); | ||
| 430 | _Traits::move(begin() + __off_dest, begin() + __off_src, __len); | ||
| 431 | } | ||
| 432 | else { | ||
| 433 | const_iterator __m = __f + __len; | ||
| 434 | _Traits::move(__first, __f, __len); | ||
| 435 | _M_insert(__last, __m, __l, true); | ||
| 436 | } | ||
| 437 | } | ||
| 417 | _M_insert(__last, __m, __l, __self_ref ); | ||
| 418 | } else if (__f < __first) { // we have to take care of overlaping | ||
| 419 | const_iterator __m = __f + __len; | ||
| 420 | // We have to deal with possible reallocation because we do insert first. | ||
| 421 | const difference_type __off_dest = __first - this->begin(); | ||
| 422 | const difference_type __off_src = __f - this->begin(); | ||
| 423 | _M_insert(__last, __m, __l, true); | ||
| 424 | _Traits::move(begin() + __off_dest, begin() + __off_src, __len); | ||
| 425 | } else { | ||
| 426 | const_iterator __m = __f + __len; | ||
| 427 | _Traits::move(__first, __f, __len); | ||
| 428 | _M_insert(__last, __m, __l, true); | ||
| 438 | 429 | } | |
| 439 | 430 | return *this; | |
| 440 | 431 | } |
test/unit/string_test.cpp
(6 / 0)
|   | |||
| 541 | 541 | CPPUNIT_ASSERT( s == "1345656" ); | |
| 542 | 542 | ||
| 543 | 543 | s = "123456"; | |
| 544 | i = s.begin(); | ||
| 545 | ci = s.begin() + 1; | ||
| 546 | s.replace(i, i, ci, ci + 1); | ||
| 547 | CPPUNIT_CHECK( s == "2123456" ); | ||
| 548 | |||
| 549 | s = "123456"; | ||
| 544 | 550 | s.replace(s.begin() + 4, s.end(), cs.begin(), cs.end()); | |
| 545 | 551 | CPPUNIT_ASSERT( s == "1234123456" ); | |
| 546 | 552 |

