ICU-6238 Support standard stringprep profiles in ICU4J. Merging changes from the work branch to the trunk.

X-SVN-Rev: 25358
This commit is contained in:
Yoshito Umaoka 2009-02-02 17:03:23 +00:00
parent eb175516be
commit 26009b31ae
6 changed files with 227 additions and 37 deletions

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b74afbda7f9c8f15b595f8c58a5f35dabfe22057d0ba10daf8a62657834f66a9
size 767202
oid sha256:56a5b21ddeedead9564ef4adcc69d949fd798c859a7c8f4fa4874d276b9e9148
size 767198

View file

@ -1,23 +1,20 @@
/*
*******************************************************************************
* Copyright (C) 2003-2008, International Business Machines Corporation and *
* Copyright (C) 2003-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.dev.test.stringprep;
import java.io.InputStream;
import java.util.Random;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.text.IDNA;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.StringPrep;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.UCharacterIterator;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.impl.ICUData;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.Utility;
/**
* @author ram
@ -289,8 +286,7 @@ public class TestIDNA extends TestFmwk {
}
}
public void TestNamePrepConformance() throws Exception{
InputStream stream = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/uidna.spp");
StringPrep namePrep = new StringPrep(stream);
StringPrep namePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
for(int i=0; i<TestData.conformanceTestCases.length;i++){
TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);

View file

@ -5,7 +5,7 @@
package com.ibm.icu.dev.test.util;
public class DebugUtilitiesData extends Object {
public static final String ICU4C_VERSION="4.1.2";
public static final String ICU4C_VERSION="4.1.3";
public static final int UDebugEnumType = 0;
public static final int UCalendarDateFields = 1;
public static final int UCalendarMonths = 2;

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6d4cf3cef357041e836677efcc1d656e94fb679fc90c4239ac4f57841278db5c
size 6651969
oid sha256:eae8453e6a30afd99c5bcd3f4050622b49f268d04bdac6522ef2f59df08f613f
size 6685042

View file

@ -1,18 +1,13 @@
/*
*******************************************************************************
* Copyright (C) 2003-2007, International Business Machines Corporation and *
* Copyright (C) 2003-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;
import com.ibm.icu.impl.ICUData;
import com.ibm.icu.impl.ICUResourceBundle;
import java.text.ParseException;
/**
*
@ -84,13 +79,7 @@ public final class IDNA {
/* private constructor to prevent construction of the object */
private IDNA(){
try{
InputStream stream = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/uidna.spp");
namePrep = new StringPrep(stream);
stream.close();
}catch (IOException e){
throw new MissingResourceException(e.toString(),"","");
}
namePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
}
private static boolean startsWithPrefix(StringBuffer src){
@ -222,7 +211,7 @@ public final class IDNA {
* - IDNA.DEFAULT Use default options, i.e., do not process unassigned code points
* and do not use STD3 ASCII rules
* If unassigned code points are found the operation fails with
* ParseException.
* StringPrepParseException.
*
* - IDNA.ALLOW_UNASSIGNED Unassigned values can be converted to ASCII for query operations
* If this option is set, the unassigned code points are in the input
@ -232,7 +221,7 @@ public final class IDNA {
* If this option is set and the input does not satisfy STD3 rules,
* the operation will fail with ParseException
* @return StringBuffer the converted String
* @throws ParseException
* @throws StringPrepParseException
* @stable ICU 2.8
*/
public static StringBuffer convertToASCII(String src, int options)

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2003-2007, International Business Machines Corporation and *
* Copyright (C) 2003-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -10,15 +10,16 @@ import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import com.ibm.icu.impl.CharTrie;
import com.ibm.icu.impl.StringPrepDataReader;
import com.ibm.icu.impl.ICUData;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.NormalizerImpl;
import com.ibm.icu.impl.StringPrepDataReader;
import com.ibm.icu.impl.UBiDiProps;
import com.ibm.icu.util.VersionInfo;
import com.ibm.icu.lang.UCharacterDirection;
import com.ibm.icu.util.VersionInfo;
/**
* StringPrep API implements the StingPrep framework as described by
@ -69,7 +70,143 @@ public final class StringPrep {
* @stable ICU 2.8
*/
public static final int ALLOW_UNASSIGNED = 0x0001;
/**
* Profile type: RFC3491 Nameprep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3491_NAMEPREP = 0;
/**
* Profile type: RFC3530 nfs4_cs_prep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3530_NFS4_CS_PREP = 1;
/**
* Profile type: RFC3530 nfs4_cs_prep with case insensitive option
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3530_NFS4_CS_PREP_CI = 2;
/**
* Profile type: RFC3530 nfs4_cis_prep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3530_NSF4_CIS_PREP = 3;
/**
* Profile type: RFC3530 nfs4_mixed_prep for prefix
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3530_NSF4_MIXED_PREP_PREFIX = 4;
/**
* Profile type: RFC3530 nfs4_mixed_prep for suffix
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3530_NSF4_MIXED_PREP_SUFFIX = 5;
/**
* Profile type: RFC3722 iSCSI
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3722_ISCSI = 6;
/**
* Profile type: RFC3920 XMPP Nodeprep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3920_NODEPREP = 7;
/**
* Profile type: RFC3920 XMPP Resourceprep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC3920_RESOURCEPREP = 8;
/**
* Profile type: RFC4011 Policy MIB Stringprep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC4011_MIB = 9;
/**
* Profile type: RFC4013 SASLprep
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC4013_SASLPREP = 10;
/**
* Profile type: RFC4505 trace
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC4505_TRACE = 11;
/**
* Profile type: RFC4518 LDAP
* @see #getInstance(int)
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static final int RFC4518_LDAP = 12;
/**
* Profile type: RFC4518 LDAP for case ignore, numeric and stored prefix
* matching rules
* @see #getInstance(int)
* @provisional This API might change or be removed in a future release.
* @draft ICU 4.2
*/
public static final int RFC4518_LDAP_CI = 13;
// Last available profile
private static final int MAX_PROFILE = RFC4518_LDAP_CI;
// Profile names must be aligned to profile type definitions
private static final String[] PROFILE_NAMES = {
"rfc3491", /* RFC3491_NAMEPREP */
"rfc3530cs", /* RFC3530_NFS4_CS_PREP */
"rfc3530csci", /* RFC3530_NFS4_CS_PREP_CI */
"rfc3491", /* RFC3530_NSF4_CIS_PREP */
"rfc3530mixp", /* RFC3530_NSF4_MIXED_PREP_PREFIX */
"rfc3491", /* RFC3530_NSF4_MIXED_PREP_SUFFIX */
"rfc3722", /* RFC3722_ISCSI */
"rfc3920node", /* RFC3920_NODEPREP */
"rfc3920res", /* RFC3920_RESOURCEPREP */
"rfc4011", /* RFC4011_MIB */
"rfc4013", /* RFC4013_SASLPREP */
"rfc4505", /* RFC4505_TRACE */
"rfc4518", /* RFC4518_LDAP */
"rfc4518ci", /* RFC4518_LDAP_CI */
};
private static final WeakReference[] CACHE = new WeakReference[MAX_PROFILE];
private static final int UNASSIGNED = 0x0000;
private static final int MAP = 0x0001;
private static final int PROHIBITED = 0x0002;
@ -188,6 +325,50 @@ public final class StringPrep {
}
}
/**
* Gets a StringPrep instance for the specified profile
*
* @param profile
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public static StringPrep getInstance(int profile) {
if (profile < 0 || profile > MAX_PROFILE) {
throw new IllegalArgumentException("Bad profile type");
}
StringPrep instance = null;
// A StringPrep instance is immutable. We use a single instance
// per type and store it in the internal cache.
synchronized (CACHE) {
WeakReference ref = CACHE[profile];
if (ref != null) {
instance = (StringPrep)ref.get();
}
if (instance == null) {
InputStream stream = ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE + "/"
+ PROFILE_NAMES[profile] + ".spp");
if (stream != null) {
try {
try {
instance = new StringPrep(stream);
} finally {
stream.close();
}
} catch (IOException e) {
throw new RuntimeException(e.toString());
}
}
if (instance != null) {
CACHE[profile] = new WeakReference(instance);
}
}
}
return instance;
}
private static final class Values{
boolean isIndex;
int value;
@ -357,7 +538,7 @@ public final class StringPrep {
*/
/**
* Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
* checks for prohited and BiDi characters in the order defined by RFC 3454
* checks for prohibited and BiDi characters in the order defined by RFC 3454
* depending on the options specified in the profile.
*
* @param src A UCharacterIterator object containing the source string
@ -369,7 +550,7 @@ public final class StringPrep {
* as normal Unicode code points.
*
* @return StringBuffer A StringBuffer containing the output
* @throws ParseException
* @throws StringPrepParseException
* @stable ICU 2.8
*/
public StringBuffer prepare(UCharacterIterator src, int options)
@ -438,4 +619,28 @@ public final class StringPrep {
return normOut;
}
/**
* Prepare the input String for use in applications with the given profile. This operation maps, normalizes(NFKC),
* checks for prohibited and BiDi characters in the order defined by RFC 3454
* depending on the options specified in the profile.
*
* @param src A string
* @param options A bit set of options:
*
* - StringPrep.NONE Prohibit processing of unassigned code points in the input
*
* - StringPrep.ALLOW_UNASSIGNED Treat the unassigned code points are in the input
* as normal Unicode code points.
*
* @return String A String containing the output
* @throws StringPrepParseException
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public String prepare(String src, int options)
throws StringPrepParseException{
StringBuffer result = prepare(UCharacterIterator.getInstance(src), options);
return result.toString();
}
}