Java 类org.apache.commons.lang.CharUtils 实例源码

项目:abina-common-util    文件:StringUtil.java   
/**
 * 对象属性转换为字段 例如:userName to user_name
 * 
 * @param property
 *            字段名
 * @return
 */
public static String propertyToField(String property) {
    if (null == property) {
        return "";
    }
    char[] chars = property.toCharArray();
    StringBuffer sb = new StringBuffer();
    for (char c : chars) {
        if (CharUtils.isAsciiAlphaUpper(c)) {
            sb.append("_" + StringUtils.lowerCase(CharUtils.toString(c)));
        } else {
            sb.append(c);
        }
    }
    return sb.toString().toUpperCase();
}
项目:ShapeChange    文件:EADocument.java   
/**
 * Replace all spaces with underscores and removes non-ASCII characters and
 * removes ASCII characters that are not printable.
 *
 * @param filename
 * @return
 */
private String escapeFileName(String filename) {

    if (filename == null) {

        return null;

    } else {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < filename.length(); i++) {
            char aChar = filename.charAt(i);
            if (aChar == ' ') {
                sb.append('_');
            } else if (CharUtils.isAsciiPrintable(aChar)) {
                sb.append(aChar);
            } else {
                // ignore character if not ASCII printable
            }
        }
        return sb.toString();
    }
}
项目:ef-orm    文件:JefTester.java   
private static void sampleAdd(Map<Integer, Integer> data, BufferedReader r)
        throws IOException {
    String line;
    while ((line = r.readLine()) != null) {
        for (char c : line.toCharArray()) {
            total++;
            Integer i = (int) c;
            if (!CharUtils.isAscii((char) i.intValue())) {
                totalStat++;
                if (data.containsKey(i)) {
                    data.put(i, data.get(i) + 1);
                } else {
                    data.put(i, 1);
                }
            }
        }
    }
}
项目:buildmetadata-maven-plugin    文件:ManifestHelper.java   
private static String normalize(final String key)
{
  final int length = key.length();
  final StringBuilder buffer = new StringBuilder(length);
  for (int i = 0; i < length; i++)
  {
    final char ch = key.charAt(i);
    if (CharUtils.isAsciiAlphanumeric(ch) || ch == '-' || ch == '_')
    {
      buffer.append(ch);
    }
    else
    {
      buffer.append('_');
    }
  }

  return buffer.toString();
}
项目:playweb    文件:JcrUtil.java   
public static String generateNodeName(String text, int maxLength) {
    String nodeName = text;
    final char[] chars = Normalizer.normalize(nodeName, Normalizer.Form.NFKD).toCharArray();
    final char[] newChars = new char[chars.length];
    int j = 0;
    for (char aChar : chars) {
        if (CharUtils.isAsciiAlphanumeric(aChar) || aChar == 32 || aChar == '-') {
            newChars[j++] = aChar;
        }
    }
    nodeName = new String(newChars, 0, j).trim().replaceAll(" ", "-").toLowerCase();
    if (nodeName.length() > maxLength) {
        nodeName = nodeName.substring(0, maxLength);
        if (nodeName.endsWith("-") && nodeName.length() > 2) {
            nodeName = nodeName.substring(0, nodeName.length() - 1);
        }
    }

    return StringUtils.isNotEmpty(nodeName) ? nodeName : "untitled";
}
项目:airsonic    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:goobi-viewer-indexer    文件:AbstractIndexer.java   
/**
 * Removes any non-alphanumeric trailing characters from the given string.
 * 
 * @param value
 * @return Cleaned up value.
 * @should clean up value correctly
 * @should throw IllegalArgumentException given null
 */
