ICU-3630 cover jsr 204 APIs where possible, also jb 3523 after a fashion

X-SVN-Rev: 14686
This commit is contained in:
Doug Felt 2004-03-11 16:51:51 +00:00
parent 46a1802eff
commit 77c134dc38
2 changed files with 69 additions and 8 deletions
icu4j/src/com/ibm/icu
dev/test/lang
text

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UTF16Test.java,v $
* $Date: 2002/10/28 21:59:23 $
* $Revision: 1.20 $
* $Date: 2004/03/11 16:51:50 $
* $Revision: 1.21 $
*
*******************************************************************************
*/
@ -1439,7 +1439,64 @@ public final class UTF16Test extends TestFmwk
e.printStackTrace();
}
}
public void TestNewString() {
final int[] codePoints = {
UCharacter.toCodePoint(UCharacter.MIN_HIGH_SURROGATE, UCharacter.MAX_LOW_SURROGATE),
UCharacter.toCodePoint(UCharacter.MAX_HIGH_SURROGATE, UCharacter.MIN_LOW_SURROGATE),
UCharacter.MAX_HIGH_SURROGATE,
'A',
-1,
};
final String cpString = "" +
UCharacter.MIN_HIGH_SURROGATE +
UCharacter.MAX_LOW_SURROGATE +
UCharacter.MAX_HIGH_SURROGATE +
UCharacter.MIN_LOW_SURROGATE +
UCharacter.MAX_HIGH_SURROGATE +
'A';
final int[][] tests = {
{ 0, 1, 0, 2 },
{ 0, 2, 0, 4 },
{ 1, 1, 2, 2 },
{ 1, 2, 2, 3 },
{ 1, 3, 2, 4 },
{ 2, 2, 4, 2 },
{ 2, 3, 0, -1 },
{ 4, 5, 0, -1 },
{ 3, -1, 0, -1 }
};
for (int i = 0; i < tests.length; ++i) {
int[] t = tests[i];
int s = t[0];
int c = t[1];
int rs = t[2];
int rc = t[3];
Exception e = null;
try {
String str = UTF16.newString(codePoints, s, c);
if (rc == -1 || !str.equals(cpString.substring(rs, rs+rc))) {
errln("failed codePoints iter: " + i + " start: " + s + " len: " + c);
}
continue;
}
catch (IndexOutOfBoundsException e1) {
e = e1;
}
catch (IllegalArgumentException e2) {
e = e2;
}
if (rc != -1) {
errln(e.getMessage());
}
}
}
// private data members ----------------------------------------------
private final static String INDEXOF_SUPPLEMENTARY_STRING_ =

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/UTF16.java,v $
* $Date: 2004/03/11 07:23:29 $
* $Revision: 1.35 $
* $Date: 2004/03/11 16:51:51 $
* $Revision: 1.36 $
*
*******************************************************************************
*/
@ -2299,16 +2299,20 @@ public final class UTF16
}
/**
* Cover JDK 1.5 API. Create String from an array of codePoints.
* Cover JDK 1.5 API. Create a String from an array of codePoints.
* @param codePoints the code array
* @param offset the start of the text in the code point array
* @param count the number of code points
* @return a String representing the code points between offset and count
* @throws IllegalArgumentException if an invalid code point is encountered
* @throws IndexOutOfBoundsException if the offset or count are out of bounds.
* @throws IndexOutOfBoundsException if the offset or count are out of bounds.
* @draft ICU 3.0
*/
public static String newString(int[] codePoints, int offset, int count) {
char[] chars = new char[codePoints.length];
if (count < 0) {
throw new IllegalArgumentException();
}
char[] chars = new char[count];
int w = 0;
for (int r = offset, e = offset + count; r < e; ++r) {
int cp = codePoints[r];