From 685da47d1af86e2206705e603ded5239c9ad6440 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Wed, 17 Jun 2009 22:11:57 +0000 Subject: [PATCH] ICU-6955 Fix BOCU-1 logical errors and add test case. X-SVN-Rev: 26128 --- icu4c/source/test/testdata/conversion.txt | 10 +++++++++- .../src/com/ibm/icu/charset/CharsetBOCU1.java | 13 ++++++------- icu4j/main/shared/data/testdata.jar | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/icu4c/source/test/testdata/conversion.txt b/icu4c/source/test/testdata/conversion.txt index 0fcd06a2588..0c0978d7141 100644 --- a/icu4c/source/test/testdata/conversion.txt +++ b/icu4c/source/test/testdata/conversion.txt @@ -811,7 +811,8 @@ conversion:table(nofallback) { :intvector{ 4, 6 }, :int{1}, :int{0}, "", ".", :bin{""} } - // Code Coverage for BOCU-1 + + // Improve Code Coverage for BOCU-1 { "BOCU-1", :bin{ 91fbc555fd6349 }, @@ -826,6 +827,13 @@ conversion:table(nofallback) { :intvector{}, :int{1}, :int{0}, "", ".", :bin{""} } + { + "BOCU-1", + :bin{ 5b4bccf9 }, + "\u000b", + :intvector{}, + :int{1}, :int{0}, "", "0", :bin{""} + } } } diff --git a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetBOCU1.java b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetBOCU1.java index ace38c89b52..83cc6c47abc 100644 --- a/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetBOCU1.java +++ b/icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetBOCU1.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2008, International Business Machines Corporation and * + * Copyright (C) 2008-2009, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -815,8 +815,7 @@ class CharsetBOCU1 extends CharsetICU { /* conversion "loop" similar to _SCSUToUnicodeWithOffsets() */ if(count>0 && byteIndex>0 && target.position()0) { - if(BOCU1_START_NEG_2 <=(c=source.get(source.position())) && c< BOCU1_START_POS_2) { + if(BOCU1_START_NEG_2 <=(c=source.get(source.position())&UConverterConstants.UNSIGNED_BYTE_MASK) && c< BOCU1_START_POS_2) { c = prev + (c-BOCU1_MIDDLE); if(c<0x3000) { target.put((char)c); @@ -965,10 +964,10 @@ class CharsetBOCU1 extends CharsetICU { ++nextSourceIndex; c = decodeBocu1TrailByte(1, source.get()); if(c<0 || ((c = prev + diff + c)&UConverterConstants.UNSIGNED_INT_MASK)>0x10ffff) { - bytes[0]= source.get(-2); - bytes[1]= source.get(-1); + bytes[0]= source.get(source.position()-2); + bytes[1]= source.get(source.position()-1); byteIndex = 2; - cr = CoderResult.malformedForLength(1); + cr = CoderResult.malformedForLength(2); break; } } else if(c == BOCU1_RESET) { diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar index ecbe5b50ed8..c1dd078c698 100755 --- a/icu4j/main/shared/data/testdata.jar +++ b/icu4j/main/shared/data/testdata.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:96abd036f2721efd98951b4065d3ac8041867dd1e127fc20f4547d1c5fcfe0db -size 772172 +oid sha256:e45a334fc1a57269c5a6365b5a074a3d3f41d7824cd9fa2900acda7377a1f182 +size 772209