类org.apache.commons.lang3.CharUtils源码实例Demo

下面列出了怎么用org.apache.commons.lang3.CharUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: org.hl7.fhir.core   文件: ADLImporter.java
private String generateToken(String atCode, boolean upFirst) {
	if (!texts.containsKey(atCode))
		return atCode;
  String text = texts.get(atCode).getText();
  boolean lastText = false;
  StringBuilder b = new StringBuilder();
  for (char c : text.toCharArray()) {
  	boolean ok = CharUtils.isAscii(c);
  	if (ok) 
  		if (b.length() == 0)
         ok = Character.isAlphabetic(c);
  		else
  			ok = Character.isAlphabetic(c) || Character.isDigit(c);
  	if (!ok) {
  		lastText = false;
  	} else {
  		if (!lastText && (b.length() > 0 || upFirst)) 
  			b.append(Character.toUpperCase(c));
  		else
  			b.append(Character.toLowerCase(c));
  		lastText = true;
  	}
  }
 	return b.toString();
}
 
源代码2 项目: DataLink   文件: Configuration.java
/**
 * 根据用户提供的json path,寻址Character对象
 * 
 * @return Character对象,如果path不存在或者Character不存在,返回null
 */
public Character getChar(final String path) {
	String result = this.getString(path);
	if (null == result) {
		return null;
	}

	try {
		return CharUtils.toChar(result);
	} catch (Exception e) {
		throw DataXException.asDataXException(
				CommonErrorCode.CONFIG_ERROR,
				String.format("任务读取配置文件出错. 因为配置文件路径[%s] 值非法,期望是字符类型: %s. 请检查您的配置并作出修改.", path,
						e.getMessage()));
	}
}
 
源代码3 项目: raptor   文件: CaseFormatUtil.java
/**
 * 判断str是哪种命名格式的,不能保证一定判断对,慎用
 *
 * @param str
 * @return
 */
public static CaseFormat determineFormat(String str) {
    Preconditions.checkNotNull(str);
    String[] split = str.split("_");
    List<String> splitedStrings = Arrays.stream(split).map(String::trim).filter(StringUtils::isNotBlank).collect(Collectors.toList());

    if (splitedStrings.size() == 1) {
        //camel
        if (CharUtils.isAsciiAlphaUpper(splitedStrings.get(0).charAt(0))) {
            return CaseFormat.UPPER_CAMEL;
        } else {
            return CaseFormat.LOWER_CAMEL;
        }
    } else if (splitedStrings.size() > 1) {
        //underscore
        if (CharUtils.isAsciiAlphaUpper(splitedStrings.get(0).charAt(0))) {
            return CaseFormat.UPPER_UNDERSCORE;
        } else {
            return CaseFormat.LOWER_UNDERSCORE;
        }
    }else{
        //判断不出那个
        return CaseFormat.LOWER_CAMEL;
    }
}
 
源代码4 项目: jingtum-lib-java   文件: NameUtils.java
/**
 * covert field name to column name userName --> user_name
 * covert class name to column name UserName -- > user_name
 */
public static String getUnderlineName(String propertyName) {
	if (null == propertyName) {
		return "";
	}
	StringBuilder sbl = new StringBuilder(propertyName);
	sbl.setCharAt(0, Character.toLowerCase(sbl.charAt(0)));
	propertyName = sbl.toString();
	char[] chars = propertyName.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();
}
 
源代码5 项目: tracingplane-java   文件: JavaCompilerUtils.java
/**
 * Replaces characters preceded by underscores with uppercase version, eg:
 * 
 * 'hello_world' => 'helloWorld' 'hello_World' => 'helloWorld' 'hello__world' => 'hello_World'
 */
public static String formatCamelCase(String name) {
    StringBuilder formatted = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
        char ci = name.charAt(i);
        if (i < name.length() - 1 && ci == '_' && CharUtils.isAscii(ci)) {
            char cii = name.charAt(i + 1);
            if (CharUtils.isAsciiAlphaLower(cii)) {
                formatted.append(StringUtils.upperCase(String.valueOf(cii)));
                i++;
            }
        } else {
            formatted.append(name.charAt(i));
        }
    }
    return formatted.toString();
}
 
