java.lang.Character.codePointCount()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中java.lang.Character.codePointCount()方法的一些代码示例,展示了Character.codePointCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.codePointCount()方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:codePointCount

Character.codePointCount介绍

[英]Counts the number of Unicode code points in the subsequence of the specified character sequence, as delineated by beginIndex and endIndex. Any surrogate values with missing pair values will be counted as one code point.
[中]

代码示例

代码示例来源:origin: redisson/redisson

private static int[] toCodePoints(char[] str) {
  int[] codePoints = new int[Character.codePointCount(str, 0, str.length)];
  for (int i = 0, c = 0; i < str.length; c++) {
    int cp = Character.codePointAt(str, i);
    codePoints[c] = cp;
    i += Character.charCount(cp);
  }
  return codePoints;
}

代码示例来源:origin: libgdx/libgdx

/** Calculates the number of Unicode code points between {@code beginIndex} and {@code endIndex}.
 * 
 * @param beginIndex the inclusive beginning index of the subsequence.
 * @param endIndex the exclusive end index of the subsequence.
 * @return the number of Unicode code points in the subsequence.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is negative or greater than {@code endIndex} or {@code endIndex} is
 *            greater than {@link #length()}.
 * @see Character
 * @see Character#codePointCount(char[], int, int)
 * @since 1.5 */
public int codePointCount (int beginIndex, int endIndex) {
  if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
    throw new StringIndexOutOfBoundsException();
  }
  return Character.codePointCount(chars, beginIndex, endIndex - beginIndex);
}

代码示例来源:origin: libgdx/libgdx

/** Calculates the number of Unicode code points between {@code beginIndex} and {@code endIndex}.
 * 
 * @param beginIndex the inclusive beginning index of the subsequence.
 * @param endIndex the exclusive end index of the subsequence.
 * @return the number of Unicode code points in the subsequence.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is negative or greater than {@code endIndex} or {@code endIndex} is
 *            greater than {@link #length()}.
 * @see Character
 * @see Character#codePointCount(char[], int, int)
 * @since 1.5 */
public int codePointCount (int beginIndex, int endIndex) {
  if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
    throw new StringIndexOutOfBoundsException();
  }
  return Character.codePointCount(chars, beginIndex, endIndex - beginIndex);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
  public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
    if(index != 0) {
      throw new IllegalStateException("CsvEscaper should never reach the [1] index");
    }
    if (StringUtils.containsNone(input.toString(), CSV_SEARCH_CHARS)) {
      out.write(input.toString());
    } else {
      out.write(CSV_QUOTE);
      out.write(StringUtils.replace(input.toString(), CSV_QUOTE_STR, CSV_QUOTE_STR + CSV_QUOTE_STR));
      out.write(CSV_QUOTE);
    }
    return Character.codePointCount(input, 0, input.length());
  }
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

