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

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

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

String.codePointBefore介绍

[英]Returns the character (Unicode code point) before the specified index. The index refers to char values (Unicode code units) and ranges from 1 to CharSequence#length().

If the char value at (index - 1) is in the low-surrogate range, (index - 2) is not negative, and the char value at (index - 2) is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned. If the char value at index - 1 is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned.
[中]返回指定索引之前的字符(Unicode代码点)。索引引用char值(Unicode代码单位),范围从1到CharSequence#length()。
如果(index - 1)处的char值在低代理项范围内,(index - 2)不是负值,(index - 2)处的char值在高代理项范围内,则返回代理项对的补充代码点值。如果index - 1处的char值是未配对的低代理项或高代理项,则返回代理项值。

代码示例

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

int peekPrev() {
  return str.codePointBefore(idx);
}

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

/**
 * Returns the character (Unicode code point) before the specified
 * index. The index refers to {@code char} values
 * (Unicode code units) and ranges from {@code 1} to {@link
 * CharSequence#length() length}.
 * <p>
 * If the {@code char} value at {@code (index - 1)}
 * is in the low-surrogate range, {@code (index - 2)} is not
 * negative, and the {@code char} value at {@code (index -
 * 2)} is in the high-surrogate range, then the
 * supplementary code point value of the surrogate pair is
 * returned. If the {@code char} value at {@code index -
 * 1} is an unpaired low-surrogate or a high-surrogate, the
 * surrogate value is returned.
 *
 * @param index the index following the code point that should be returned
 * @return the Unicode code point value before the given index.
 * @throws IndexOutOfBoundsException if the {@code index}
 *                                   argument is less than 1 or greater than the length
 *                                   of this string.
 */
public int codePointBefore(int index) {
  return back.codePointBefore(index);
}

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

private int rtrimIndex( String value )
  {
    int end = value.length();
    while ( end > 0 )
    {
      int codePoint = value.codePointBefore( end );
      if ( !Character.isWhitespace( codePoint ) )
      {
        break;
      }
      end--;
    }
    return end;
  }
}

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

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

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

public int peekPrev() throws NoSuchElementException {
  if (! hasPrev()) throw new NoSuchElementException();
  return string.codePointBefore(idx + offs);
}

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

public int peekPrevious() throws NoSuchElementException {
  if (! hasPrevious()) throw new NoSuchElementException();
  return string.codePointBefore(idx + offs);
}

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

@Override
public boolean matches(final URI uri, final String abstractType, final String abstractTypeAuthority) {
  String host = uri.getHost();
  if (host == null) {
    return false;
  }
  final String canonHost = host.toLowerCase(Locale.ROOT);
  if (suffixMatch) {
    if (canonHost.equals(hostSpec)) {
      return super.matches(uri, abstractType, abstractTypeAuthority);
    }
    if (canonHost.endsWith(hostSpec)) {
      assert canonHost.length() > hostSpec.length(); // because otherwise it would be equal, which is tested above
      return canonHost.codePointBefore(canonHost.length() - hostSpec.length()) == '.' && super.matches(uri, abstractType, abstractTypeAuthority);
    }
    return false;
  } else {
    return canonHost.equals(hostSpec) && super.matches(uri, abstractType, abstractTypeAuthority);
  }
}

代码示例来源:origin: oracle/opengrok

int cp = filename.codePointBefore(newLength);
int nChars = Character.charCount(cp);
String c = filename.substring(newLength - nChars, newLength);

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

offset = s.offsetByCodePoints(0, j);
if (Character.isWhitespace(s.codePointBefore(offset))) {
  curLength = j - 1;

代码示例来源:origin: opengeospatial/geoapi

/**
 * Returns the index {@literal <} {@code from} of the last whitespace character.
 */
private static int skipTrailingWhitespaces(final String doc, int from) {
   while (from > 0) {
    final int c = doc.codePointBefore(from);
    if (!Character.isWhitespace(c)) break;
    from -= Character.charCount(c);
  }
  return from;
}

代码示例来源:origin: org.wildfly.common/wildfly-common

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

代码示例来源:origin: org.jboss.eap/wildfly-client-all

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

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public int peekPrev() throws NoSuchElementException {
  if (! hasPrev()) throw new NoSuchElementException();
  return string.codePointBefore(idx + offs);
}

代码示例来源:origin: org.wildfly.common/wildfly-common

public int peekPrevious() throws NoSuchElementException {
  if (! hasPrevious()) throw new NoSuchElementException();
  return string.codePointBefore(idx + offs);
}

代码示例来源:origin: org.wildfly.security/wildfly-elytron

public int peekPrev() throws NoSuchElementException {
  if (! hasPrev()) throw new NoSuchElementException();
  return string.codePointBefore(idx + offs);
}

代码示例来源:origin: NationalSecurityAgency/datawave

public static String incrementOneCodepoint(String term) {
  int codepoint = term.codePointBefore(term.length());
  int cpc = term.codePointCount(0, term.length());
  int offset = term.offsetByCodePoints(0, cpc - 1);
  codepoint = codepoint < Integer.MAX_VALUE ? codepoint + 1 : codepoint;
  int cparray[] = {codepoint};
  return term.substring(0, offset) + new String(cparray, 0, 1);
}

代码示例来源:origin: NationalSecurityAgency/datawave

public static String decrementOneCodepoint(String term) {
  int codepoint = term.codePointBefore(term.length());
  int cpc = term.codePointCount(0, term.length());
  int offset = term.offsetByCodePoints(0, cpc - 1);
  codepoint = codepoint > 0 ? codepoint - 1 : codepoint;
  int cparray[] = {codepoint};
  return term.substring(0, offset) + new String(cparray, 0, 1);
}

代码示例来源:origin: org.ceylon-lang/ceylon.language

@Ignore
public static Character getLast(java.lang.String value) {
  if (value.isEmpty()) {
    return null;
  } else {
    return Character.instance(value.codePointBefore(value.length()));
  }
}

代码示例来源:origin: smola/galimatias

private void decrIdx() {
  if (idx <= startIdx) {
    setIdx(idx - 1);
    return;
  }
  final int charCount = Character.charCount(this.input.codePointBefore(idx));
  setIdx(this.idx - charCount);
}

代码示例来源:origin: org.ceylon-lang/ceylon.language

@Ignore
public static Integer 
lastIndexWhere(java.lang.String value, Callable<? extends Boolean> fun) {
  for (int offset = value.length(); offset>0;) {
    int cp = value.codePointBefore(offset);
    offset-=java.lang.Character.charCount(cp);
    if (fun.$call$(Character.instance(cp)).booleanValue()) {
      int index = value.codePointCount(0, offset);
      return Integer.instance(index);
    }
  }
  return null;
}

相关文章