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

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

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

Character.isISOControl介绍

[英]Indicates whether the specified character is an ISO control character.
[中]指示指定的字符是否为ISO控制字符。

代码示例

代码示例来源:origin: SonarSource/sonarqube

private static void checkBufferForISOControlChars(byte[] buffer, int off, int len) {
  for (int i = off; i < len; i++) {
   char streamChar = (char) buffer[i];
   if (Character.isISOControl(streamChar) && streamChar != '\n') {
    // replace control chars by a simple space
    buffer[i] = ' ';
   }
  }
 }
}

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

protected final static String _getCharDesc(int ch)
{
  char c = (char) ch;
  if (Character.isISOControl(c)) {
    return "(CTRL-CHAR, code "+ch+")";
  }
  if (ch > 255) {
    return "'"+c+"' (code "+ch+" / 0x"+Integer.toHexString(ch)+")";
  }
  return "'"+c+"' (code "+ch+")";
}

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

protected final static String _getCharDesc(int ch)
{
  char c = (char) ch;
  if (Character.isISOControl(c)) {
    return "(CTRL-CHAR, code "+ch+")";
  }
  if (ch > 255) {
    return "'"+c+"' (code "+ch+" / 0x"+Integer.toHexString(ch)+")";
  }
  return "'"+c+"' (code "+ch+")";
}

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

/**
 * Indicates whether the specified character is an ISO control character.
 *
 * @param c
 *            the character to check.
 * @return {@code true} if {@code c} is an ISO control character;
 *         {@code false} otherwise.
 */
public static boolean isISOControl(char c) {
  return isISOControl((int) c);
}

代码示例来源:origin: iBotPeaches/Apktool

private static boolean isPrintableChar(char c) {
    Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
    return !Character.isISOControl(c) && c != KeyEvent.CHAR_UNDEFINED
        && block != null && block != Character.UnicodeBlock.SPECIALS;
  }
}

代码示例来源:origin: jenkinsci/jenkins

private static String toPrintableName(String name) {
  StringBuilder printableName = new StringBuilder();
  for( int i=0; i<name.length(); i++ ) {
    char ch = name.charAt(i);
    if(Character.isISOControl(ch))
      printableName.append("\\u").append((int)ch).append(';');
    else
      printableName.append(ch);
  }
  return printableName.toString();
}

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

static String characterLiteralWithoutSingleQuotes(char c) {
 // see https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.6
 switch (c) {
  case '\b': return "\\b"; /* \u0008: backspace (BS) */
  case '\t': return "\\t"; /* \u0009: horizontal tab (HT) */
  case '\n': return "\\n"; /* \u000a: linefeed (LF) */
  case '\f': return "\\f"; /* \u000c: form feed (FF) */
  case '\r': return "\\r"; /* \u000d: carriage return (CR) */
  case '\"': return "\"";  /* \u0022: double quote (") */
  case '\'': return "\\'"; /* \u0027: single quote (') */
  case '\\': return "\\\\";  /* \u005c: backslash (\) */
  default:
   return isISOControl(c) ? String.format("\\u%04x", (int) c) : Character.toString(c);
 }
}

代码示例来源:origin: org.codehaus.jackson/jackson-core-asl

protected final static String _getCharDesc(int ch)
{
  char c = (char) ch;
  if (Character.isISOControl(c)) {
    return "(CTRL-CHAR, code "+ch+")";
  }
  if (ch > 255) {
    return "'"+c+"' (code "+ch+" / 0x"+Integer.toHexString(ch)+")";
  }
  return "'"+c+"' (code "+ch+")";
}

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

static int codePointIndexToCharIndex(String s, int codePointCount) {
 for (int i = 0, j = 0, length = s.length(), c; i < length; i += Character.charCount(c)) {
  if (j == codePointCount) {
   return i;
  }
  c = s.codePointAt(i);
  if ((Character.isISOControl(c) && c != '\n' && c != '\r')
    || c == Buffer.REPLACEMENT_CHARACTER) {
   return -1;
  }
  j++;
 }
 return s.length();
}

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