protected static String cleanUpNamedEntityValue(String value) {
    if (value == null) {
        throw new IllegalArgumentException("value may not be null");
    }
    StringBuilder sb = new StringBuilder(value);
    while (sb.length() > 1 && !CharUtils.isAsciiAlphanumeric(sb.charAt(sb.length() - 1))) {
        sb.deleteCharAt(sb.length() - 1);
    }
    while (sb.length() > 1 && !CharUtils.isAsciiAlphanumeric(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }

    return sb.toString();
}
项目:sonar-checkstyle    文件:CheckstyleTestUtils.java   
public static void assertSimilarXml(String expectedXml, String xml) {
    XMLUnit.setIgnoreWhitespace(true);
    final Diff diff;
    try {
        diff = XMLUnit.compareXML(xml, expectedXml);
    }
    catch (SAXException | IOException ex) {
        throw new IllegalArgumentException("Could not run XML comparison", ex);
    }
    final String message = "Diff: " + diff + CharUtils.LF + "XML: " + xml;
    assertTrue(message, diff.similar());
}
项目:spring-oauth-client    文件:JavaPropertySetStrategy.java   
private String keyToField(String key) {
    if (key.length() == 0) {
        return key;
    }

    StringBuilder sb = new StringBuilder();
    char[] chars = key.toCharArray();

    //If first char is Uppercase, update it to lowercase
    if (key.indexOf(SEPARATOR) == -1 && ('A' <= chars[0] && chars[0] <= 'Z')) {
        chars[0] = (char) (chars[0] + 'a' - 'A');
        return String.valueOf(chars);
    }


    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (c == SEPARATOR) {
            int j = i + 1;
            if (j < chars.length) {
                sb.append(StringUtils.upperCase(CharUtils.toString(chars[j])));
                i++;
            }
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}
项目:subsonic    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:springmvc-raml-plugin    文件:ResourceUrlStyleChecker.java   
@Override
public Set<StyleIssue> checkResourceStyle(String name, RamlResource resource,
        IssueLocation location, RamlRoot raml) {
    logger.debug("Checking resource " + name);
    Set<StyleIssue> issues = new LinkedHashSet<>();

    if (!NamingHelper.isUriParamResource(name) && CHARS_NOT_ALLOWED.matcher(name).find()) {
        issues.add(new StyleIssue(location, SPECIAL_CHARS_IN_URL , resource, null));
    }

    if (CharUtils.isAsciiAlphaUpper(name.charAt(0))) {
        issues.add(new StyleIssue(location, CAPITALISED_RESOURCE, resource, null));
    }
    return issues;
}
项目:ef-orm    文件:JefTester.java   
static int getFixedLenth(String ss, int start, int len) {
    int offset = start;
    int currentLen = 0;
    while (offset < ss.length() && currentLen < len) {
        char c = ss.charAt(offset++);
        currentLen += jef.tools.string.CharUtils.isAsian(c) ? 2 : 1;
    }
    return offset;
}
项目:tajo    文件:TestStringUtil.java   
@Test
public void testUnicodeEscapedDelimiter() {
  for (int i = 0; i < 128; i++) {
    char c = (char) i;
    String delimiter = CharUtils.unicodeEscaped(c);
    String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
    assertEquals(delimiter, escapedDelimiter);
    assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
    assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
  }
}
项目:tajo    文件:TestStringUtil.java   
@Test
public void testUnescapedDelimiter() {
  for (int i = 0; i < 128; i++) {
    char c = (char) i;
    String delimiter = String.valueOf(c);
    String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
    assertEquals(CharUtils.unicodeEscaped(c), escapedDelimiter);
    assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
    assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
  }
}
项目:FutureSonic-Server    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:madsonic-server-5.1    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:madsonic-server-5.0    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:madsonic-server-5.0    文件:UrlTag.java   
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
项目:jbpm-data-modeler    文件:ValidationUtils.java   
public static Boolean isJavaIdentifier(String s) {
    if (StringUtils.isBlank(s)) return false;
    if (!SourceVersion.isName(s)) return false;
    for (int i = 1; i < s.length(); i++) {
        if (!CharUtils.isAsciiPrintable(s.charAt(i))) return false;
    }
    return true;
}
项目:tajo    文件:DescTableCommand.java   
protected String toFormattedString(TableDesc desc) {
  StringBuilder sb = new StringBuilder();
  sb.append("\ntable name: ").append(desc.getName()).append("\n");
  sb.append("table uri: ").append(desc.getUri()).append("\n");
  sb.append("store type: ").append(desc.getMeta().getDataFormat()).append("\n");
  if (desc.getStats() != null) {

    long row = desc.getStats().getNumRows();
    String rowText = row == TajoConstants.UNKNOWN_ROW_NUMBER ? "unknown" : row + "";
    sb.append("number of rows: ").append(rowText).append("\n");
    sb.append("volume: ").append(
        FileUtil.humanReadableByteCount(desc.getStats().getNumBytes(),
            true)).append("\n");
  }
  sb.append("Options:\n");
  for(Map.Entry<String, String> entry : desc.getMeta().toMap().entrySet()){

    /*
    *  Checks whether the character is ASCII 7 bit printable.
    *  For example, a printable unicode '\u007c' become the character ‘|’.
    *
    *  Control-chars : ctrl-a(\u0001), tab(\u0009) ..
    *  Printable-chars : '|'(\u007c), ','(\u002c) ..
    * */

    String value = entry.getValue();
    String unescaped = StringEscapeUtils.unescapeJava(value);
    if (unescaped.length() == 1 && CharUtils.isAsciiPrintable(unescaped.charAt(0))) {
      value = unescaped;
    }
    sb.append("\t").append("'").append(entry.getKey()).append("'").append("=")
        .append("'").append(value).append("'").append("\n");
  }
  sb.append("\n");
  sb.append("schema: \n");

  for(int i = 0; i < desc.getSchema().size(); i++) {
    Column col = desc.getSchema().getColumn(i);
    sb.append(col.getSimpleName()).append("\t").append(col.getTypeDesc());
    sb.append("\n");
  }

  sb.append("\n");
  if (desc.getPartitionMethod() != null) {
    PartitionMethodDesc partition = desc.getPartitionMethod();
    sb.append("Partitions: \n");

    sb.append("type:").append(partition.getPartitionType().name()).append("\n");

    sb.append("columns:").append(":");
    sb.append(StringUtils.join(partition.getExpressionSchema().toArray()));
  }

  return sb.toString();
}
项目:tajo    文件:StringUtils.java   
public static String unicodeEscapedDelimiter(char c) {
  return CharUtils.unicodeEscaped(c);
}
项目:ali-idea-plugin    文件:Lexer.java   
Lexeme next() {
    if(next == null) {
        while(pos < str.length() && Character.isWhitespace(str.charAt(pos))) {
            ++pos;
        }
        if(pos > str.length()) {
            throw new NoSuchElementException();
        }
        if(pos == str.length()) {
            next = new Lexeme(pos, pos, "", Type.END);
            return next;
        }
        int startPos = pos;
        if(str.charAt(pos) == '\'' || str.charAt(pos) == '"') {
            int end = pos;
            do {
                ++end;
            } while(end < str.length() && str.charAt(end) != str.charAt(pos));
            if(end == str.length() || str.charAt(end) != str.charAt(pos)) {
                throw new ParserException("Unterminated literal", pos);
            }
            pos = end + 1;
            next = new Lexeme(startPos, end, str.substring(startPos + 1, end), Type.VALUE);
            return next;
        }
        for(Type type: Type.values()) {
            if(type.getRepr() == null) {
                continue;
            }

            if(str.substring(pos).toUpperCase().startsWith(type.getRepr())) {
                int len = type.getRepr().length();
                if(CharUtils.isAsciiAlphanumeric(type.getRepr().charAt(len - 1)) && str.length() > pos + len && CharUtils.isAsciiAlphanumeric(str.charAt(pos + len))) {
                    // don't split words to match lexeme
                    continue;
                }
                next = new Lexeme(startPos, startPos + len, str.substring(startPos, startPos + len), type);
                pos += len;
                return next;
            }
        }
        do {
            ++pos;
        } while(pos < str.length() && allowedInLiteral(str.charAt(pos)));
        next = new Lexeme(startPos, pos, str.substring(startPos, pos), Type.VALUE);
    }
    return next;
}
项目:ShapeChange    文件:JsonSchema.java   
/**
 * <p>See https://tools.ietf.org/html/rfc7159: characters that must be escaped quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)</p>
 * <p>Control characters that are likely to occur in EA models, especially when using memo tagged values: \n, \r and \t.</p>
 */
private String escape(String s2) {
    return StringUtils.replaceEach(s2, new String[]{"\"", "\\", "\n", "\r", "\t"} , new String[]{"\\\"", "\\\\", CharUtils.unicodeEscaped('\n'),  CharUtils.unicodeEscaped('\r'), CharUtils.unicodeEscaped('\t')});
}