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

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

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

Character.isJavaIdentifierPart介绍

[英]Indicates whether the specified character is a valid part of a Java identifier other than the first character.
[中]指示指定的字符是否是除第一个字符以外的Java标识符的有效部分。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private boolean isVariableName(String name) {
  char[] chars = name.toCharArray();
  if (!Character.isJavaIdentifierStart(chars[0])) {
    return false;
  }
  for (int i = 1; i < chars.length; i++) {
    if (!Character.isJavaIdentifierPart(chars[i])) {
      return false;
    }
  }
  return true;
}

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

public static void main(String[] args) {
  for (char c‮h = 0; c‮h < Character.MAX_VALUE; c‮h++) {
    if (Character.isJavaIdentifierPart(c‮h) && !Character.isJavaIdentifierStart(c‮h)) {
      System.out.printf("%04x <%s>%n", (int) c‮h, "" + c‮h);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private String maybeExtractVariableName(@Nullable String candidateToken) {
  if (!StringUtils.hasLength(candidateToken)) {
    return null;
  }
  if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
      Character.isLowerCase(candidateToken.charAt(0))) {
    char[] tokenChars = candidateToken.toCharArray();
    for (char tokenChar : tokenChars) {
      if (!Character.isJavaIdentifierPart(tokenChar)) {
        return null;
      }
    }
    return candidateToken;
  }
  else {
    return null;
  }
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * Returns true if s is a legal Java identifier.<p>
 * <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a>
 */
public static boolean isJavaIdentifier(String s) {
  if (isEmpty(s) || !Character.isJavaIdentifierStart(s.charAt(0))) {
    return false;
  }
  for (int i = 1; i < s.length(); i++) {
    if (!Character.isJavaIdentifierPart(s.charAt(i))) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * Returns true if s is a legal Java identifier.<p>
 * <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a>
 */
public static boolean isJavaIdentifier(String s) {
  if (isEmpty(s) || !Character.isJavaIdentifierStart(s.charAt(0))) {
    return false;
  }
  for (int i = 1; i < s.length(); i++) {
    if (!Character.isJavaIdentifierPart(s.charAt(i))) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: prestodb/presto

private final void _checkMatchEnd(String matchStr, int i, int c) throws IOException {
  // but actually only alphanums are problematic
  char ch = (char) c;
  if (Character.isJavaIdentifierPart(ch)) {
    _reportInvalidToken(matchStr.substring(0, i));
  }
}

代码示例来源:origin: square/javapoet

public static String toJavaIdentifier(String suggestion) {
 StringBuilder result = new StringBuilder();
 for (int i = 0; i < suggestion.length(); ) {
  int codePoint = suggestion.codePointAt(i);
  if (i == 0
    && !Character.isJavaIdentifierStart(codePoint)
    && Character.isJavaIdentifierPart(codePoint)) {
   result.append("_");
  }
  int validCodePoint = Character.isJavaIdentifierPart(codePoint) ? codePoint : '_';
  result.appendCodePoint(validCodePoint);
  i += Character.charCount(codePoint);
 }
 return result.toString();
}

代码示例来源:origin: pxb1988/dex2jar

private static boolean isJavaIdentifier(String str) {
  if (str.length() < 1) {
    return false;
  }
  if (!Character.isJavaIdentifierStart(str.charAt(0))) {
    return false;
  }
  for (int i = 1; i < str.length(); i++) {
    if (!Character.isJavaIdentifierPart(str.charAt(i))) {
      return false;
    }
  }
  return true;
}

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

private final void _checkMatchEnd(String matchStr, int i, int c) throws IOException {
  // but actually only alphanums are problematic
  char ch = (char) c;
  if (Character.isJavaIdentifierPart(ch)) {
    _reportInvalidToken(matchStr.substring(0, i));
  }
}

代码示例来源:origin: org.easymock/easymock

public static boolean isJavaIdentifier(String mockName) {
  if (mockName.length() == 0 || mockName.indexOf(' ') > -1
      || !Character.isJavaIdentifierStart(mockName.charAt(0))) {
    return false;
  }
  for (char c : mockName.substring(1).toCharArray()) {
    if (!isJavaIdentifierPart(c)) {
      return false;
    }
  }
  return true;
}

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

private void checkFilename(String filename, int len)
  throws BadHttpRequest
{
  for (int i = 0; i < len; ++i) {
    char c = filename.charAt(i);
    if (!Character.isJavaIdentifierPart(c) && c != '.' && c != '/')
      throw new BadHttpRequest();
  }
  if (filename.indexOf("..") >= 0)
    throw new BadHttpRequest();
}

代码示例来源:origin: prestodb/presto

private final void _checkMatchEnd(String matchStr, int i, int ch) throws IOException {
  // but actually only alphanums are problematic
  char c = (char) _decodeCharForError(ch);
  if (Character.isJavaIdentifierPart(c)) {
    _reportInvalidToken(matchStr.substring(0, i));
  }
}

代码示例来源:origin: prestodb/presto

private final void _checkMatchEnd(String matchStr, int i, int ch) throws IOException {
  // but actually only alphanums are problematic
  char c = (char) _decodeCharForError(ch);
  if (Character.isJavaIdentifierPart(c)) {
    _reportInvalidToken(c, matchStr.substring(0, i));
  }
}

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

private final void _checkMatchEnd(String matchStr, int i, int ch) throws IOException {
  // but actually only alphanums are problematic
  char c = (char) _decodeCharForError(ch);
  if (Character.isJavaIdentifierPart(c)) {
    _reportInvalidToken(matchStr.substring(0, i));
  }
}

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

private final void _checkMatchEnd(String matchStr, int i, int ch) throws IOException {
  // but actually only alphanums are problematic
  char c = (char) _decodeCharForError(ch);
  if (Character.isJavaIdentifierPart(c)) {
    _reportInvalidToken(c, matchStr.substring(0, i));
  }
}

代码示例来源:origin: prestodb/presto

protected void _reportInvalidToken(int ch, String matchedPart, String msg)
  throws IOException
 {
   StringBuilder sb = new StringBuilder(matchedPart);
   /* Let's just try to find what appears to be the token, using
   * regular Java identifier character rules. It's just a heuristic,
   * nothing fancy here (nor fast).
   */
   while (true) {
     char c = (char) _decodeCharForError(ch);
     if (!Character.isJavaIdentifierPart(c)) {
       break;
     }
     sb.append(c);
     ch = _inputData.readUnsignedByte();
   }
   _reportError("Unrecognized token '"+sb.toString()+"': was expecting "+msg);
 }

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

protected void _reportInvalidToken(int ch, String matchedPart, String msg)
  throws IOException
 {
   StringBuilder sb = new StringBuilder(matchedPart);
   /* Let's just try to find what appears to be the token, using
   * regular Java identifier character rules. It's just a heuristic,
   * nothing fancy here (nor fast).
   */
   while (true) {
     char c = (char) _decodeCharForError(ch);
     if (!Character.isJavaIdentifierPart(c)) {
       break;
     }
     sb.append(c);
     ch = _inputData.readUnsignedByte();
   }
   _reportError("Unrecognized token '"+sb.toString()+"': was expecting "+msg);
 }

代码示例来源:origin: stanfordnlp/CoreNLP

protected String readJavaIdentifier() {
 readWhiteSpace();
 StringBuilder sb = new StringBuilder();
 char ch = read();
 if (Character.isJavaIdentifierStart(ch) && !isEOF) {
  sb.append(ch);
  ch = read();
  while (Character.isJavaIdentifierPart(ch) && !isEOF) {
   sb.append(ch);
   ch = read();
  }
 }
 unread();
 // log.info("Read text: ["+sb+"]");
 return sb.toString().intern();
}

代码示例来源:origin: alibaba/fastjson

String readName() {
  skipWhitespace();
  if (ch != '\\' && !Character.isJavaIdentifierStart(ch)) {
    throw new JSONPathException("illeal jsonpath syntax. " + path);
  }
  StringBuilder buf = new StringBuilder();
  while (!isEOF()) {
    if (ch == '\\') {
      next();
      buf.append(ch);
      if (isEOF()) {
        return buf.toString();
      }
      next();
      continue;
    }
    boolean identifierFlag = Character.isJavaIdentifierPart(ch);
    if (!identifierFlag) {
      break;
    }
    buf.append(ch);
    next();
  }
  if (isEOF() && Character.isJavaIdentifierPart(ch)) {
    buf.append(ch);
  }
  return buf.toString();
}

代码示例来源:origin: prestodb/presto

protected JsonToken _finishErrorToken() throws IOException
  {
    while (_inputPtr < _inputEnd) {
      int i = (int) _inputBuffer[_inputPtr++];

// !!! TODO: Decode UTF-8 characters properly...
//            char c = (char) _decodeCharForError(i);

      char ch = (char) i;
      if (Character.isJavaIdentifierPart(ch)) {
        // 11-Jan-2016, tatu: note: we will fully consume the character,
        // included or not, so if recovery was possible, it'd be off-by-one...
        _textBuffer.append(ch);
        if (_textBuffer.size() < MAX_ERROR_TOKEN_LENGTH) {
          continue;
        }
      }
      return _reportErrorToken(_textBuffer.contentsAsString());
    }
    return (_currToken = JsonToken.NOT_AVAILABLE);
  }

相关文章

Character类方法