private static int[] toCodePoints(char[] str) {
  int[] codePoints = new int[Character.codePointCount(str, 0, str.length)];
  for (int i = 0, c = 0; i < str.length; c++) {
    int cp = Character.codePointAt(str, i);
    codePoints[c] = cp;
    i += Character.charCount(cp);
  }
  return codePoints;
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
  public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
    if(index != 0) {
      throw new IllegalStateException("CsvUnescaper should never reach the [1] index");
    }
    if ( input.charAt(0) != CSV_QUOTE || input.charAt(input.length() - 1) != CSV_QUOTE ) {
      out.write(input.toString());
      return Character.codePointCount(input, 0, input.length());
    }
    // strip quotes
    final String quoteless = input.subSequence(1, input.length() - 1).toString();
    if ( StringUtils.containsAny(quoteless, CSV_SEARCH_CHARS) ) {
      // deal with escaped quotes; ie) ""
      out.write(StringUtils.replace(quoteless, CSV_QUOTE_STR + CSV_QUOTE_STR, CSV_QUOTE_STR));
    } else {
      out.write(input.toString());
    }
    return Character.codePointCount(input, 0, input.length());
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core

private static int[] codePoints(String input) {
 int length = Character.codePointCount(input, 0, input.length());
 int word[] = new int[length];
 for (int i = 0, j = 0, cp = 0; i < input.length(); i += Character.charCount(cp)) {
  word[j++] = cp = input.codePointAt(i);
 }
 return word;
}

代码示例来源:origin: robovm/robovm

/**
 * Calculates the number of Unicode code points between {@code start}
 * and {@code end}.
 *
 * @param start
 *            the inclusive beginning index of the subsequence.
 * @param end
 *            the exclusive end index of the subsequence.
 * @return the number of Unicode code points in the subsequence.
 * @throws IndexOutOfBoundsException
 *         if {@code start < 0 || end > length() || start > end}
 * @see Character#codePointCount(CharSequence, int, int)
 * @since 1.5
 */
public int codePointCount(int start, int end) {
  if (start < 0 || end > count || start > end) {
    throw startEndAndLength(start, end);
  }
  return Character.codePointCount(value, offset + start, end - start);
}

代码示例来源:origin: robovm/robovm

/**
 * Calculates the number of Unicode code points between {@code start}
 * and {@code end}.
 *
 * @param start
 *            the inclusive beginning index of the subsequence.
 * @param end
 *            the exclusive end index of the subsequence.
 * @return the number of Unicode code points in the subsequence.
 * @throws IndexOutOfBoundsException
 *             if {@code start} is negative or greater than
 *             {@code end} or {@code end} is greater than
 *             {@link #length()}.
 * @see Character
 * @see Character#codePointCount(char[], int, int)
 * @since 1.5
 */
public int codePointCount(int start, int end) {
  if (start < 0 || end > count || start > end) {
    throw startEndAndLength(start, end);
  }
  return Character.codePointCount(value, start, end - start);
}

代码示例来源:origin: Neamar/KISS

/**
 * @param text string where to search
 * @return true if each character in pattern is found sequentially within text
 */
public MatchInfo match(CharSequence text) {
  int idx = 0;
  int idxCodepoint = 0;
  int textLength = text.length();
  int[] codepoints = new int[Character.codePointCount(text, 0, textLength)];
  while (idx < textLength) {
    int codepoint = Character.codePointAt(text, idx);
    codepoints[idxCodepoint] = codepoint;
    idx += Character.charCount(codepoint);
    idxCodepoint += 1;
  }
  return match(codepoints);
}

代码示例来源:origin: linkedin/indextank-engine

int length = Character.codePointCount(input, 0, input.length());
word = new int[length];
for (int i = 0, j = 0, cp = 0; i < input.length(); i += Character.charCount(cp)) {

代码示例来源:origin: Neamar/KISS

public static StringNormalizer.Result simplifyPhoneNumber(String phoneNumber) {
    // This is done manually for performance reason,
    // But the algorithm is just a regexp replacement of "[-.():/ ]" with ""

    int numCodePoints = Character.codePointCount(phoneNumber, 0, phoneNumber.length());
    IntSequenceBuilder codePoints = new IntSequenceBuilder(numCodePoints);
    IntSequenceBuilder resultMap = new IntSequenceBuilder(numCodePoints);

    int i = 0;
    for (int iterCodePoint = 0; iterCodePoint < numCodePoints; iterCodePoint += 1) {
      int c = Character.codePointAt(phoneNumber, i);

      if (c != ' ' && c != '-' && c != '.' && c != '(' && c != ')' && c != ':' && c != '/') {
        codePoints.add(c);
        resultMap.add(i);
      }
      i += Character.charCount(c);
    }

    return new StringNormalizer.Result(phoneNumber.length(), codePoints.toArray(), resultMap.toArray());
  }
}

代码示例来源:origin: org.apache.lucene/lucene-analyzers-common

@Override
 public boolean accept() {
  final int max32 = termAtt.length();
  final int min32 = max32 >> 1;
  if (min32 >= min && max32 <= max) {
   // definitely within range
   return true;
  } else if (min32 > max || max32 < min) {
   // definitely not
   return false;
  } else {
   // we must count to be sure
   int len = Character.codePointCount(termAtt.buffer(), 0, termAtt.length());
   return (len >= min && len <= max);
  }
 }
}

代码示例来源:origin: Neamar/KISS

int numCodePoints = Character.codePointCount(input, 0, input.length());
IntSequenceBuilder codePoints = new IntSequenceBuilder(numCodePoints);
IntSequenceBuilder resultMap = new IntSequenceBuilder(numCodePoints);

代码示例来源:origin: stackoverflow.com

boolean isHindi = false;
 for (int k = 0; k < Character.codePointCount(myString, 0, myString.length()); k++) {
   int c = myString.codePointAt(k);
   if (c >= 0x0900 && c <= 0x097F) {  //Hindi uni-codes are within this range
     isHindi = true;
     break;
   }
 }

代码示例来源:origin: stackoverflow.com

public static boolean textIsPersian(String s) {
for (int i = 0; i < Character.codePointCount(s, 0, s.length()); i++) {
  int c = s.codePointAt(i);
  if (c >= 0x0600 && c <=0x06FF || c== 0xFB8A || c==0x067E || c==0x0686 || c==0x06AF)
    return true;
}
return false;

代码示例来源:origin: stackoverflow.com

public static boolean textIsPersian(String s) {
for (int i = 0; i < Character.codePointCount(s, 0, s.length()); i++) {
  int c = s.codePointAt(i);
  if ((c >= 0x0600 && c <=0x06FF) || (c>=0xFB50 && c<=0xFDFF) || (c>=0xFE70 && c<=0xFEFF) )
    return true;
}
return false;
}

代码示例来源:origin: org.apache.lucene/lucene-analyzers-common

curTermCodePointCount = Character.codePointCount(termAtt, 0, curTermLength);
curPosIncr += posIncrAtt.getPositionIncrement();

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene

private static int[] codePoints(String input) {
 int length = Character.codePointCount(input, 0, input.length());
 int word[] = new int[length];
 for (int i = 0, j = 0, cp = 0; i < input.length(); i += Character.charCount(cp)) {
  word[j++] = cp = input.codePointAt(i);
 }
 return word;
}

代码示例来源:origin: org.apache.lucene/lucene-analyzers-common

curTermCodePointCount = Character.codePointCount(termAtt, 0, termAtt.length());
curPosIncr += posIncrAtt.getPositionIncrement();
curPos = 0;

相关文章

微信公众号

最新文章

更多

Character类方法