Package com.ibm.icu.text
Class StringPrep
- java.lang.Object
-
- com.ibm.icu.text.StringPrep
-
public final class StringPrep extends java.lang.Object
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 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- Unassigned Table: Contains code points that are unassigned in the Unicode Version supported by StringPrep. Currently RFC 3454 supports Unicode 3.2.
- Prohibited Table: Contains code points that are prohibited from the output of the StringPrep processing function.
- Mapping Table: Contains code points that are deleted from the output or case mapped.
- Map: For each character in the input, check if it has a mapping and, if so, replace it with its mapping.
- Normalize: Possibly normalize the result of step 1 using Unicode normalization.
- Prohibit: Check for any characters that are not allowed in the output. If any are found, return an error.
- 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 satisfy the requirements for bidirectional strings, return an error.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
StringPrep.Values
-
Field Summary
Fields Modifier and Type Field Description static int
ALLOW_UNASSIGNED
Option to allow processing of unassigned code points in the inputprivate UBiDiProps
bdp
private static java.lang.ref.WeakReference<StringPrep>[]
CACHE
private static int
CHECK_BIDI_ON
private boolean
checkBiDi
static int
DEFAULT
Option to prohibit processing of unassigned code points in the inputprivate static int
DELETE
private boolean
doNFKC
private static int
FOUR_UCHARS_MAPPING_INDEX_START
private static int
INDEX_MAPPING_DATA_SIZE
private static int
INDEX_TOP
private int[]
indexes
private static int
MAP
private char[]
mappingData
private static int
MAX_INDEX_VALUE
private static int
MAX_PROFILE
private static int
NORM_CORRECTNS_LAST_UNI_VERSION
private static int
NORMALIZATION_ON
private VersionInfo
normCorrVer
private static int
ONE_UCHAR_MAPPING_INDEX_START
private static int
OPTIONS
private static java.lang.String[]
PROFILE_NAMES
private static int
PROHIBITED
static int
RFC3491_NAMEPREP
Profile type: RFC3491 Nameprepstatic int
RFC3530_NFS4_CIS_PREP
Profile type: RFC3530 nfs4_cis_prepstatic int
RFC3530_NFS4_CS_PREP
Profile type: RFC3530 nfs4_cs_prepstatic int
RFC3530_NFS4_CS_PREP_CI
Profile type: RFC3530 nfs4_cs_prep with case insensitive optionstatic int
RFC3530_NFS4_MIXED_PREP_PREFIX
Profile type: RFC3530 nfs4_mixed_prep for prefixstatic int
RFC3530_NFS4_MIXED_PREP_SUFFIX
Profile type: RFC3530 nfs4_mixed_prep for suffixstatic int
RFC3722_ISCSI
Profile type: RFC3722 iSCSIstatic int
RFC3920_NODEPREP
Profile type: RFC3920 XMPP Nodeprepstatic int
RFC3920_RESOURCEPREP
Profile type: RFC3920 XMPP Resourceprepstatic int
RFC4011_MIB
Profile type: RFC4011 Policy MIB Stringprepstatic int
RFC4013_SASLPREP
Profile type: RFC4013 SASLprepstatic int
RFC4505_TRACE
Profile type: RFC4505 tracestatic int
RFC4518_LDAP
Profile type: RFC4518 LDAPstatic int
RFC4518_LDAP_CI
Profile type: RFC4518 LDAP for case ignore, numeric and stored prefix matching rulesprivate CharTrie
sprepTrie
private VersionInfo
sprepUniVer
private static int
THREE_UCHARS_MAPPING_INDEX_START
private static int
TWO_UCHARS_MAPPING_INDEX_START
private static int
TYPE_LIMIT
private static int
TYPE_THRESHOLD
private static int
UNASSIGNED
-
Constructor Summary
Constructors Modifier Constructor Description StringPrep(java.io.InputStream inputStream)
Creates an StringPrep object after reading the input stream.private
StringPrep(java.nio.ByteBuffer bytes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private char
getCodePointValue(int ch)
static StringPrep
getInstance(int profile)
Gets a StringPrep instance for the specified profileprivate static void
getValues(char trieWord, StringPrep.Values values)
private static VersionInfo
getVersionInfo(byte[] version)
private static VersionInfo
getVersionInfo(int comp)
private java.lang.StringBuffer
map(UCharacterIterator iter, int options)
private java.lang.StringBuffer
normalize(java.lang.StringBuffer src)
java.lang.StringBuffer
prepare(UCharacterIterator src, int options)
Prepare the input buffer for use in applications with the given profile.java.lang.String
prepare(java.lang.String src, int options)
Prepare the input String for use in applications with the given profile.
-
-
-
Field Detail
-
DEFAULT
public static final int DEFAULT
Option to prohibit processing of unassigned code points in the input
-
ALLOW_UNASSIGNED
public static final int ALLOW_UNASSIGNED
Option to allow processing of unassigned code points in the input
-
RFC3491_NAMEPREP
public static final int RFC3491_NAMEPREP
Profile type: RFC3491 Nameprep- See Also:
getInstance(int)
, Constant Field Values
-
RFC3530_NFS4_CS_PREP
public static final int RFC3530_NFS4_CS_PREP
Profile type: RFC3530 nfs4_cs_prep- See Also:
getInstance(int)
, Constant Field Values
-
RFC3530_NFS4_CS_PREP_CI
public static final int RFC3530_NFS4_CS_PREP_CI
Profile type: RFC3530 nfs4_cs_prep with case insensitive option- See Also:
getInstance(int)
, Constant Field Values
-
RFC3530_NFS4_CIS_PREP
public static final int RFC3530_NFS4_CIS_PREP
Profile type: RFC3530 nfs4_cis_prep- See Also:
getInstance(int)
, Constant Field Values
-
RFC3530_NFS4_MIXED_PREP_PREFIX
public static final int RFC3530_NFS4_MIXED_PREP_PREFIX
Profile type: RFC3530 nfs4_mixed_prep for prefix- See Also:
getInstance(int)
, Constant Field Values
-
RFC3530_NFS4_MIXED_PREP_SUFFIX
public static final int RFC3530_NFS4_MIXED_PREP_SUFFIX
Profile type: RFC3530 nfs4_mixed_prep for suffix- See Also:
getInstance(int)
, Constant Field Values
-
RFC3722_ISCSI
public static final int RFC3722_ISCSI
Profile type: RFC3722 iSCSI- See Also:
getInstance(int)
, Constant Field Values
-
RFC3920_NODEPREP
public static final int RFC3920_NODEPREP
Profile type: RFC3920 XMPP Nodeprep- See Also:
getInstance(int)
, Constant Field Values
-
RFC3920_RESOURCEPREP
public static final int RFC3920_RESOURCEPREP
Profile type: RFC3920 XMPP Resourceprep- See Also:
getInstance(int)
, Constant Field Values
-
RFC4011_MIB
public static final int RFC4011_MIB
Profile type: RFC4011 Policy MIB Stringprep- See Also:
getInstance(int)
, Constant Field Values
-
RFC4013_SASLPREP
public static final int RFC4013_SASLPREP
Profile type: RFC4013 SASLprep- See Also:
getInstance(int)
, Constant Field Values
-
RFC4505_TRACE
public static final int RFC4505_TRACE
Profile type: RFC4505 trace- See Also:
getInstance(int)
, Constant Field Values
-
RFC4518_LDAP
public static final int RFC4518_LDAP
Profile type: RFC4518 LDAP- See Also:
getInstance(int)
, Constant Field Values
-
RFC4518_LDAP_CI
public static final int RFC4518_LDAP_CI
Profile type: RFC4518 LDAP for case ignore, numeric and stored prefix matching rules- See Also:
getInstance(int)
, Constant Field Values
-
MAX_PROFILE
private static final int MAX_PROFILE
- See Also:
- Constant Field Values
-
PROFILE_NAMES
private static final java.lang.String[] PROFILE_NAMES
-
CACHE
private static final java.lang.ref.WeakReference<StringPrep>[] CACHE
-
UNASSIGNED
private static final int UNASSIGNED
- See Also:
- Constant Field Values
-
MAP
private static final int MAP
- See Also:
- Constant Field Values
-
PROHIBITED
private static final int PROHIBITED
- See Also:
- Constant Field Values
-
DELETE
private static final int DELETE
- See Also:
- Constant Field Values
-
TYPE_LIMIT
private static final int TYPE_LIMIT
- See Also:
- Constant Field Values
-
NORMALIZATION_ON
private static final int NORMALIZATION_ON
- See Also:
- Constant Field Values
-
CHECK_BIDI_ON
private static final int CHECK_BIDI_ON
- See Also:
- Constant Field Values
-
TYPE_THRESHOLD
private static final int TYPE_THRESHOLD
- See Also:
- Constant Field Values
-
MAX_INDEX_VALUE
private static final int MAX_INDEX_VALUE
- See Also:
- Constant Field Values
-
INDEX_MAPPING_DATA_SIZE
private static final int INDEX_MAPPING_DATA_SIZE
- See Also:
- Constant Field Values
-
NORM_CORRECTNS_LAST_UNI_VERSION
private static final int NORM_CORRECTNS_LAST_UNI_VERSION
- See Also:
- Constant Field Values
-
ONE_UCHAR_MAPPING_INDEX_START
private static final int ONE_UCHAR_MAPPING_INDEX_START
- See Also:
- Constant Field Values
-
TWO_UCHARS_MAPPING_INDEX_START
private static final int TWO_UCHARS_MAPPING_INDEX_START
- See Also:
- Constant Field Values
-
THREE_UCHARS_MAPPING_INDEX_START
private static final int THREE_UCHARS_MAPPING_INDEX_START
- See Also:
- Constant Field Values
-
FOUR_UCHARS_MAPPING_INDEX_START
private static final int FOUR_UCHARS_MAPPING_INDEX_START
- See Also:
- Constant Field Values
-
OPTIONS
private static final int OPTIONS
- See Also:
- Constant Field Values
-
INDEX_TOP
private static final int INDEX_TOP
- See Also:
- Constant Field Values
-
sprepTrie
private CharTrie sprepTrie
-
indexes
private int[] indexes
-
mappingData
private char[] mappingData
-
sprepUniVer
private VersionInfo sprepUniVer
-
normCorrVer
private VersionInfo normCorrVer
-
doNFKC
private boolean doNFKC
-
checkBiDi
private boolean checkBiDi
-
bdp
private UBiDiProps bdp
-
-
Constructor Detail
-
StringPrep
public StringPrep(java.io.InputStream inputStream) throws java.io.IOException
Creates an StringPrep object after reading the input stream. The object does not hold a reference to the input steam, so the stream can be closed after the method returns.- Parameters:
inputStream
- The stream for reading the StringPrep profile binarySun- Throws:
java.io.IOException
- An exception occurs when I/O of the inputstream is invalid
-
StringPrep
private StringPrep(java.nio.ByteBuffer bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getCodePointValue
private char getCodePointValue(int ch)
-
getVersionInfo
private static VersionInfo getVersionInfo(int comp)
-
getVersionInfo
private static VersionInfo getVersionInfo(byte[] version)
-
getInstance
public static StringPrep getInstance(int profile)
Gets a StringPrep instance for the specified profile- Parameters:
profile
- The profile passed to find the StringPrep instance.
-
getValues
private static final void getValues(char trieWord, StringPrep.Values values)
-
map
private java.lang.StringBuffer map(UCharacterIterator iter, int options) throws StringPrepParseException
- Throws:
StringPrepParseException
-
normalize
private java.lang.StringBuffer normalize(java.lang.StringBuffer src)
-
prepare
public java.lang.StringBuffer prepare(UCharacterIterator src, int options) throws StringPrepParseException
Prepare the input buffer 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.- Parameters:
src
- A UCharacterIterator object containing the source stringoptions
- A bit set of options:DEFAULT
Prohibit processing of unassigned code points in the inputALLOW_UNASSIGNED
Treat the unassigned code points are in the input as normal Unicode code points.
- Returns:
- StringBuffer A StringBuffer containing the output
- Throws:
StringPrepParseException
- An exception occurs when parsing a string is invalid.
-
prepare
public java.lang.String prepare(java.lang.String src, int options) throws StringPrepParseException
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.- Parameters:
src
- A stringoptions
- A bit set of options:DEFAULT
Prohibit processing of unassigned code points in the inputALLOW_UNASSIGNED
Treat the unassigned code points are in the input as normal Unicode code points.
- Returns:
- String A String containing the output
- Throws:
StringPrepParseException
- An exception when parsing or preparing a string is invalid.
-
-