java.lang.String.offsetByCodePoints()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(477)

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

String.offsetByCodePoints介绍

[英]Returns the index within this String that is offset from the given index by codePointOffset code points. Unpaired surrogates within the text range given by index and codePointOffset count as one code point each.
[中]返回此String中的索引,该索引与给定的index偏移codePointOffset代码点。indexcodePointOffset给出的文本范围内的未配对代理项各计为一个代码点。

代码示例

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

int getPrevIdx() {
  return str.offsetByCodePoints(idx, -1);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Returns the index within this {@code CharSeq} that is
 * offset from the given {@code index} by
 * {@code codePointOffset} code points. Unpaired surrogates
 * within the text range given by {@code index} and
 * {@code codePointOffset} count as one code point each.
 *
 * @param index           the index to be offset
 * @param codePointOffset the offset in code points
 * @return the index within this {@code CharSeq}
 * @throws IndexOutOfBoundsException if {@code index}
 *                                   is negative or larger then the length of this
 *                                   {@code CharSeq}, or if {@code codePointOffset} is positive
 *                                   and the substring starting with {@code index} has fewer
 *                                   than {@code codePointOffset} code points,
 *                                   or if {@code codePointOffset} is negative and the substring
 *                                   before {@code index} has fewer than the absolute value
 *                                   of {@code codePointOffset} code points.
 */
public int offsetByCodePoints(int index, int codePointOffset) {
  return back.offsetByCodePoints(index, codePointOffset);
}

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

int next() {
  final int idx = this.idx;
  try {
    return str.codePointAt(idx);
  } finally {
    this.idx = str.offsetByCodePoints(idx, 1);
  }
}

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

IllegalArgumentException unexpectedCharacter() {
  return new IllegalArgumentException("Unexpected character at " + string.offsetByCodePoints(idx, -1));
}

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

private static void appendSegment(final StringBuilder b, final String segment) {
  int cp;
  for (int i = 0; i < segment.length(); i = segment.offsetByCodePoints(i, 1)) {
    cp = segment.codePointAt(i);
    if (cp == '/' || cp == '\'' || cp == '"') {
      b.append('\\');
    }
    b.appendCodePoint(cp);
  }
}

代码示例来源:origin: facebook/litho

private static String getBasePropMatcherName(final MethodParamModel prop, final String suffix) {
 final String name = prop.getName();
 final int fst = Character.toUpperCase(name.codePointAt(0));
 return 'm'
   + String.copyValueOf(Character.toChars(fst))
   + name.substring(name.offsetByCodePoints(0, 1))
   + suffix;
}

代码示例来源:origin: apache/geode

protected static String capitalize(String name) {
  if (name == null || name.length() == 0)
   return name;
  int offset1 = name.offsetByCodePoints(0, 1);
  return name.substring(0, offset1).toUpperCase() + name.substring(offset1);
 }
}

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

@Override
public TextValue substring( int start, int length )
{
  int s = Math.min( start, length() );
  int e = Math.min( s + length, length() );
  int codePointStart = value.offsetByCodePoints( 0, s );
  int codePointEnd = value.offsetByCodePoints( 0, e );
  return Values.stringValue( value.substring( codePointStart, codePointEnd ) );
}

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

public int next() {
  if (! hasNext()) throw new NoSuchElementException();
  try {
    offset++;
    return string.codePointAt(idx + offs);
  } finally {
    idx = string.offsetByCodePoints(idx + offs, 1) - offs;
  }
}

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

public int prev() {
  if (! hasPrev()) throw new NoSuchElementException();
  idx = string.offsetByCodePoints(idx + offs, -1) - offs;
  offset--;
  return string.codePointAt(idx + offs);
}

代码示例来源:origin: k9mail/k-9

private static String importStringFromIphone(String str) {
  StringBuilder buff = new StringBuilder(str.length());
  for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) {
    int codePoint = str.codePointAt(i);
    buff.appendCodePoint(importCodePointFromIphone(codePoint));
  }
  return buff.toString();
}

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

