ICU-3064 Move the files to text package

X-SVN-Rev: 12965
This commit is contained in:
Ram Viswanadha 2003-08-27 21:13:15 +00:00
parent ace6bd29ca
commit 0ec174575d
12 changed files with 298 additions and 336 deletions

View file

@ -5,15 +5,15 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/IDNAReference.java,v $
* $Date: 2003/08/21 23:42:25 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:14 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
package com.ibm.icu.dev.test.stringprep;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.stringprep.ParseException;
/**
* @author ram
@ -117,17 +117,17 @@ public class IDNAReference {
}
public static StringBuffer convertToASCII(String src, int options)
throws ParseException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToASCII(iter,options);
}
public static StringBuffer convertToASCII(StringBuffer src, int options)
throws ParseException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToASCII(iter,options);
}
public static StringBuffer convertToASCII(UCharacterIterator srcIter, int options)
throws ParseException{
throws StringPrepParseException{
char[] caseFlags = null;
@ -168,17 +168,17 @@ public class IDNAReference {
/* populate the parseError struct */
if(srcIsLDH==false){
throw new ParseException( "The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException( "The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
(failPos>0) ? (failPos-1) : failPos);
}else if(processOut.charAt(0) == HYPHEN){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),0);
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),0);
}else{
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
(poLen>0) ? poLen-1 : poLen);
@ -202,27 +202,27 @@ public class IDNAReference {
//Step 6: copy the contents in b2 into dest
dest.append(lowerOut);
}else{
throw new ParseException("The input does not start with the ACE Prefix.",
ParseException.ACE_PREFIX_ERROR,processOut.toString(),0);
throw new StringPrepParseException("The input does not start with the ACE Prefix.",
StringPrepParseException.ACE_PREFIX_ERROR,processOut.toString(),0);
}
}
if(dest.length() > MAX_LABEL_LENGTH){
throw new ParseException("The labels in the input are too long. Length > 64.",
ParseException.LABEL_TOO_LONG_ERROR,dest.toString(),0);
throw new StringPrepParseException("The labels in the input are too long. Length > 64.",
StringPrepParseException.LABEL_TOO_LONG_ERROR,dest.toString(),0);
}
return dest;
}
public static StringBuffer convertIDNtoASCII(UCharacterIterator iter,int options)
throws ParseException{
throws StringPrepParseException{
return convertIDNToASCII(iter.getText(), options);
}
public static StringBuffer convertIDNtoASCII(StringBuffer str,int options)
throws ParseException{
throws StringPrepParseException{
return convertIDNToASCII(str.toString(), options);
}
public static StringBuffer convertIDNToASCII(String src,int options)
throws ParseException{
throws StringPrepParseException{
char[] srcArr = src.toCharArray();
StringBuffer result = new StringBuffer();
int sepIndex=0;
@ -243,17 +243,17 @@ public class IDNAReference {
}
public static StringBuffer convertToUnicode(String src, int options)
throws ParseException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToUnicode(iter,options);
}
public static StringBuffer convertToUnicode(StringBuffer src, int options)
throws ParseException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToUnicode(iter,options);
}
public static StringBuffer convertToUnicode(UCharacterIterator iter, int options)
throws ParseException{
throws StringPrepParseException{
char[] caseFlags = null;
@ -309,8 +309,8 @@ public class IDNAReference {
//step 7: verify
if(compareCaseInsensitiveASCII(processOut, toASCIIOut) !=0){
throw new ParseException("The verification step prescribed by the RFC 3491 failed",
ParseException.VERIFICATION_ERROR);
throw new StringPrepParseException("The verification step prescribed by the RFC 3491 failed",
StringPrepParseException.VERIFICATION_ERROR);
}
//step 8: return output of step 5
@ -324,17 +324,17 @@ public class IDNAReference {
|| processOut.charAt(processOut.length()-1) == HYPHEN){
if(srcIsLDH==false){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),
(failPos>0) ? (failPos-1) : failPos);
}else if(processOut.charAt(0) == HYPHEN){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),0);
}else{
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
processOut.length());
@ -346,15 +346,15 @@ public class IDNAReference {
}
}
public static StringBuffer convertIDNToUnicode(UCharacterIterator iter, int options)
throws ParseException{
throws StringPrepParseException{
return convertIDNToUnicode(iter.getText(), options);
}
public static StringBuffer convertIDNToUnicode(StringBuffer str, int options)
throws ParseException{
throws StringPrepParseException{
return convertIDNToUnicode(str.toString(), options);
}
public static StringBuffer convertIDNToUnicode(String src, int options)
throws ParseException{
throws StringPrepParseException{
char[] srcArr = src.toCharArray();
StringBuffer result = new StringBuffer();
@ -376,7 +376,7 @@ public class IDNAReference {
}
// TODO: optimize
public static int compare(StringBuffer s1, StringBuffer s2, int options)
throws ParseException{
throws StringPrepParseException{
if(s1==null || s2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}
@ -386,7 +386,7 @@ public class IDNAReference {
}
// TODO: optimize
public static int compare(String s1, String s2, int options)
throws ParseException{
throws StringPrepParseException{
if(s1==null || s2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}
@ -396,7 +396,7 @@ public class IDNAReference {
}
// TODO: optimize
public static int compare(UCharacterIterator i1, UCharacterIterator i2, int options)
throws ParseException{
throws StringPrepParseException{
if(i1==null || i2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/NFS4StringPrep.java,v $
* $Date: 2003/08/27 03:08:29 $
* $Revision: 1.2 $
* $Date: 2003/08/27 21:13:14 $
* $Revision: 1.3 $
*
*******************************************************************************
*/
@ -17,8 +17,8 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import com.ibm.icu.dev.test.TestUtil;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.stringprep.StringPrep;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.StringPrep;
import com.ibm.icu.text.UCharacterIterator;
/**
@ -78,7 +78,7 @@ public final class NFS4StringPrep {
}
private static byte[] prepare(byte[] src, StringPrep prep)
throws ParseException, UnsupportedEncodingException{
throws StringPrepParseException, UnsupportedEncodingException{
String s = new String(src, "UTF-8");
UCharacterIterator iter = UCharacterIterator.getInstance(s);
StringBuffer out = prep.prepare(iter,StringPrep.NONE);
@ -86,17 +86,17 @@ public final class NFS4StringPrep {
}
public static byte[] cs_prepare(byte[] src, boolean caseInsensitive)
throws IOException, ParseException, UnsupportedEncodingException{
throws IOException, StringPrepParseException, UnsupportedEncodingException{
NFS4StringPrep prep = getInstance();
if(caseInsensitive){
return prepare(src, prep.nfscsi);
}else{
return prepare(src,prep.nfscsi);
return prepare(src, prep.nfscss);
}
}
public static byte[] cis_prepare(byte[] src)
throws IOException, ParseException, UnsupportedEncodingException{
throws IOException, StringPrepParseException, UnsupportedEncodingException{
NFS4StringPrep prep = getInstance();
return prepare(src, prep.nfscis);
}
@ -140,7 +140,7 @@ public final class NFS4StringPrep {
private static final char AT_SIGN = '@';
public static byte[] mixed_prepare(byte[] src)
throws IOException, ParseException, UnsupportedEncodingException{
throws IOException, StringPrepParseException, UnsupportedEncodingException{
String s = new String(src, "UTF-8");
int index = s.indexOf(AT_SIGN);
StringBuffer out = new StringBuffer();
@ -151,7 +151,7 @@ public final class NFS4StringPrep {
int i= findStringIndex(special_prefixes, prefixString);
String suffixString = s.substring(index+1, s.length());
if(i>-1 && !suffixString.equals("")){
throw new ParseException("Suffix following a special index", ParseException.INVALID_CHAR_FOUND);
throw new StringPrepParseException("Suffix following a special index", StringPrepParseException.INVALID_CHAR_FOUND);
}
UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/NamePrepTransform.java,v $
* $Date: 2003/08/21 23:42:21 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:14 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -17,7 +17,7 @@ import java.util.ResourceBundle;
import com.ibm.icu.impl.ICULocaleData;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.lang.UCharacterDirection;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.text.Transliterator;
@ -97,11 +97,11 @@ public class NamePrepTransform {
*/
public StringBuffer prepare(UCharacterIterator src,
int options)
throws ParseException{
throws StringPrepParseException{
return prepare(src.getText(),options);
}
private String map ( String src, int options)
throws ParseException{
throws StringPrepParseException{
// map
boolean allowUnassigned = (boolean) ((options & ALLOW_UNASSIGNED)>0);
String caseMapOut = transform.mapTransform.transliterate(src);
@ -109,14 +109,14 @@ public class NamePrepTransform {
int ch;
while((ch=iter.nextCodePoint())!=UCharacterIterator.DONE){
if(transform.unassignedSet.contains(ch)==true && allowUnassigned ==false){
throw new ParseException("An unassigned code point was found in the input",
ParseException.UNASSIGNED_ERROR);
throw new StringPrepParseException("An unassigned code point was found in the input",
StringPrepParseException.UNASSIGNED_ERROR);
}
}
return caseMapOut;
}
public StringBuffer prepare(String src,int options)
throws ParseException{
throws StringPrepParseException{
int ch;
String mapOut = map(src,options);
@ -131,8 +131,8 @@ public class NamePrepTransform {
if(transform.prohibitedSet.contains(ch)==true){
throw new ParseException("A prohibited code point was found in the input",
ParseException.PROHIBITED_ERROR,
throw new StringPrepParseException("A prohibited code point was found in the input",
StringPrepParseException.PROHIBITED_ERROR,
iter.getText(),iter.getIndex());
}
@ -152,8 +152,8 @@ public class NamePrepTransform {
// satisfy 2
if( leftToRight == true && rightToLeft == true){
throw new ParseException("The input does not conform to the rules for BiDi code points.",
ParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
}
//satisfy 3
@ -161,8 +161,8 @@ public class NamePrepTransform {
!((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
){
throw new ParseException("The input does not conform to the rules for BiDi code points.",
ParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),(rtlPos>ltrPos) ? rtlPos : ltrPos);
}
return new StringBuffer(mapOut);

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/PunycodeReference.java,v $
* $Date: 2003/08/21 23:42:25 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:14 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -32,7 +32,7 @@ http://www.nicemice.net/amc/
*/
package com.ibm.icu.dev.test.stringprep;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.text.UTF16;
@ -225,7 +225,7 @@ public final class PunycodeReference {
}
public static final StringBuffer encode(StringBuffer input,char[] case_flags)
throws ParseException{
throws StringPrepParseException{
int[] in = new int[input.length()];
int inLen = 0;
int ch;
@ -257,21 +257,21 @@ public final class PunycodeReference {
}
private static void getException(int rc)
throws ParseException{
throws StringPrepParseException{
switch(rc){
case punycode_big_output:
throw new ParseException("The output capacity was not sufficient.",ParseException.BUFFER_OVERFLOW_ERROR);
throw new StringPrepParseException("The output capacity was not sufficient.",StringPrepParseException.BUFFER_OVERFLOW_ERROR);
case punycode_bad_input:
throw new ParseException("Illegal char found in the input",ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found in the input",StringPrepParseException.ILLEGAL_CHAR_FOUND);
case punycode_overflow:
throw new ParseException("Invalid char found in the input",ParseException.INVALID_CHAR_FOUND);
throw new StringPrepParseException("Invalid char found in the input",StringPrepParseException.INVALID_CHAR_FOUND);
}
}
private static final int MAX_BUFFER_SIZE = 100;
public static final StringBuffer decode(StringBuffer input,char[] case_flags)
throws ParseException{
throws StringPrepParseException{
char[] in = input.toString().toCharArray();
int[] outLen = new int[1];
outLen[0] = MAX_BUFFER_SIZE;

View file

@ -5,15 +5,15 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/TestData.java,v $
* $Date: 2003/08/21 23:42:25 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:15 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
package com.ibm.icu.dev.test.stringprep;
import com.ibm.icu.stringprep.IDNA;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.text.IDNA;
import com.ibm.icu.text.StringPrepParseException;
/**
* @author ram
@ -286,7 +286,7 @@ public class TestData {
},
"www.XN--8mb5595fsoa28orucya378bqre2tcwop06c5qbw82a1rffmae0361dea96b.com",
new ParseException("",ParseException.PROHIBITED_ERROR),
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR),
false, true, true),
new ErrorCase( new char[]{
@ -298,7 +298,7 @@ public class TestData {
},
"www.XN--6lA2Bz548Fj1GuA391Bf1Gb1N59Ab29A7iA.com",
new ParseException("",ParseException.UNASSIGNED_ERROR),
new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR),
false, true, true
),
new ErrorCase( new char[]{
@ -310,7 +310,7 @@ public class TestData {
},
"www.xn--ghBGI4851OiyA33VqrD6Az86C4qF83CtRv93D5xBk15AzfG0nAgA0578DeA71C.com",
new ParseException("",ParseException.CHECK_BIDI_ERROR),
new StringPrepParseException("",StringPrepParseException.CHECK_BIDI_ERROR),
false, true, true
),
new ErrorCase( new char[]{
@ -324,7 +324,7 @@ public class TestData {
},
"www.xn----b95Ew8SqA315Ao5FbuMlnNmhA.com",
new ParseException("",ParseException.STD3_ASCII_RULES_ERROR),
new StringPrepParseException("",StringPrepParseException.STD3_ASCII_RULES_ERROR),
true, true, false
),
new ErrorCase( new char[]{
@ -340,7 +340,7 @@ public class TestData {
},
/* wrong ACE-prefix followed by valid ACE-encoded ASCII */
"www.XY-----b91I0V65S96C2A355Cw1E5yCeQr19CsnP1mFfmAE0361DeA96B.com",
new ParseException("",ParseException.ACE_PREFIX_ERROR),
new StringPrepParseException("",StringPrepParseException.ACE_PREFIX_ERROR),
false, false, false
),
/* cannot verify U_IDNA_VERIFICATION_ERROR */
@ -354,7 +354,7 @@ public class TestData {
},
"www.xn--989AoMsVi5E83Db1D2A355Cv1E0vAk1DwRv93D5xBh15A0Dt30A5JpSD879Ccm6FeA98C.com",
new ParseException("",ParseException.LABEL_TOO_LONG_ERROR),
new StringPrepParseException("",StringPrepParseException.LABEL_TOO_LONG_ERROR),
false, true, true
),
new ErrorCase( new char[]{
@ -364,7 +364,7 @@ public class TestData {
},
"www.xn--01-tvdmo.com",
new ParseException("",ParseException.CHECK_BIDI_ERROR),
new StringPrepParseException("",StringPrepParseException.CHECK_BIDI_ERROR),
false, true, true
),
@ -375,7 +375,7 @@ public class TestData {
},
"www.XN--ghbgi278xia.com",
new ParseException("",ParseException.PROHIBITED_ERROR),
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR),
false, true, true
),
new ErrorCase( new char[] {
@ -385,7 +385,7 @@ public class TestData {
},
"www.-abcde.com",
new ParseException("",ParseException.STD3_ASCII_RULES_ERROR),
new StringPrepParseException("",StringPrepParseException.STD3_ASCII_RULES_ERROR),
true, true, false
),
new ErrorCase( new char[] {
@ -395,7 +395,7 @@ public class TestData {
},
"www.abcde-.com",
new ParseException("",ParseException.STD3_ASCII_RULES_ERROR),
new StringPrepParseException("",StringPrepParseException.STD3_ASCII_RULES_ERROR),
true, true, false
),
new ErrorCase( new char[]{
@ -405,7 +405,7 @@ public class TestData {
},
"www.abcde@.com",
new ParseException("",ParseException.STD3_ASCII_RULES_ERROR),
new StringPrepParseException("",StringPrepParseException.STD3_ASCII_RULES_ERROR),
true, true, false
),
@ -469,55 +469,55 @@ public class TestData {
"Non-ASCII multibyte space character U+1680",
"\u00E1\u009A\u0080", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Non-ASCII 8bit control character U+0085",
"\u00C2\u0085", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Non-ASCII multibyte control character U+180E",
"\u00E1\u00A0\u008E", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Non-ASCII control character U+1D175",
"\u00F0\u009D\u0085\u00B5", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Plane 0 private use character U+F123",
"\u00EF\u0084\u00A3", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Plane 15 private use character U+F1234",
"\u00F3\u00B1\u0088\u00B4", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Plane 16 private use character U+10F234",
"\u00F4\u008F\u0088\u00B4", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Non-character code point U+8FFFE",
"\u00F2\u008F\u00BF\u00BE", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Non-character code point U+10FFFF",
"\u00F4\u008F\u00BF\u00BF", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
/*
{
@ -530,13 +530,13 @@ public class TestData {
"Non-plain text character U+FFFD",
"\u00EF\u00BF\u00BD", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Ideographic description character U+2FF5",
"\u00E2\u00BF\u00B5", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Display property character U+0341",
@ -550,38 +550,38 @@ public class TestData {
"Left-to-right mark U+200E",
"\u00E2\u0080\u008E", "\u00CC\u0081",
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Deprecated U+202A",
"\u00E2\u0080\u00AA", "\u00CC\u0081",
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Language tagging character U+E0001",
"\u00F3\u00A0\u0080\u0081", "\u00CC\u0081",
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Language tagging character U+E0042",
"\u00F3\u00A0\u0081\u0082", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.PROHIBITED_ERROR)
new StringPrepParseException("",StringPrepParseException.PROHIBITED_ERROR)
),
new ConformanceTestCase(
"Bidi: RandALCat character U+05BE and LCat characters",
"\u0066\u006F\u006F\u00D6\u00BE\u0062\u0061\u0072", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.CHECK_BIDI_ERROR)
new StringPrepParseException("",StringPrepParseException.CHECK_BIDI_ERROR)
),
new ConformanceTestCase(
"Bidi: RandALCat character U+FD50 and LCat characters",
"\u0066\u006F\u006F\u00EF\u00B5\u0090\u0062\u0061\u0072", null,
"Nameprep",IDNA.DEFAULT ,
new ParseException("",ParseException.CHECK_BIDI_ERROR)
new StringPrepParseException("",StringPrepParseException.CHECK_BIDI_ERROR)
),
new ConformanceTestCase(
"Bidi: RandALCat character U+FB38 and LCat characters",
@ -593,7 +593,7 @@ public class TestData {
"Bidi: RandALCat without trailing RandALCat U+0627 U+0031",
"\u00D8\u00A7\u0031", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.CHECK_BIDI_ERROR)
new StringPrepParseException("",StringPrepParseException.CHECK_BIDI_ERROR)
),
new ConformanceTestCase(
"Bidi: RandALCat character U+0627 U+0031 U+0628",
@ -605,7 +605,7 @@ public class TestData {
"Unassigned code point U+E0002",
"\u00F3\u00A0\u0080\u0082", null,
"Nameprep", IDNA.DEFAULT,
new ParseException("",ParseException.UNASSIGNED_ERROR)
new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR)
),
/* // Invalid UTF-8

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/TestIDNA.java,v $
* $Date: 2003/08/21 23:42:21 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:14 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -16,9 +16,9 @@ import java.io.InputStream;
import java.util.Random;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.stringprep.IDNA;
import com.ibm.icu.stringprep.StringPrep;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.text.IDNA;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.StringPrep;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.impl.LocaleUtility;
@ -31,7 +31,7 @@ public class TestIDNA extends TestFmwk {
public static void main(String[] args) throws Exception {
new TestIDNA().run(args);
}
private ParseException unassignedException = new ParseException("",ParseException.UNASSIGNED_ERROR);
private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);
public void TestToUnicode() throws Exception{
for(int i=0; i<TestData.asciiIn.length; i++){
// test StringBuffer toUnicode
@ -94,7 +94,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -109,7 +109,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -124,7 +124,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -145,7 +145,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -159,7 +159,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -174,7 +174,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -194,7 +194,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +"\n Got: "+ ex.toString() +"\n Expected: " +ex.toString());
}
@ -209,7 +209,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -224,7 +224,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -244,7 +244,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToIDNASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToIDNASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -258,7 +258,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToIDNASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToIDNASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -274,7 +274,7 @@ public class TestIDNA extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -308,7 +308,7 @@ public class TestIDNA extends TestFmwk {
if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(testCase.expected == null || !ex.equals(testCase.expected)){
errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
}
@ -324,7 +324,7 @@ public class TestIDNA extends TestFmwk {
if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(testCase.expected == null || !ex.equals(testCase.expected)){
errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
}
@ -631,20 +631,20 @@ public class TestIDNA extends TestFmwk {
StringBuffer label = src;
ParseException expected = null;
StringPrepParseException expected = null;
StringBuffer ascii = null;
int options = IDNA.DEFAULT;
logln("Comparing idnaref_toASCII with uidna_toASCII for input: " + prettify(label));
try{
ascii = IDNAReference.convertToASCII(label, options);
}catch( ParseException e){
}catch( StringPrepParseException e){
expected = e;
if(e.equals(unassignedException)){
options = IDNA.ALLOW_UNASSIGNED;
expected = null;
try{
ascii = IDNAReference.convertToASCII(label, options);
}catch( ParseException ex){
}catch( StringPrepParseException ex){
expected = ex;
}
}
@ -662,14 +662,14 @@ public class TestIDNA extends TestFmwk {
options = IDNA.DEFAULT;
try{
uni = IDNAReference.convertToUnicode(ascii, options);
}catch( ParseException e ){
}catch( StringPrepParseException e ){
expected = e;
if(expected.equals(unassignedException)){
options = IDNA.ALLOW_UNASSIGNED;
expected = null;
try{
uni = IDNAReference.convertToUnicode(ascii, options);
}catch(ParseException ex){
}catch(StringPrepParseException ex){
expected = ex;
}
}

View file

@ -5,15 +5,15 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/stringprep/TestIDNARef.java,v $
* $Date: 2003/08/21 23:42:27 $
* $Revision: 1.1 $
* $Date: 2003/08/27 21:13:15 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
package com.ibm.icu.dev.test.stringprep;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.stringprep.ParseException;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.UCharacterIterator;
/**
@ -26,7 +26,7 @@ public class TestIDNARef extends TestFmwk {
public static void main(String[] args) throws Exception {
new TestIDNARef().run(args);
}
private ParseException unassignedException = new ParseException("",ParseException.UNASSIGNED_ERROR);
private StringPrepParseException unassignedException = new StringPrepParseException("",StringPrepParseException.UNASSIGNED_ERROR);
public void TestToUnicode() throws Exception{
for(int i=0; i<TestData.asciiIn.length; i++){
// test StringBuffer toUnicode
@ -89,7 +89,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -104,7 +104,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -119,7 +119,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("Did not get the expected exception for source: " + prettify(src) +" Got: "+ ex.toString());
}
@ -140,7 +140,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -154,7 +154,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToUnicode did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -169,7 +169,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("Did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -189,7 +189,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -204,7 +204,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -219,7 +219,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !expectedException.equals(ex)){
errln("convertToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -239,7 +239,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -253,7 +253,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertToIDNAReferenceSCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -269,7 +269,7 @@ public class TestIDNARef extends TestFmwk {
if(expectedException!=null && !unassignedException.equals(expectedException)){
errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(expectedException == null || !ex.equals(expectedException)){
errln("convertIDNToASCII did not get the expected exception for source: " +src +" Got: "+ ex.toString());
}
@ -302,7 +302,7 @@ public class TestIDNARef extends TestFmwk {
if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(testCase.expected == null || !ex.equals(testCase.expected)){
errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
}
@ -318,7 +318,7 @@ public class TestIDNARef extends TestFmwk {
if(testCase.expected!=null && !unassignedException.equals(testCase.expected)){
errln("Did not get the expected exception. The operation succeeded!");
}
}catch(ParseException ex){
}catch(StringPrepParseException ex){
if(testCase.expected == null || !ex.equals(testCase.expected)){
errln("Did not get the expected exception for source: " +testCase.input +" Got: "+ ex.toString());
}

View file

@ -1,19 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><!-- Copyright (C) 2003, International Business Machines Corporation and
others. All Rights Reserved.
$Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/stringprep/Attic/package.html,v $
$Revision: 1.1 $
$Date: 2003/08/27 03:09:08 $
-->
<title>C:\cvs\icu4j\src\com\ibm\demo\package.html</title>
</head>
<body bgcolor="white">
<p>StringPrep and IDNA support.</p>
</body>
</html>

View file

@ -3,19 +3,18 @@
* Copyright (C) 2003-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/stringprep/Attic/IDNA.java,v $
* $Date: 2003/08/27 03:09:08 $
* $Revision: 1.2 $
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/IDNA.java,v $
* $Date: 2003/08/27 21:12:04 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.icu.stringprep;
package com.ibm.icu.text;
import java.io.IOException;
import java.io.InputStream;
import com.ibm.icu.impl.LocaleUtility;
import com.ibm.icu.text.UCharacterIterator;
/**
*
@ -78,16 +77,23 @@ public final class IDNA {
*/
public static final int USE_STD3_RULES = 0x0002;
private static StringPrep prep = null;
// static final singleton object that is initialized
// at class initialization time, hence guaranteed to
// be initialized and thread safe
private static final IDNA singleton = new IDNA();
private static synchronized void loadInstance()
throws IOException{
if(prep==null){
// The NamePrep profile object
private StringPrep namePrep;
/* private constructor to prevent construction of the object */
private IDNA(){
try{
InputStream stream = LocaleUtility.getImplDataResourceAsStream("uidna.spp");
prep = StringPrep.getInstance(stream);
namePrep = StringPrep.getInstance(stream);
stream.close();
}
}catch (IOException e){
throw new RuntimeException(e.toString());
}
}
private static boolean startsWithPrefix(StringBuffer src){
@ -140,32 +146,10 @@ public final class IDNA {
}
}
}
private static int compareCaseInsensitiveASCII(String s1, String s2){
char c1,c2;
int rc;
for(int i =0;/* no condition */;i++) {
/* If we reach the ends of both strings then they match */
if(i == s1.length()) {
return 0;
}
c1 = s1.charAt(i);
c2 = s2.charAt(i);
/* Case-insensitive comparison */
if(c1!=c2) {
rc=(int)toASCIILower(c1)-(int)toASCIILower(c2);
if(rc!=0) {
return rc;
}
}
}
}
private static int getSeparatorIndex(char[] src,int start, int limit)
throws IOException{
loadInstance();
private static int getSeparatorIndex(char[] src,int start, int limit){
for(; start<limit;start++){
if(prep.isLabelSeparator(src[start])){
if(isLabelSeparator(src[start])){
return start;
}
}
@ -173,6 +157,26 @@ public final class IDNA {
return start;
}
/*
private static int getSeparatorIndex(UCharacterIterator iter){
int currentIndex = iter.getIndex();
int separatorIndex = 0;
int ch;
while((ch=iter.next())!= UCharacterIterator.DONE){
if(isLabelSeparator(ch)){
separatorIndex = iter.getIndex();
iter.setIndex(currentIndex);
return separatorIndex;
}
}
// reset index
iter.setIndex(currentIndex);
// we have not found the separator just return the length
}
*/
private static boolean isLDHChar(int ch){
// high runner case
if(ch>0x007A){
@ -189,9 +193,26 @@ public final class IDNA {
return false;
}
/* private constructor to prevent construction of the object */
private IDNA(){}
/**
* Ascertain if the given code point is a label separator as
* defined by the IDNA RFC
*
* @param ch The code point to be ascertained
* @return true if the char is a label separator
* @draft ICU 2.8
*/
public static boolean isLabelSeparator(int ch){
switch(ch){
case 0x002e:
case 0x3002:
case 0xFF0E:
case 0xFF61:
return true;
default:
return false;
}
}
/**
* This function implements the ToASCII operation as defined in the IDNA RFC.
* This operation is done on <b>single labels</b> before sending it to something that expects
@ -215,11 +236,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToASCII(String src, int options)
throws ParseException, IOException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToASCII(iter,options);
}
@ -247,11 +267,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToASCII(StringBuffer src, int options)
throws ParseException, IOException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToASCII(iter,options);
}
@ -279,13 +298,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToASCII(UCharacterIterator srcIter, int options)
throws ParseException, IOException{
//load the data
loadInstance();
throws StringPrepParseException{
boolean[] caseFlags = null;
@ -299,7 +315,7 @@ public final class IDNA {
int failPos = -1;
// step 2
StringBuffer processOut = prep.prepare(srcIter,options);
StringBuffer processOut = singleton.namePrep.prepare(srcIter,options);
int poLen = processOut.length();
StringBuffer dest = new StringBuffer();
// step 3 & 4
@ -325,17 +341,17 @@ public final class IDNA {
/* populate the parseError struct */
if(srcIsLDH==false){
throw new ParseException( "The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException( "The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
(failPos>0) ? (failPos-1) : failPos);
}else if(processOut.charAt(0) == HYPHEN){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),0);
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),0);
}else{
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
(poLen>0) ? poLen-1 : poLen);
@ -362,13 +378,13 @@ public final class IDNA {
dest.append(lowerOut);
}else{
throw new ParseException("The input does not start with the ACE Prefix.",
ParseException.ACE_PREFIX_ERROR,processOut.toString(),0);
throw new StringPrepParseException("The input does not start with the ACE Prefix.",
StringPrepParseException.ACE_PREFIX_ERROR,processOut.toString(),0);
}
}
if(dest.length() > MAX_LABEL_LENGTH){
throw new ParseException("The labels in the input are too long. Length > 64.",
ParseException.LABEL_TOO_LONG_ERROR,dest.toString(),0);
throw new StringPrepParseException("The labels in the input are too long. Length > 64.",
StringPrepParseException.LABEL_TOO_LONG_ERROR,dest.toString(),0);
}
return dest;
}
@ -401,11 +417,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNtoASCII(UCharacterIterator iter,int options)
throws ParseException, IOException{
public static StringBuffer convertIDNToASCII(UCharacterIterator iter,int options)
throws StringPrepParseException{
return convertIDNToASCII(iter.getText(), options);
}
@ -437,11 +452,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNtoASCII(StringBuffer str,int options)
throws ParseException, IOException{
public static StringBuffer convertIDNToASCII(StringBuffer str,int options)
throws StringPrepParseException{
return convertIDNToASCII(str.toString(), options);
}
@ -473,13 +487,11 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNToASCII(String src,int options)
throws ParseException, IOException{
//load the data
loadInstance();
throws StringPrepParseException{
char[] srcArr = src.toCharArray();
StringBuffer result = new StringBuffer();
int sepIndex=0;
@ -523,11 +535,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToUnicode(String src, int options)
throws ParseException, IOException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToUnicode(iter,options);
}
@ -555,11 +566,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToUnicode(StringBuffer src, int options)
throws ParseException, IOException{
throws StringPrepParseException{
UCharacterIterator iter = UCharacterIterator.getInstance(src);
return convertToUnicode(iter,options);
}
@ -587,13 +597,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertToUnicode(UCharacterIterator iter, int options)
throws ParseException, IOException{
//load the data
loadInstance();
throws StringPrepParseException{
boolean[] caseFlags = null;
@ -622,7 +629,7 @@ public final class IDNA {
if(srcIsASCII == false){
// step 2: process the string
iter.setIndex(saveIndex);
processOut = prep.prepare(iter,options);
processOut = singleton.namePrep.prepare(iter,options);
}else{
//just point to source
@ -649,8 +656,8 @@ public final class IDNA {
//step 7: verify
if(compareCaseInsensitiveASCII(processOut, toASCIIOut) !=0){
throw new ParseException("The verification step prescribed by the RFC 3491 failed",
ParseException.VERIFICATION_ERROR);
throw new StringPrepParseException("The verification step prescribed by the RFC 3491 failed",
StringPrepParseException.VERIFICATION_ERROR);
}
//step 8: return output of step 5
@ -664,17 +671,17 @@ public final class IDNA {
|| processOut.charAt(processOut.length()-1) == HYPHEN){
if(srcIsLDH==false){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(),
(failPos>0) ? (failPos-1) : failPos);
}else if(processOut.charAt(0) == HYPHEN){
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),0);
}else{
throw new ParseException("The input does not conform to the STD 3 ASCII rules",
ParseException.STD3_ASCII_RULES_ERROR,
throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules",
StringPrepParseException.STD3_ASCII_RULES_ERROR,
processOut.toString(),
processOut.length());
@ -711,11 +718,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNToUnicode(UCharacterIterator iter, int options)
throws ParseException, IOException{
throws StringPrepParseException{
return convertIDNToUnicode(iter.getText(), options);
}
@ -744,11 +750,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNToUnicode(StringBuffer str, int options)
throws ParseException, IOException{
throws StringPrepParseException{
return convertIDNToUnicode(str.toString(), options);
}
@ -777,11 +782,10 @@ public final class IDNA {
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
public static StringBuffer convertIDNToUnicode(String src, int options)
throws ParseException, IOException{
throws StringPrepParseException{
char[] srcArr = src.toCharArray();
StringBuffer result = new StringBuffer();
@ -828,12 +832,11 @@ public final class IDNA {
* the operation will fail with ParseException
* @return 0 if the strings are equal, > 0 if s1 > s2 and < 0 if s1 < s2
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
// TODO: optimize
public static int compare(StringBuffer s1, StringBuffer s2, int options)
throws ParseException, IOException{
throws StringPrepParseException{
if(s1==null || s2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}
@ -868,12 +871,11 @@ public final class IDNA {
* the operation will fail with ParseException
* @return 0 if the strings are equal, > 0 if s1 > s2 and < 0 if s1 < s2
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
// TODO: optimize
public static int compare(String s1, String s2, int options)
throws ParseException, IOException{
throws StringPrepParseException{
if(s1==null || s2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}
@ -907,12 +909,11 @@ public final class IDNA {
* the operation will fail with ParseException
* @return 0 if the strings are equal, > 0 if i1 > i2 and < 0 if i1 < i2
* @throws ParseException
* @throws IOException
* @draft ICU 2.8
*/
// TODO: optimize
public static int compare(UCharacterIterator i1, UCharacterIterator i2, int options)
throws ParseException, IOException{
throws StringPrepParseException{
if(i1==null || i2 == null){
throw new IllegalArgumentException("One of the source buffers is null");
}

View file

@ -4,16 +4,15 @@
* others. All Rights Reserved. *
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/stringprep/Attic/Punycode.java,v $
* $Date: 2003/08/27 03:09:08 $
* $Revision: 1.2 $
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Punycode.java,v $
* $Date: 2003/08/27 21:12:04 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.icu.stringprep;
package com.ibm.icu.text;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.text.UTF16;
/**
* Ported code from ICU punycode.c
@ -138,7 +137,7 @@ final class Punycode {
* @return
* @throws ParseException
*/
public static StringBuffer encode(StringBuffer src, boolean[] caseFlags) throws ParseException{
public static StringBuffer encode(StringBuffer src, boolean[] caseFlags) throws StringPrepParseException{
int[] cpBuffer = new int[MAX_CP_COUNT];
int n, delta, handledCPCount, basicLength, destLength, bias, j, m, q, k, t, srcCPCount;
@ -178,7 +177,7 @@ final class Punycode {
n|=UCharacter.getCodePoint(c, c2);
} else {
/* error: unmatched surrogate */
throw new ParseException("Illegal char found",ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found",StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
cpBuffer[srcCPCount++]=n;
}
@ -299,7 +298,7 @@ final class Punycode {
* @throws ParseException
*/
public static StringBuffer decode(StringBuffer src, boolean[] caseFlags)
throws ParseException{
throws StringPrepParseException{
int srcLength = src.length();
StringBuffer result = new StringBuffer();
int n, destLength, i, bias, basicLength, j, in, oldi, w, k, digit, t,
@ -326,7 +325,7 @@ final class Punycode {
while(j>0) {
b=src.charAt(--j);
if(!isBasic(b)) {
throw new ParseException("Illegal char found", ParseException.INVALID_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.INVALID_CHAR_FOUND);
}
if(j<destCapacity) {
@ -361,16 +360,16 @@ final class Punycode {
*/
for(oldi=i, w=1, k=BASE; /* no condition */; k+=BASE) {
if(in>=srcLength) {
throw new ParseException("Illegal char found", ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
digit=basicToDigit[(byte)src.charAt(in++)];
if(digit<0) {
throw new ParseException("Invalid char found", ParseException.INVALID_CHAR_FOUND);
throw new StringPrepParseException("Invalid char found", StringPrepParseException.INVALID_CHAR_FOUND);
}
if(digit>(0x7fffffff-i)/w) {
/* integer overflow */
throw new ParseException("Illegal char found", ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
i+=digit*w;
@ -386,7 +385,7 @@ final class Punycode {
if(w>0x7fffffff/(BASE-t)) {
/* integer overflow */
throw new ParseException("Illegal char found", ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
w*=BASE-t;
}
@ -405,7 +404,7 @@ final class Punycode {
*/
if(i/destCPCount>(0x7fffffff-n)) {
/* integer overflow */
throw new ParseException("Illegal char found", ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
n+=i/destCPCount;
@ -415,7 +414,7 @@ final class Punycode {
if(n>0x10ffff || isSurrogate(n)) {
/* Unicode code point overflow */
throw new ParseException("Illegal char found", ParseException.ILLEGAL_CHAR_FOUND);
throw new StringPrepParseException("Illegal char found", StringPrepParseException.ILLEGAL_CHAR_FOUND);
}
/* Insert n at position i of the output: */

View file

@ -3,13 +3,13 @@
* Copyright (C) 2003-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/stringprep/Attic/StringPrep.java,v $
* $Date: 2003/08/27 03:09:08 $
* $Revision: 1.2 $
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/StringPrep.java,v $
* $Date: 2003/08/27 21:12:04 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.icu.stringprep;
package com.ibm.icu.text;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
@ -19,9 +19,6 @@ import java.io.InputStream;
import com.ibm.icu.impl.CharTrie;
import com.ibm.icu.impl.StringPrepDataReader;
import com.ibm.icu.impl.Trie;
import com.ibm.icu.text.Normalizer;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.util.VersionInfo;
import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.lang.UCharacterDirection;
@ -29,11 +26,11 @@ import com.ibm.icu.lang.UCharacterDirection;
/**
* StringPrep API implements the StingPrep framework as described by RFC 3454.
* StringPrep prepares Unicode strings for use in network protocols.
* Profiles of StingPrep are set of rules and data according to with the
* Profiles of StingPrep are set of rules and data according to which the
* Unicode Strings are prepared. Each profiles contains tables which describe
* how a code point should be treated. The tables are broadly classied into
* <ul>
* <li> Unassinged Table: Contains code points that are unassigned
* <li> Unassigned Table: Contains code points that are unassigned
* in the Unicode Version supported by StringPrep. Currently
* RFC 3454 supports Unicode 3.2. </li>
* <li> Prohibited Table: Contains code points that are prohibted from
@ -48,7 +45,7 @@ import com.ibm.icu.lang.UCharacterDirection;
* <li> Normalize: Possibly normalize the result of step 1 using Unicode
* normalization. </li>
* <li> Prohibit: Check for any characters that are not allowed in the
* output. If any are found, return an error.</li>
* output. If any are found, return an error.</li>
* <li> Check bidi: Possibly check for right-to-left characters, and if
* any are found, make sure that the whole string satisfies the
* requirements for bidirectional strings. If the string does not
@ -61,15 +58,15 @@ public final class StringPrep {
/**
* Option to prohibit processing of unassigned code points in the input
*
* @see usprep_prepare
* @see prepare
* @draft ICU 2.8
*/
public static final int NONE = 0x0000;
public static final int DEFAULT = 0x0000;
/**
* Option to allow processing of unassigned code points in the input
*
* @see usprep_prepare
* @see prepare
* @draft ICU 2.8
*/
public static final int ALLOW_UNASSIGNED = 0x0001;
@ -246,7 +243,7 @@ public final class StringPrep {
private StringBuffer map( UCharacterIterator iter, int options)
throws ParseException{
throws StringPrepParseException{
Values val = new Values();
char result = 0;
@ -261,8 +258,8 @@ public final class StringPrep {
// check if the source codepoint is unassigned
if(val.type == UNASSIGNED && allowUnassigned == false){
throw new ParseException("An unassigned code point was found in the input",
ParseException.UNASSIGNED_ERROR,
throw new StringPrepParseException("An unassigned code point was found in the input",
StringPrepParseException.UNASSIGNED_ERROR,
iter.getText(),iter.getIndex());
}else if((val.type == MAP)){
int index, length;
@ -303,15 +300,15 @@ public final class StringPrep {
private StringBuffer normalize(StringBuffer src){
return new StringBuffer(Normalizer.normalize(src.toString(),Normalizer.NFKC,Normalizer.UNICODE_3_2));
}
protected boolean isLabelSeparator(int ch){
/*
boolean isLabelSeparator(int ch){
int result = getCodePointValue(ch);
if( (result & 0x07) == LABEL_SEPARATOR){
return true;
}
return false;
}
*/
/*
1) Map -- For each character in the input, check if it has a mapping
and, if so, replace it with its mapping.
@ -368,7 +365,7 @@ public final class StringPrep {
* @draft ICU 2.8
*/
public StringBuffer prepare(UCharacterIterator src, int options)
throws ParseException{
throws StringPrepParseException{
// map
StringBuffer mapOut = map(src,options);
@ -393,8 +390,8 @@ public final class StringPrep {
getValues(result,val);
if(val.type == PROHIBITED ){
throw new ParseException("A prohibited code point was found in the input",
ParseException.PROHIBITED_ERROR,iter.getText(),val.value);
throw new StringPrepParseException("A prohibited code point was found in the input",
StringPrepParseException.PROHIBITED_ERROR,iter.getText(),val.value);
}
direction = UCharacter.getDirection(ch);
@ -413,8 +410,8 @@ public final class StringPrep {
if(checkBiDi == true){
// satisfy 2
if( leftToRight == true && rightToLeft == true){
throw new ParseException("The input does not conform to the rules for BiDi code points.",
ParseException.CHECK_BIDI_ERROR,iter.getText(),
throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),
(rtlPos>ltrPos) ? rtlPos : ltrPos);
}
@ -423,8 +420,8 @@ public final class StringPrep {
!((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
){
throw new ParseException("The input does not conform to the rules for BiDi code points.",
ParseException.CHECK_BIDI_ERROR,iter.getText(),
throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.",
StringPrepParseException.CHECK_BIDI_ERROR,iter.getText(),
(rtlPos>ltrPos) ? rtlPos : ltrPos);
}
}

View file

@ -3,13 +3,15 @@
* Copyright (C) 2003-2004, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/stringprep/Attic/ParseException.java,v $
* $Date: 2003/08/27 03:09:08 $
* $Revision: 1.2 $
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/StringPrepParseException.java,v $
* $Date: 2003/08/27 21:12:04 $
* $Revision: 1.1 $
*
*****************************************************************************************
*/
package com.ibm.icu.stringprep;
package com.ibm.icu.text;
import java.text.ParseException;
/**
* Exception that signals an error has occurred while parsing the
@ -17,7 +19,7 @@ package com.ibm.icu.stringprep;
*
* @author Ram Viswanadha
*/
public class ParseException extends Exception {
public class StringPrepParseException extends ParseException {
/**
* @draft ICU 2.8
*/
@ -67,10 +69,9 @@ public class ParseException extends Exception {
* @param error The error that has occurred
* @draft ICU 2.8
*/
public ParseException(String message,int error){
super(message);
public StringPrepParseException(String message,int error){
super(message, -1);
this.error = error;
this.offset = -1;
this.line = 0;
}
@ -84,11 +85,10 @@ public class ParseException extends Exception {
* @param pos The position of error in the rules string
* @draft ICU 2.8
*/
public ParseException(String message,int error, String rules, int pos){
super(message);
public StringPrepParseException(String message,int error, String rules, int pos){
super(message, -1);
this.error = error;
setContext(rules,pos);
this.offset = -1;
this.line = 0;
}
/**
@ -98,22 +98,16 @@ public class ParseException extends Exception {
* @param error The error that has occurred
* @param rules The input rules string
* @param pos The position of error in the rules string
* @param offset The character offset to the error. If the line field is
* being used, then this offset is from the start of the line.
* If the line field is not being used, then this offset is from
* the start of the text.The default value of this field
* is -1.
* @param lineNumber The line number at which the error has occurred.
* If the parse engine is not using this field, it should set it to zero. Otherwise
* it should be a positive integer. The default value of this field
* is -1. It will be set to 0 if the code populating this struct is not
* using line numbers.
*/
public ParseException(String message, int error, String rules, int pos, int offset, int lineNumber){
super(message);
public StringPrepParseException(String message, int error, String rules, int pos, int lineNumber){
super(message, -1);
this.error = error;
setContext(rules,pos);
this.offset = offset;
setContext(rules,pos);
this.line = lineNumber;
}
/**
@ -126,10 +120,10 @@ public class ParseException extends Exception {
* @draft ICU 2.8
*/
public boolean equals(Object other){
if(!(other instanceof ParseException)){
if(!(other instanceof StringPrepParseException)){
return false;
}
return ((ParseException)other).error == this.error;
return ((StringPrepParseException)other).error == this.error;
}
/**
@ -161,16 +155,6 @@ public class ParseException extends Exception {
*/
private int line;
/**
* The character offset to the error. If the line field is
* being used, then this offset is from the start of the line.
* If the line field is not being used, then this offset is from
* the start of the text.The default value of this field
* is -1. It will be set to appropriate value by the code that
* populating the struct.
* @draft ICU 2.8
*/
private int offset;
/**
* Textual context before the error. Null-terminated.