当前位置: 首页>>代码示例>>Java>>正文


Java Normalizer.Form方法代码示例

本文整理汇总了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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:NormalizerBase.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:NormalizerBase.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:NormalizerBase.java

示例4: normalize

import java.text.Normalizer; //导入方法依赖的package包/类
public static String normalize(String str, Normalizer.Form form) {
    return NormalizerBase.normalize(str, toMode(form), UNICODE_LATEST);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:NormalizerBase.java

示例5: isNormalized

import java.text.Normalizer; //导入方法依赖的package包/类
public static boolean isNormalized(String str, Normalizer.Form form) {
    return NormalizerBase.isNormalized(str, toMode(form), UNICODE_LATEST);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:NormalizerBase.java

示例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);
}
 
开发者ID:patrickfav,项目名称:bytes-java,代码行数:11,代码来源:Bytes.java


注:本文中的java.text.Normalizer.Form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。