源代码6 项目: FX-AlgorithmTrading   文件: NumberUtility.java
/**
 * 文字と数字の混ざった文字列から、数字のみを取り出してLongを作成します。
 * 主に、外部で採番されたIDから数字のIDを作成するために使用します。
 *
 * @param stringWithNumber
 * @return
 */
public static Long extractNumberString(Long headerNumber, String stringWithNumber) {
    StringBuilder sb = new StringBuilder(30);
    if (headerNumber != null) {
        sb.append(headerNumber.longValue());
    }

    for (int i = 0; i < stringWithNumber.length(); i++) {
        if (CharUtils.isAsciiNumeric(stringWithNumber.charAt(i))) {
            sb.append(stringWithNumber.charAt(i));
        }
    }

    if (sb.length() == 0) {
        return NumberUtils.LONG_ZERO;
    } else if(sb.length() >= 19) {
        // 19桁以上の場合は先頭の18文字を使用する
        return Long.valueOf(sb.substring(0, 18));
    } else {
        return Long.valueOf(sb.toString());
    }
}
 
源代码7 项目: htmlunit   文件: DateTimeFormatTest.java
private void test(final String... string) throws Exception {
    final StringBuilder html = new StringBuilder(HtmlPageTest.STANDARDS_MODE_PREFIX_
        + "<html><head>\n"
        + "<script>\n"
        + "  function test() {\n"
        + "    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));\n"
        + "    try {\n");
    for (int i = 0; i < string.length - 1; i++) {
        html.append(string[i]).append("\n");
    }
    html.append(
        "      alert(" + string[string.length - 1] + ");\n"
        + "    } catch(e) {alert('exception')}\n"
        + "  }\n"
        + "</script>\n"
        + "</head><body onload='test()'>\n"
        + "</body></html>");

    try {
        loadPageWithAlerts2(html.toString());
    }
    catch (final ComparisonFailure e) {
        final String msg = e.getMessage();
        for (int i = 0; i < msg.length(); i++) {
            final char c = msg.charAt(i);
            if (CharUtils.isAscii(c)) {
                System.out.print(c);
            }
            else {
                System.out.print(CharUtils.unicodeEscaped(c));
            }
        }
        System.out.println();
        throw e;
    }
}
 
源代码8 项目: jingtum-lib-java   文件: NameUtils.java
/**
 * covert field name to column name
 */
public static String getCamelName(String fieldName) {
	if (null == fieldName) {
		return "";
	}
	StringBuffer sb = new StringBuffer();
	if (fieldName.contains("_")) {
		fieldName = fieldName.toLowerCase();
	}
	char[] chars = fieldName.toCharArray();
	if (isUpper(chars[0])) {
		chars[0] = toLower(chars[0]);
	}
	for (int i = 0; i < chars.length; i++) {
		char c = chars[i];
		if (c == '_') {
			int j = i + 1;
			if (j < chars.length) {
				sb.append(StringUtils.upperCase(CharUtils.toString(chars[j])));
				i++;
			}
		} else {
			sb.append(c);
		}
	}
	return sb.toString();
}
 
源代码9 项目: cyberduck   文件: AbstractHostCollection.java
/**
 * @param h Bookmark
 * @return User comment for bookmark or null
 */
public String getComment(final Host h) {
    if(StringUtils.isNotBlank(h.getComment())) {
        return StringUtils.remove(StringUtils.remove(h.getComment(), CharUtils.LF), CharUtils.CR);
    }
    return null;
}
 
源代码10 项目: cyberduck   文件: PermissionOverwrite.java
public void parse(char c) {
    if(CharUtils.isAsciiNumeric(c)) {
        int intValue = CharUtils.toIntValue(c);
        this.read = (intValue & 4) > 0;
        this.write = (intValue & 2) > 0;
        this.execute = (intValue & 1) > 0;
    }
    else {
        if(c == MULTIPLE_VALUES) {
            this.read = this.write = this.execute = null;
        }
    }
}
 
源代码11 项目: spring-boot-start-current   文件: StringProUtils.java
public static String nonAsciiToUnicode ( String s ) {
    StringBuffer sb = new StringBuffer( s.length() );
    for ( Character c : s.toCharArray() ) {
        if ( ! CharUtils.isAscii( c ) ) {
            sb.append( CharUtils.unicodeEscaped( c ) );
        } else {
            sb.append( c );
        }
    }

    return sb.toString();
}
 
