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


Java Normalizer类代码示例

本文整理汇总了Java中com.ibm.icu.text.Normalizer的典型用法代码示例。如果您正苦于以下问题:Java Normalizer类的具体用法?Java Normalizer怎么用?Java Normalizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Normalizer类属于com.ibm.icu.text包,在下文中一共展示了Normalizer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:acciente,项目名称:oacc-core,代码行数:26,代码来源:ICU4Jv26TextNormalizer.java

示例2: compare

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
@Override
public int compare(CharSequence data, int start1, int start2, int length) {
    for (int x = 0; x < length; x++) {
        final int c1 = data.charAt(start1 + x);
        final int c2 = data.charAt(start2 + x);
        int thisCompare;
        if (caseInsensitive) {
            thisCompare = Normalizer.compare(c1, c2, Normalizer.COMPARE_IGNORE_CASE);
        } else {
            thisCompare = c1 - c2;
        }
        if (thisCompare != 0) {
            return thisCompare;
        }
    }
    return 0;
}
 
开发者ID:basis-technology-corp,项目名称:tcl-regex-java,代码行数:18,代码来源:Compiler.java

示例3: quickCheck

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
@Override
public Normalizer.QuickCheckResult quickCheck(CharSequence s) {
    int spanLengthAndMaybe=impl.composeQuickCheck(s, 0, s.length(), onlyContiguous, false);
    if((spanLengthAndMaybe&1)!=0) {
        return Normalizer.MAYBE;
    } else if((spanLengthAndMaybe>>>1)==s.length()) {
        return Normalizer.YES;
    } else {
        return Normalizer.NO;
    }
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:12,代码来源:Norm2AllModes.java

示例4: incrementToken

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
@Override
public final boolean incrementToken() throws IOException {
  if (input.incrementToken()) {
    if (normalizer.quickCheck(termAtt) != Normalizer.YES) {
      buffer.setLength(0);
      normalizer.normalize(termAtt, buffer);
      termAtt.setEmpty().append(buffer);
    }
    return true;
  } else {
    return false;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:ICUNormalizer2Filter.java

示例5: end

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
/**
 * @see nu.validator.htmlparser.common.CharacterHandler#end()
 */
public void end() throws SAXException {
    if (!alreadyComplainedAboutThisRun
            && !Normalizer.isNormalized(buf, 0, pos, Normalizer.NFC, 0)) {
        errAboutTextRun();
    }
    if (bufHolder != null) {
        // restore the original small buffer to avoid leaking
        // memory if this checker is recycled
        buf = bufHolder;
        bufHolder = null;
    }
}
 
开发者ID:google,项目名称:caja,代码行数:16,代码来源:NormalizationChecker.java

示例6: 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);
}
 
开发者ID:acciente,项目名称:oacc-core,代码行数:10,代码来源:ICU4Jv26TextNormalizer.java

示例7: 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));
}
 
开发者ID:acciente,项目名称:oacc-core,代码行数:15,代码来源:ICU4Jv26TextNormalizerWorstCaseExpansionTest.java

示例8: incrementToken

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
@Override
public final boolean incrementToken() throws IOException {
    if (input.incrementToken()) {
        if (normalizer.quickCheck(termAtt) != Normalizer.YES) {
            buffer.setLength(0);
            normalizer.normalize(termAtt, buffer);
            termAtt.setEmpty().append(buffer);
        }
        return true;
    } else {
        return false;
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:14,代码来源:IcuNormalizerFilter.java

示例9: characters

import com.ibm.icu.text.Normalizer; //导入依赖的package包/类
/**
 * @see nu.validator.htmlparser.common.CharacterHandler#characters(char[], int, int)
 */
public void characters(char[] ch, int start, int length)
        throws SAXException {
    if (alreadyComplainedAboutThisRun) {
        return;
    }
    if (atStartOfRun) {
        char c = ch[start];
        if (pos == 1) {
            // there's a single high surrogate in buf
            if (isComposingChar(UCharacter.getCodePoint(buf[0], c))) {
                err("Text run starts with a composing character.");
            }
            atStartOfRun = false;
        } else {
            if (length == 1 && UCharacter.isHighSurrogate(c)) {
                buf[0] = c;
                pos = 1;
                return;
            } else {
                if (UCharacter.isHighSurrogate(c)) {
                    if (isComposingChar(UCharacter.getCodePoint(c,
                            ch[start + 1]))) {
                        err("Text run starts with a composing character.");
                    }
                } else {
                    if (isComposingCharOrSurrogate(c)) {
                        err("Text run starts with a composing character.");
                    }
                }
                atStartOfRun = false;
            }
        }
    }
    int i = start;
    int stop = start + length;
    if (pos > 0) {
        // there's stuff in buf
        while (i < stop && isComposingCharOrSurrogate(ch[i])) {
            i++;
        }
        appendToBuf(ch, start, i);
        if (i == stop) {
            return;
        } else {
            if (!Normalizer.isNormalized(buf, 0, pos, Normalizer.NFC, 0)) {
                errAboutTextRun();
            }
            pos = 0;
        }
    }
    if (i < stop) {
        start = i;
        i = stop - 1;
        while (i > start && isComposingCharOrSurrogate(ch[i])) {
            i--;
        }
        if (i > start) {
            if (!Normalizer.isNormalized(ch, start, i, Normalizer.NFC, 0)) {
                errAboutTextRun();
            }
        }
        appendToBuf(ch, i, stop);
    }
}
 
开发者ID:google,项目名称:caja,代码行数:68,代码来源:NormalizationChecker.java

示例10: 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();
}
 
开发者ID:acciente,项目名称:oacc-core,代码行数:6,代码来源:ICU4Jv26TextNormalizerParityTest.java

示例11: 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}]", "");
}
 
开发者ID:atolcd,项目名称:alfresco-zip-and-download,代码行数:12,代码来源:ZipContents.java


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