本文整理汇总了Java中java.text.Normalizer.Form方法的典型用法代码示例。如果您正苦于以下问题:Java Normalizer.Form方法的具体用法?Java Normalizer.Form怎么用?Java Normalizer.Form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.Normalizer
的用法示例。
在下文中一共展示了Normalizer.Form方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNormalized
import java.text.Normalizer; //导入方法依赖的package包/类
/**
* Test if a string is in a given normalization form.
* This is semantically equivalent to source.equals(normalize(source, mode)).
*
* Unlike quickCheck(), this function returns a definitive result,
* never a "maybe".
* For NFD, NFKD, and FCD, both functions work exactly the same.
* For NFC and NFKC where quickCheck may return "maybe", this function will
* perform further tests to arrive at a true/false result.
* @param str the input string to be checked to see if it is normalized
* @param form the normalization form
* @param options the optional features to be enabled.
*/
public static boolean isNormalized(String str, Normalizer.Form form, int options) {
switch (form) {
case NFC:
return (NFC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
case NFD:
return (NFD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
case NFKC:
return (NFKC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
case NFKD:
return (NFKD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
}
throw new IllegalArgumentException("Unexpected normalization form: " +
form);
}
示例2: normalize
import java.text.Normalizer; //导入方法依赖的package包/类
/**
* Normalizes a <code>String</code> using the given normalization form.
*
* @param str the input string to be normalized.
* @param form the normalization form
* @param options the optional features to be enabled.
*/
public static String normalize(String str, Normalizer.Form form, int options) {
int len = str.length();
boolean asciiOnly = true;
if (len < 80) {
for (int i = 0; i < len; i++) {
if (str.charAt(i) > 127) {
asciiOnly = false;
break;
}
}
} else {
char[] a = str.toCharArray();
for (int i = 0; i < len; i++) {
if (a[i] > 127) {
asciiOnly = false;
break;
}
}
}
switch (form) {
case NFC :
return asciiOnly ? str : NFC.normalize(str, options);
case NFD :
return asciiOnly ? str : NFD.normalize(str, options);
case NFKC :
return asciiOnly ? str : NFKC.normalize(str, options);
case NFKD :
return asciiOnly ? str : NFKD.normalize(str, options);
}
throw new IllegalArgumentException("Unexpected normalization form: " +
form);
}
示例3: toMode
import java.text.Normalizer; //导入方法依赖的package包/类
private static Mode toMode(Normalizer.Form form) {
switch (form) {
case NFC :
return NFC;
case NFD :
return NFD;
case NFKC :
return NFKC;
case NFKD :
return NFKD;
}
throw new IllegalArgumentException("Unexpected normalization form: " +
form);
}
示例4: normalize
import java.text.Normalizer; //导入方法依赖的package包/类
public static String normalize(String str, Normalizer.Form form) {
return NormalizerBase.normalize(str, toMode(form), UNICODE_LATEST);
}
示例5: isNormalized
import java.text.Normalizer; //导入方法依赖的package包/类
public static boolean isNormalized(String str, Normalizer.Form form) {
return NormalizerBase.isNormalized(str, toMode(form), UNICODE_LATEST);
}
示例6: from
import java.text.Normalizer; //导入方法依赖的package包/类
/**
* Creates a new instance from normalized form of given utf-8 encoded string
*
* @param utf8String to get the internal byte array from
* @param form to normalize, usually you want {@link java.text.Normalizer.Form#NFKD} for compatibility
* @return new instance
*/
public static Bytes from(CharSequence utf8String, Normalizer.Form form) {
return from(Normalizer.normalize(utf8String, form), StandardCharsets.UTF_8);
}