public int previous() {
  if (! hasPrevious()) throw new NoSuchElementException();
  idx = string.offsetByCodePoints(idx + offs, - 1) - offs;
  offset--;
  return string.codePointAt(idx + offs);
}

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

public int next() {
  if (! hasNext()) throw new NoSuchElementException();
  try {
    offset++;
    return string.codePointAt(idx + offs);
  } finally {
    idx = string.offsetByCodePoints(idx + offs, 1) - offs;
  }
}

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

int prev() {
  final int idx = this.idx;
  try {
    return str.codePointBefore(idx);
  } finally {
    this.idx = str.offsetByCodePoints(idx, -1);
  }
}

代码示例来源:origin: scouter-project/scouter

/**
 * Checks an identifier.
 *
 * @param signature a string containing the signature that must be checked.
 * @param startPos index of first character to be checked.
 * @return the index of the first character after the checked part.
 */
private static int checkSignatureIdentifier(final String signature, final int startPos) {
 int pos = startPos;
 while (pos < signature.length() && ".;[/<>:".indexOf(signature.codePointAt(pos)) == -1) {
  pos = signature.offsetByCodePoints(pos, 1);
 }
 if (pos == startPos) {
  throw new IllegalArgumentException(signature + ": identifier expected at index " + startPos);
 }
 return pos;
}

代码示例来源:origin: apache/hive

public static String enforceMaxLength(String val, int maxLength) {
 if (val == null) {
  return null;
 }
 String value = val;
 if (maxLength > 0) {
  int valLength = val.codePointCount(0, val.length());
  if (valLength > maxLength) {
   // Truncate the excess chars to fit the character length.
   // Also make sure we take supplementary chars into account.
   value = val.substring(0, val.offsetByCodePoints(0, maxLength));
  }
 }
 return value;
}

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

@Override
public void encodePrintableString(final String str) {
  for (int i = 0; i < str.length(); i = str.offsetByCodePoints(i, 1)) {
    validatePrintableByte(str.codePointAt(i));
  }
  writeElement(PRINTABLE_STRING_TYPE, str.getBytes(StandardCharsets.US_ASCII));
}

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

private static IllegalArgumentException invalidExpressionSyntax(final String string, final int index) {
  String msg = CommonMessages.msg.invalidExpressionSyntax(index);
  StringBuilder b = new StringBuilder(msg.length() + string.length() + string.length() + 5);
  b.append(msg);
  b.append('\n').append('\t').append(string);
  b.append('\n').append('\t');
  for (int i = 0; i < index; i = string.offsetByCodePoints(i, 1)) {
    final int cp = string.codePointAt(i);
    if (Character.isWhitespace(cp)) {
      b.append(cp);
    } else if (Character.isValidCodePoint(cp) && ! Character.isISOControl(cp)) {
      b.append(' ');
    }
  }
  b.append('^');
  return new IllegalArgumentException(b.toString());
}

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

int next() {
  if (! hasNext()) throw unexpectedEnd();
  try {
    return string.codePointAt(idx);
  } finally {
    idx = string.offsetByCodePoints(idx, 1);
  }
}

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

private Path pathFor(String name) {
  assert name.codePointCount(0, name.length()) > 0;
  String normalizedName = name;
  if (encoded) {
    normalizedName = Normalizer.normalize(name, Normalizer.Form.NFKC)
        .toLowerCase(Locale.ROOT)
        .replaceAll("[^a-z0-9]", "_");
  }
  Path path = root;
  int idx = 0;
  for (int level = 0; level < levels; level ++) {
    int newIdx = normalizedName.offsetByCodePoints(idx, 1);
    path = path.resolve(normalizedName.substring(idx, newIdx));
    idx = newIdx;
    if (idx == normalizedName.length()) {
      break;
    }
  }
  if (encoded) {
    String base32 = ByteIterator.ofBytes(new ByteStringBuilder().append(name).toArray())
        .base32Encode(Base32Alphabet.STANDARD, false).drainToString();
    name = normalizedName + "-" + base32;
  }
  return path.resolve(name + ".xml");
}

相关文章