diff --git a/icu4c/source/common/unicode/utext.h b/icu4c/source/common/unicode/utext.h index f3e41b0831a..8e83531754f 100644 --- a/icu4c/source/common/unicode/utext.h +++ b/icu4c/source/common/unicode/utext.h @@ -50,8 +50,8 @@ #include "unicode/utypes.h" -#include "unicode/rep.h" #ifdef XP_CPLUSPLUS +#include "unicode/rep.h" #include "unicode/unistr.h" #endif @@ -543,9 +543,9 @@ utext_extract(UText *ut, * @draft ICU 3.4 */ #define UTEXT_NEXT32FROM(ut, index) \ - ((index) >= (ut)->start && \ - (index) < (ut)->limit && \ - (ut)->chunk.UTF16Indexes && \ + ((index) >= (ut)->chunk.start && \ + (index) < (ut)->chunk.limit && \ + !(ut)->chunk.nonUTF16Indexes && \ (ut)->chunk.contents[(ut)->chunk.offset=(ut)->chunk.start+(index)] < 0xd800 ? \ (ut)->chunk.contents[((ut)->chunk.offset)++] : utext_next32From(ut, index)) @@ -559,11 +559,11 @@ utext_extract(UText *ut, * @draft ICU 3.4 */ #define UTEXT_PREVIOUS32FROM(ut, index) \ - ((index) > (ut)->start && \ - (index) <= (ut)->limit && \ - (ut)->chunk.UTF16Indexes && \ + ((index) > (ut)->chunk.start && \ + (index) <= (ut)->chunk.limit && \ + !(ut)->chunk.nonUTF16Indexes && \ (ut)->chunk.contents[(ut)->chunk.offset=(ut)->chunk.start+(index-1)] < 0xd800 ? \ - (ut)->chunk.contents[--((ut)->chunk.offset)] : utext_previous32From(ut, index)) + (ut)->chunk.contents[(ut)->chunk.offset] : utext_previous32From(ut, index)) @@ -1255,7 +1255,7 @@ enum { NULL, /* copy () */ \ NULL, NULL, /* map * 2 () */ \ NULL /* close () */ \ -}; +} U_CDECL_END diff --git a/icu4c/source/test/cintltst/Makefile.in b/icu4c/source/test/cintltst/Makefile.in index f2cdf32e90a..b99266114f9 100644 --- a/icu4c/source/test/cintltst/Makefile.in +++ b/icu4c/source/test/cintltst/Makefile.in @@ -52,7 +52,7 @@ cucdapi.o cucdtst.o custrtst.o cstrcase.o cutiltst.o nucnvtst.o nccbtst.o bocu1t cbiditst.o cbididat.o eurocreg.o udatatst.o utf16tst.o utransts.o \ ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o utf8tst.o ucmptst.o \ stdnmtst.o ctstdep.o usrchtst.o custrtrn.o sorttest.o trietest.o usettest.o uenumtst.o utmstest.o \ -idnatest.o nfsprep.o spreptst.o sprpdata.o hpmufn.o tracetst.o reapits.o +idnatest.o nfsprep.o spreptst.o sprpdata.o hpmufn.o tracetst.o reapits.o utexttst.o DEPS = $(OBJECTS:.o=.d) diff --git a/icu4c/source/test/cintltst/calltest.c b/icu4c/source/test/cintltst/calltest.c index 5c05489cb7a..3740b40e5c0 100644 --- a/icu4c/source/test/cintltst/calltest.c +++ b/icu4c/source/test/cintltst/calltest.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1996-2004, International Business Machines Corporation and + * Copyright (c) 1996-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -37,6 +37,8 @@ void addIDNATest(TestNode** root); void addHeapMutexTest(TestNode **root); void addUTraceTest(TestNode** root); void addURegexTest(TestNode** root); +void addUTextTest(TestNode** root); + void addAllTests(TestNode** root) { @@ -73,5 +75,6 @@ void addAllTests(TestNode** root) #if !UCONFIG_NO_REGULAR_EXPRESSIONS addURegexTest(root); #endif + addUTextTest(root); } diff --git a/icu4c/source/test/cintltst/cintltst.vcproj b/icu4c/source/test/cintltst/cintltst.vcproj index 00c2020a40a..94928310d10 100644 --- a/icu4c/source/test/cintltst/cintltst.vcproj +++ b/icu4c/source/test/cintltst/cintltst.vcproj @@ -342,9 +342,6 @@ - - @@ -428,6 +425,9 @@ + + @@ -494,6 +494,9 @@ + + diff --git a/icu4c/source/test/intltest/utxttest.cpp b/icu4c/source/test/intltest/utxttest.cpp index 873513ceac0..1e0411fdcb6 100644 --- a/icu4c/source/test/intltest/utxttest.cpp +++ b/icu4c/source/test/intltest/utxttest.cpp @@ -221,6 +221,33 @@ void UTextTest::TestAccess(const UnicodeString &us, UText *ut, int cpCount, m *c foundIndex = utext_getIndex(ut); TEST_ASSERT(foundIndex == 0); + foundC = utext_previous32(ut); + TEST_ASSERT(foundC == U_SENTINEL); + foundIndex = utext_getIndex(ut); + TEST_ASSERT(foundIndex == 0); + + + // And again, with the macros + utext_setIndex(ut, len); + for (i=cpCount-1; i>=0; i--) { + expectedC = cpMap[i].cp; + expectedIndex = cpMap[i].nativeIdx; + foundC = UTEXT_PREVIOUS32(ut); + foundIndex = utext_getIndex(ut); + TEST_ASSERT(expectedIndex == foundIndex); + TEST_ASSERT(expectedC == foundC); + if (gFailed) { + return; + } + } + + // + // Backwards iteration, above, should have left our iterator + // position at zero, and continued backwards iterationshould fail. + // + foundIndex = utext_getIndex(ut); + TEST_ASSERT(foundIndex == 0); + foundC = utext_previous32(ut); TEST_ASSERT(foundC == U_SENTINEL); foundIndex = utext_getIndex(ut); @@ -258,6 +285,32 @@ void UTextTest::TestAccess(const UnicodeString &us, UText *ut, int cpCount, m *c } } + cpIndex = 0; + for (i=0; i