源代码12 项目: api-compiler   文件: ApiNameGenerator.java
/**
 * Replaces all non alphanumeric characters in input string with {@link
 * ApiNameGenerator#API_NAME_FILLER_CHAR}
 */
private static String replaceNonAlphanumericChars(String input, boolean allowDots) {
  StringBuilder alphaNumeric = new StringBuilder();
  for (char hostnameChar : input.toCharArray()) {
    if (CharUtils.isAsciiAlphanumeric(hostnameChar) || (allowDots && hostnameChar == SEPARATOR)) {
      alphaNumeric.append(hostnameChar);
    } else {
      alphaNumeric.append(API_NAME_FILLER_CHAR);
    }
  }
  return alphaNumeric.toString();
}
 
源代码13 项目: api-compiler   文件: ApiNameGenerator.java
private static boolean startsWithAlphaOrUnderscore(String string) {
  if (Strings.isNullOrEmpty(string)) {
    return false;
  }
  char firstCharacter = string.charAt(0);
  return CharUtils.isAsciiAlpha(firstCharacter) || firstCharacter == API_NAME_FILLER_CHAR;
}
 
源代码14 项目: herd   文件: Hive13DdlGenerator.java
/**
 * Gets the DDL character value based on the specified configured character value. This method supports UTF-8 encoded strings and will "Hive" escape any
 * non-ASCII printable characters using '\(value)'.
 *
 * @param string the configured character value.
 * @param escapeSingleBackslash specifies if we need to escape a single backslash character with an extra backslash
 *
 * @return the DDL character value.
 */
public String getDdlCharacterValue(String string, boolean escapeSingleBackslash)
{
    // Assume the empty string for the return value.
    StringBuilder returnValueStringBuilder = new StringBuilder();

    // If we have an actual character, set the return value based on our rules.
    if (StringUtils.isNotEmpty(string))
    {
        // Convert the string to UTF-8 so we can the proper characters that were sent via XML.
        String utf8String = new String(string.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);

        // Loop through each character and add each one to the return value.
        for (int i = 0; i < utf8String.length(); i++)
        {
            // Default to the character itself.
            Character character = string.charAt(i);
            String nextValue = character.toString();

            // If the character isn't ASCII printable, then "Hive" escape it.
            if (!CharUtils.isAsciiPrintable(character))
            {
                // If the character is unprintable, then display it as the ASCII octal value in \000 format.
                nextValue = String.format("\\%03o", (int) character);
            }

            // Add this character to the return value.
            returnValueStringBuilder.append(nextValue);
        }

        // Check if we need to escape a single backslash character with an extra backslash.
        if (escapeSingleBackslash && returnValueStringBuilder.toString().equals("\\"))
        {
            returnValueStringBuilder.append('\\');
        }
    }

    // Return the value.
    return returnValueStringBuilder.toString();
}
 
源代码15 项目: OpenEstate-IO   文件: RandomStringUtilsTest.java
private static boolean isAsciiAlpha(String value) {
    for (char c : value.toCharArray()) {
        if (!CharUtils.isAsciiAlpha(c))
            return false;
    }
    return true;
}
 
源代码16 项目: OpenEstate-IO   文件: RandomStringUtilsTest.java
private static boolean isAsciiAlphanumeric(String value) {
    for (char c : value.toCharArray()) {
        if (!CharUtils.isAsciiAlphanumeric(c))
            return false;
    }
    return true;
}
 
源代码17 项目: OpenEstate-IO   文件: RandomStringUtilsTest.java
private static boolean isAsciiNumeric(String value) {
    for (char c : value.toCharArray()) {
        if (!CharUtils.isAsciiNumeric(c))
            return false;
    }
    return true;
}
 
源代码18 项目: count-db   文件: InspectFile.java
private static String replaceNonAscii(String valueToPrint) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < valueToPrint.length(); i++) {
        if (CharUtils.isAscii(valueToPrint.charAt(i))) {
            result.append(valueToPrint.charAt(i));
        } else {
            result.append("?");
        }
    }
    return result.toString();
}
 
