本文整理汇总了Java中sun.text.normalizer.UCharacterIterator类的典型用法代码示例。如果您正苦于以下问题:Java UCharacterIterator类的具体用法?Java UCharacterIterator怎么用?Java UCharacterIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UCharacterIterator类属于sun.text.normalizer包,在下文中一共展示了UCharacterIterator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mixed_prepare
import sun.text.normalizer.UCharacterIterator; //导入依赖的package包/类
public static byte[] mixed_prepare(byte[] src)
throws IOException, ParseException, UnsupportedEncodingException{
String s = new String(src, "UTF-8");
int index = s.indexOf(AT_SIGN);
StringBuffer out = new StringBuffer();
if(index > -1){
/* special prefixes must not be followed by suffixes! */
String prefixString = s.substring(0,index);
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", -1);
}
UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
out.append(AT_SIGN); // add the delimiter
out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
}else{
UCharacterIterator iter = UCharacterIterator.getInstance(s);
out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));
}
return out.toString().getBytes("UTF-8");
}
示例2: TestNamePrepConformance
import sun.text.normalizer.UCharacterIterator; //导入依赖的package包/类
public static void TestNamePrepConformance() throws Exception {
InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
StringPrep namePrep = new StringPrep(stream);
stream.close();
int i;
for(i=0; i<TestData.conformanceTestCases.length;i++){
TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
try{
UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
StringBuffer output = namePrep.prepare(iter, testCase.flags);
if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
" Got: "+ prettify(output.toString()) );
}
} catch(ParseException ex) {
if (testCase.expected == null) {
fail("get the unexpected exception for source: " +testCase.input +" Got: "+ ex.toString());
}
}
}
System.out.println("Nameprep test count: " + i);
}
示例3: TestNamePrepConformance
import sun.text.normalizer.UCharacterIterator; //导入依赖的package包/类
public static void TestNamePrepConformance() throws Exception {
InputStream stream = StringPrep.class.getModule()
.getResourceAsStream("sun/net/idn/uidna.spp");
StringPrep namePrep = new StringPrep(stream);
stream.close();
int i;
for(i=0; i<TestData.conformanceTestCases.length;i++){
TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
try{
UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
StringBuffer output = namePrep.prepare(iter, testCase.flags);
if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
" Got: "+ prettify(output.toString()) );
}
} catch(ParseException ex) {
if (testCase.expected == null) {
fail("get the unexpected exception for source: " +testCase.input +" Got: "+ ex.toString());
}
}
}
System.out.println("Nameprep test count: " + i);
}
示例4: prepare
import sun.text.normalizer.UCharacterIterator; //导入依赖的package包/类
private static byte[] prepare(byte[] src, StringPrep prep)
throws ParseException, UnsupportedEncodingException{
String s = new String(src, "UTF-8");
UCharacterIterator iter = UCharacterIterator.getInstance(s);
StringBuffer out = prep.prepare(iter,StringPrep.DEFAULT);
return out.toString().getBytes("UTF-8");
}
示例5: toUnicodeInternal
import sun.text.normalizer.UCharacterIterator; //导入依赖的package包/类
private static String toUnicodeInternal(String label, int flag) {
boolean[] caseFlags = null;
StringBuffer dest;
// step 1
// find out if all the codepoints in input are ASCII
boolean isASCII = isAllASCII(label);
if(!isASCII){
// step 2
// perform the nameprep operation; flag ALLOW_UNASSIGNED is used here
try {
UCharacterIterator iter = UCharacterIterator.getInstance(label);
dest = namePrep.prepare(iter, flag);
} catch (Exception e) {
// toUnicode never fails; if any step fails, return the input string
return label;
}
} else {
dest = new StringBuffer(label);
}
// step 3
// verify ACE Prefix
if(startsWithACEPrefix(dest)) {
// step 4
// Remove the ACE Prefix
String temp = dest.substring(ACE_PREFIX_LENGTH, dest.length());
try {
// step 5
// Decode using punycode
StringBuffer decodeOut = Punycode.decode(new StringBuffer(temp), null);
// step 6
// Apply toASCII
String toASCIIOut = toASCII(decodeOut.toString(), flag);
// step 7
// verify
if (toASCIIOut.equalsIgnoreCase(dest.toString())) {
// step 8
// return output of step 5
return decodeOut.toString();
}
} catch (Exception ignored) {
// no-op
}
}
// just return the input
return label;
}