From 61b0ae2bd24934c4f738a3f5d80db3c1f30fa1c6 Mon Sep 17 00:00:00 2001 From: ntrifunovic Date: Sat, 9 Feb 2013 23:33:27 +0000 Subject: [PATCH] Fix for bug ID: 3576827 - replace_invalid() only works with back_inserter git-svn-id: http://svn.code.sf.net/p/utfcpp/code@136 a809a056-fc17-0410-9590-b4f493f8b08e --- source/utf8/checked.h | 4 ++-- test_drivers/smoke_test/test.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/utf8/checked.h b/source/utf8/checked.h index 1c1cadd..cc1ec47 100644 --- a/source/utf8/checked.h +++ b/source/utf8/checked.h @@ -109,13 +109,13 @@ namespace utf8 case internal::NOT_ENOUGH_ROOM: throw not_enough_room(); case internal::INVALID_LEAD: - utf8::append (replacement, out); + out = utf8::append (replacement, out); ++start; break; case internal::INCOMPLETE_SEQUENCE: case internal::OVERLONG_SEQUENCE: case internal::INVALID_CODE_POINT: - utf8::append (replacement, out); + out = utf8::append (replacement, out); ++start; // just one replacement mark for the sequence while (start != end && utf8::internal::is_trail(*start)) diff --git a/test_drivers/smoke_test/test.cpp b/test_drivers/smoke_test/test.cpp index 9273da2..7489835 100644 --- a/test_drivers/smoke_test/test.cpp +++ b/test_drivers/smoke_test/test.cpp @@ -153,12 +153,12 @@ int main() //replace_invalid char invalid_sequence[] = "a\x80\xe0\xa0\xc0\xaf\xed\xa0\x80z"; - vector replace_invalid_result; - replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), back_inserter(replace_invalid_result), '?'); + vector replace_invalid_result(50); + replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), replace_invalid_result.begin(), '?'); bvalid = is_valid(replace_invalid_result.begin(), replace_invalid_result.end()); assert (bvalid); const char* fixed_invalid_sequence = "a????z"; - assert (std::equal(replace_invalid_result.begin(), replace_invalid_result.end(), fixed_invalid_sequence)); + assert (std::equal(replace_invalid_result.begin(), replace_invalid_result.begin() + sizeof(fixed_invalid_sequence), fixed_invalid_sequence)); // iterator utf8::iterator it(threechars, threechars, threechars + 9);