源代码19 项目: gradle-in-action-source   文件: ToDoApp.java
public static void main(String args[]) {
    CommandLineInputHandler commandLineInputHandler = new CommandLineInputHandler();
    char command = DEFAULT_INPUT;

    while (CommandLineInput.EXIT.getShortCmd() != command) {
        commandLineInputHandler.printOptions();
        String input = commandLineInputHandler.readInput();
        System.out.println("-----> " + CharUtils.toChar(input, DEFAULT_INPUT));
        command = CharUtils.toChar(input, DEFAULT_INPUT);
        CommandLineInput commandLineInput = CommandLineInput.getCommandLineInputForInput(command);
        commandLineInputHandler.processInput(commandLineInput);
    }
}
 
源代码20 项目: MyCommunity   文件: SensitiveFilter.java
private boolean isSymbol(Character c) {
    // 0x2E80~0x9FFF 是东亚文字范围
    return !CharUtils.isAsciiAlphanumeric(c) && (c < 0x2E80 || c > 0x9FFF);
}
 
源代码21 项目: onedev   文件: TextQuery.java
private boolean isWordChar(char ch) {
	return CharUtils.isAsciiAlphanumeric(ch) || ch == '_';
}
 
源代码22 项目: cyberduck   文件: Local.java
public Local(final String parent, final String name, final String delimiter) {
    this(parent.endsWith(delimiter) ?
        String.format("%s%s", parent, name) :
        String.format("%s%c%s", parent, CharUtils.toChar(delimiter), name));
}
 
源代码23 项目: cyberduck   文件: Local.java
public Local(final Local parent, final String name, final String delimiter) {
    this(parent.isRoot() ?
        String.format("%s%s", parent.getAbsolute(), name) :
        String.format("%s%c%s", parent.getAbsolute(), CharUtils.toChar(delimiter), name));
}
 
源代码24 项目: nifi   文件: JacksonCSVRecordReader.java
public JacksonCSVRecordReader(final InputStream in, final ComponentLog logger, final RecordSchema schema, final CSVFormat csvFormat, final boolean hasHeader, final boolean ignoreHeader,
                              final String dateFormat, final String timeFormat, final String timestampFormat, final String encoding) throws IOException {
    super(logger, schema, hasHeader, ignoreHeader, dateFormat, timeFormat, timestampFormat);

    final Reader reader = new InputStreamReader(new BOMInputStream(in));

    CsvSchema.Builder csvSchemaBuilder = CsvSchema.builder()
            .setColumnSeparator(csvFormat.getDelimiter())
            .setLineSeparator(csvFormat.getRecordSeparator())
            // Can only use comments in Jackson CSV if the correct marker is set
            .setAllowComments("#" .equals(CharUtils.toString(csvFormat.getCommentMarker())))
            // The call to setUseHeader(false) in all code paths is due to the way Jackson does data binding/mapping. Missing or extra columns may not
            // be handled correctly when using the header for mapping.
            .setUseHeader(false);

    csvSchemaBuilder = (csvFormat.getQuoteCharacter() == null) ? csvSchemaBuilder : csvSchemaBuilder.setQuoteChar(csvFormat.getQuoteCharacter());
    csvSchemaBuilder = (csvFormat.getEscapeCharacter() == null) ? csvSchemaBuilder : csvSchemaBuilder.setEscapeChar(csvFormat.getEscapeCharacter());

    if (hasHeader) {
        if (ignoreHeader) {
            csvSchemaBuilder = csvSchemaBuilder.setSkipFirstDataRow(true);
        }
    }

    CsvSchema csvSchema = csvSchemaBuilder.build();

    // Add remaining config options to the mapper
    List<CsvParser.Feature> features = new ArrayList<>();
    features.add(CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS);
    if (csvFormat.getIgnoreEmptyLines()) {
        features.add(CsvParser.Feature.SKIP_EMPTY_LINES);
    }
    if (csvFormat.getTrim()) {
        features.add(CsvParser.Feature.TRIM_SPACES);
    }

    ObjectReader objReader = mapper.readerFor(String[].class)
            .with(csvSchema)
            .withFeatures(features.toArray(new CsvParser.Feature[features.size()]));

    recordStream = objReader.readValues(reader);
}
 
 类所在包
 同包方法