本文整理汇总了Java中com.ibm.icu.text.Normalizer.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Normalizer.normalize方法的具体用法?Java Normalizer.normalize怎么用?Java Normalizer.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.text.Normalizer
的用法示例。
在下文中一共展示了Normalizer.normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalizeToNfc
import com.ibm.icu.text.Normalizer; //导入方法依赖的package包/类
@Override
public char[] normalizeToNfc(char[] source) {
int destBufferSize = 3 * source.length;
char[] result = null;
do {
char[] destBuffer = new char[destBufferSize];
try {
final int destBufferUsedCount = Normalizer.normalize(source, destBuffer, Normalizer.NFC, 0);
result = copyContents(destBuffer, destBufferUsedCount);
}
catch (IndexOutOfBoundsException e) {
// NOTE: since we allocate an initial buffer that is 3x of
// the source text length we never expect this to happen
// try the next loop iteration with a larger buffer
destBufferSize += source.length;
}
finally {
// zero out the current dest buffer
zeroOut(destBuffer);
}
} while (result == null);
return result;
}
示例2: ICU4Jv26TextNormalizer
import com.ibm.icu.text.Normalizer; //导入方法依赖的package包/类
private ICU4Jv26TextNormalizer() {
// this "no-op" call to the Normalize class is *very* important, without it when the
// com.ibm.icu.text.Normalizer class is not present in the classpath a load of the
// class will not fail until it is attempted in the normalizeToNfc() method below -- which
// is too late. The class load needs to fail here to cause the getInstance() method below to
// propagate the class load exception and correctly trigger the fallback to the JDK based
// TextNormalizer implementation in the parent class's TextNormalizer#getInstance().
Normalizer.normalize("", Normalizer.NFC, 0);
}
示例3: testExpansion
import com.ibm.icu.text.Normalizer; //导入方法依赖的package包/类
@Test
public void testExpansion() throws Exception {
final int expectedMaxExpansionSize = 3 * src.length();
// allocate the destination to be 3x of the source length
char[] dest = new char[expectedMaxExpansionSize];
// normalize the text
final int actualDestLen = Normalizer.normalize(src.toCharArray(), dest, Normalizer.NFC, 0);
assertThat("Note: " +
"if this test fails, then the ICU4J library in use does not maintain our bounded expansion " +
"and could leak passwords; use a different library or adjust the expansion factor",
actualDestLen, lessThanOrEqualTo(expectedMaxExpansionSize));
}
示例4: normalizeDirect
import com.ibm.icu.text.Normalizer; //导入方法依赖的package包/类
private char[] normalizeDirect() {
// normalize using direct call to underlying normalizer
final String dest = Normalizer.normalize(new String(srcCharArray), Normalizer.NFC);
return dest.toCharArray();
}
示例5: unAccent
import com.ibm.icu.text.Normalizer; //导入方法依赖的package包/类
/**
* ZipEntry() does not convert filenames from Unicode to platform (waiting
* Java 7) http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499
*
* @param s
* @return
*/
public static String unAccent(String s) {
String temp = Normalizer.normalize(s, Normalizer.NFD, 0);
return temp.replaceAll("[^\\p{ASCII}]", "");
}