From 01889c42808988eafff3dfa06fe433f1a3414fd3 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Thu, 6 May 2004 17:41:09 +0000 Subject: [PATCH] ICU-2761 make UnicodeString::extractBetween() pin properly X-SVN-Rev: 15179 --- icu4c/source/common/unicode/unistr.h | 7 +++++-- icu4c/source/common/unistr.cpp | 9 ++++++--- icu4c/source/test/intltest/ustrtest.cpp | 9 ++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/icu4c/source/common/unicode/unistr.h b/icu4c/source/common/unicode/unistr.h index 15ac16c207..3fe4aeb5e3 100644 --- a/icu4c/source/common/unicode/unistr.h +++ b/icu4c/source/common/unicode/unistr.h @@ -3748,8 +3748,11 @@ inline void UnicodeString::extractBetween(int32_t start, int32_t limit, UChar *dst, - int32_t dstStart) const -{ doExtract(start, limit - start, dst, dstStart); } + int32_t dstStart) const { + pinIndex(start); + pinIndex(limit); + doExtract(start, limit - start, dst, dstStart); +} inline UChar UnicodeString::doCharAt(int32_t offset) const diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index 409f31efd7..32a51b0c62 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1999-2003, International Business Machines Corporation and * +* Copyright (C) 1999-2004, International Business Machines Corporation and * * others. All Rights Reserved. * ****************************************************************************** * @@ -1621,8 +1621,11 @@ UnicodeString::extract(char *dest, int32_t destCapacity, void UnicodeString::extractBetween(int32_t start, int32_t limit, - UnicodeString& target) const -{ doExtract(start, limit - start, target); } + UnicodeString& target) const { + pinIndex(start); + pinIndex(limit); + doExtract(start, limit - start, target); +} int32_t UnicodeString::doExtract(int32_t start, int32_t length, diff --git a/icu4c/source/test/intltest/ustrtest.cpp b/icu4c/source/test/intltest/ustrtest.cpp index ba7050b941..7922f51828 100644 --- a/icu4c/source/test/intltest/ustrtest.cpp +++ b/icu4c/source/test/intltest/ustrtest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2004, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -440,6 +440,13 @@ UnicodeStringTest::TestExtract() if (test1.extract(11, 12, test4) != 12 || test4[12] != 0) { errln("UnicodeString.extract(char *) failed to return the correct size of destination buffer."); } + + // test proper pinning in extractBetween() + test1.extractBetween(-3, 7, test5); + if(test5!=UNICODE_STRING("Now is ", 7)) { + errln("UnicodeString.extractBetween(-3, 7) did not pin properly."); + } + test1.extractBetween(11, 23, test5); if (test1.extract(60, 71, test6) != 9) { errln("UnicodeString.extract() failed to return the correct size of destination buffer for end of buffer.");