/**
 * Write HTML escape sequence for the specified Unicode character, unless
 * it's an ISO control character, in which case it is ignored.
 * @param out a defined, target instance
 * @param c the character to write
 * @throws IOException if an error occurs while writing to the stream
 */
public static void writeUnicodeChar(Writer out, char c)
    throws IOException {
  if (!Character.isISOControl(c)) {
    out.append("&#").append(Integer.toString(c)).append(';');
  }
}

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

private static int getChunkSize(String hex) {
  hex = hex.trim();
  for (int i = 0; i < hex.length(); i ++) {
    char c = hex.charAt(i);
    if (c == ';' || Character.isWhitespace(c) || Character.isISOControl(c)) {
      hex = hex.substring(0, i);
      break;
    }
  }
  return Integer.parseInt(hex, 16);
}

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

private static int nextTestWhitespaceLength(boolean match, String str,
  int off) {
  int i = 0;
  while (off + i < str.length()) {
    int cp = Character.codePointAt(str, off + i);
    if ((Character.isWhitespace(cp) || Character.isISOControl(cp)) !=
      match) {
      return i;
    }
    i += Character.charCount(cp);
  }
  return str.length() - off;
}

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

private static void skipControlCharactersStandard(ByteBuf undecodedChunk) {
  for (;;) {
    char c = (char) undecodedChunk.readUnsignedByte();
    if (!Character.isISOControl(c) && !Character.isWhitespace(c)) {
      undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);
      break;
    }
  }
}

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

@Override
public void ensureValid(String name, Object value) {
  String s = (String) value;
  if (s == null) {
    // This can happen during creation of the config object due to no default value being defined for the
    // name configuration - a missing name parameter is caught when checking for mandatory parameters,
    // thus we can ok a null value here
    return;
  } else if (s.isEmpty()) {
    throw new ConfigException(name, value, "String may not be empty");
  }
  // Check name string for illegal characters
  ArrayList<Integer> foundIllegalCharacters = new ArrayList<>();
  for (int i = 0; i < s.length(); i++) {
    if (Character.isISOControl(s.codePointAt(i))) {
      foundIllegalCharacters.add(s.codePointAt(i));
    }
  }
  if (!foundIllegalCharacters.isEmpty()) {
    throw new ConfigException(name, value, "String may not contain control sequences but had the following ASCII chars: " + Utils.join(foundIllegalCharacters, ", "));
  }
}

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

/**
 * @param bindex Relative index within base64 character unit; between 0
 *   and 3 (as unit has exactly 4 characters)
 */
protected IllegalArgumentException reportInvalidBase64Char(Base64Variant b64variant, int ch, int bindex, String msg) throws IllegalArgumentException {
  String base;
  if (ch <= INT_SPACE) {
    base = String.format("Illegal white space character (code 0x%s) as character #%d of 4-char base64 unit: can only used between units",
        Integer.toHexString(ch), (bindex+1));
  } else if (b64variant.usesPaddingChar(ch)) {
    base = "Unexpected padding character ('"+b64variant.getPaddingChar()+"') as character #"+(bindex+1)+" of 4-char base64 unit: padding only legal as 3rd or 4th character";
  } else if (!Character.isDefined(ch) || Character.isISOControl(ch)) {
    // Not sure if we can really get here... ? (most illegal xml chars are caught at lower level)
    base = "Illegal character (code 0x"+Integer.toHexString(ch)+") in base64 content";
  } else {
    base = "Illegal character '"+((char)ch)+"' (code 0x"+Integer.toHexString(ch)+") in base64 content";
  }
  if (msg != null) {
    base = base + ": " + msg;
  }
  return new IllegalArgumentException(base);
}

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

/**
 * @param bindex Relative index within base64 character unit; between 0
 *   and 3 (as unit has exactly 4 characters)
 */
protected IllegalArgumentException reportInvalidBase64Char(Base64Variant b64variant, int ch, int bindex, String msg) throws IllegalArgumentException {
  String base;
  if (ch <= INT_SPACE) {
    base = String.format("Illegal white space character (code 0x%s) as character #%d of 4-char base64 unit: can only used between units",
        Integer.toHexString(ch), (bindex+1));
  } else if (b64variant.usesPaddingChar(ch)) {
    base = "Unexpected padding character ('"+b64variant.getPaddingChar()+"') as character #"+(bindex+1)+" of 4-char base64 unit: padding only legal as 3rd or 4th character";
  } else if (!Character.isDefined(ch) || Character.isISOControl(ch)) {
    // Not sure if we can really get here... ? (most illegal xml chars are caught at lower level)
    base = "Illegal character (code 0x"+Integer.toHexString(ch)+") in base64 content";
  } else {
    base = "Illegal character '"+((char)ch)+"' (code 0x"+Integer.toHexString(ch)+") in base64 content";
  }
  if (msg != null) {
    base = base + ": " + msg;
  }
  return new IllegalArgumentException(base);
}

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

/**
 * @param bindex Relative index within base64 character unit; between 0
 *   and 3 (as unit has exactly 4 characters)
 */
protected void _reportInvalidBase64(char ch, int bindex, String msg)
  throws IllegalArgumentException
{
  String base;
  if (ch <= INT_SPACE) {
    base = "Illegal white space character (code 0x"+Integer.toHexString(ch)+") as character #"+(bindex+1)+" of 4-char base64 unit: can only used between units";
  } else if (usesPaddingChar(ch)) {
    base = "Unexpected padding character ('"+getPaddingChar()+"') as character #"+(bindex+1)+" of 4-char base64 unit: padding only legal as 3rd or 4th character";
  } else if (!Character.isDefined(ch) || Character.isISOControl(ch)) {
    // Not sure if we can really get here... ? (most illegal xml chars are caught at lower level)
    base = "Illegal character (code 0x"+Integer.toHexString(ch)+") in base64 content";
  } else {
    base = "Illegal character '"+ch+"' (code 0x"+Integer.toHexString(ch)+") in base64 content";
  }
  if (msg != null) {
    base = base + ": " + msg;
  }
  throw new IllegalArgumentException(base);
}

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

/**
 * Returns true if the body in question probably contains human readable text. Uses a small sample
 * of code points to detect unicode control characters commonly used in binary file signatures.
 */
static boolean isPlaintext(Buffer buffer) {
 try {
  Buffer prefix = new Buffer();
  long byteCount = buffer.size() < 64 ? buffer.size() : 64;
  buffer.copyTo(prefix, 0, byteCount);
  for (int i = 0; i < 16; i++) {
   if (prefix.exhausted()) {
    break;
   }
   int codePoint = prefix.readUtf8CodePoint();
   if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) {
    return false;
   }
  }
  return true;
 } catch (EOFException e) {
  return false; // Truncated UTF-8 sequence.
 }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Check if the given name is suitable as a name
 * for job, view, etc.
 *
 * @throws Failure
 *      if the given name is not good
 */
public static void checkGoodName(String name) throws Failure {
  if(name==null || name.length()==0)
    throw new Failure(Messages.Hudson_NoName());
  if(".".equals(name.trim()))
    throw new Failure(Messages.Jenkins_NotAllowedName("."));
  if("..".equals(name.trim()))
    throw new Failure(Messages.Jenkins_NotAllowedName(".."));
  for( int i=0; i<name.length(); i++ ) {
    char ch = name.charAt(i);
    if(Character.isISOControl(ch)) {
      throw new Failure(Messages.Hudson_ControlCodeNotAllowed(toPrintableName(name)));
    }
    if("?*/\\%!@#$^&|<>[]:;".indexOf(ch)!=-1)
      throw new Failure(Messages.Hudson_UnsafeChar(ch));
  }
  // looks good
}

代码示例来源:origin: google/guava

@GwtIncompatible // Character.isISOControl
public void testJavaIsoControl() {
 for (int c = 0; c <= Character.MAX_VALUE; c++) {
  assertEquals(
    "" + c, Character.isISOControl(c), CharMatcher.javaIsoControl().matches((char) c));
 }
}

相关文章

Character类方法