Java 类org.apache.commons.lang3.CharUtils 实例源码
项目:datax
文件: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()));
}
}
项目: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();
}
项目:Browscap4j
文件:RegexResolver.java
/**
* Takes in a name pattern from the browscap.csv file,
* and returns a Regex representation of it.
* @param namePattern the name pattern
* @return regex for the name pattern
*/
public static String toRegex(String namePattern) {
final StringBuilder patternBuilder = new StringBuilder();
patternBuilder.append("^");
for (final char c : namePattern.toCharArray()) {
switch (c) {
case '*':
patternBuilder.append(".*?");
break;
case '?':
patternBuilder.append(".");
break;
default:
if(CharUtils.isAsciiAlphanumeric(c) || c==' '){
//The char c is either an alphabet,or a number or a whitespace,and NOT a regex wildcard.
patternBuilder.append(c);
}else {
patternBuilder.append("\\").append(c);
}
}
}
patternBuilder.append("$");
final String pattern = patternBuilder.toString().toLowerCase();
return pattern;
}
项目:sequencetools
文件:AsciiCharacterCheck.java
private boolean isAscii(String text)
{
char j;
if(text==null)
return true;
for(int i=0; i<text.length();i++)
{
if(CharUtils.isAscii(text.charAt(i)))
continue;
else
{
j= text.charAt(i);
}
return false;
}
return true;
}
项目:atsd-jdbc
文件:UnivocityParserRowContext.java
static char lastCharForColumn(int column, int[] splitIndexes, String line) {
boolean pairedQuote = true;
int currentColumn = splitIndexes.length - 1;
final int lastLineIndex = line.length() - 1;
char currentChar;
for (int i = lastLineIndex; i >= 0; --i) {
currentChar = line.charAt(i);
if (currentChar == '"') {
pairedQuote = !pairedQuote;
} else if (currentChar == ',' && pairedQuote) {
splitIndexes[currentColumn] = i;
--currentColumn;
continue;
}
if (currentColumn == column && pairedQuote && !CharUtils.isAsciiControl(currentChar)) {
return currentChar;
}
}
return '\0';
}
项目:cloud-meter
文件:CsvSampleWriter.java
@Override
public long write(Sample sample) {
Validate.validState(writer != null, "No writer set! Call setWriter() first!");
StringBuilder row = new StringBuilder();
char[] specials = new char[] { separator,
CSVSaveService.QUOTING_CHAR, CharUtils.CR, CharUtils.LF };
for (int i = 0; i < columnCount; i++) {
String data = sample.getData(i);
row.append(CSVSaveService.quoteDelimiters(data, specials))
.append(separator);
}
row.setLength(row.length() - 1);
writer.println(row.toString());
sampleCount++;
return sampleCount;
}
项目: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());
}
}
项目:crigtt
文件:CrigttFileUtils.java
public static String buildSafeFileName(String fileName) {
char[] fileNameChars = FilenameUtils.getName(fileName).toCharArray();
StrBuilder fileNameBuilder = new StrBuilder(fileNameChars.length);
char fileNameChar;
for (int a = 0; a < fileNameChars.length; a++) {
if (!CharUtils.isAscii((fileNameChar = fileNameChars[a]))) {
continue;
}
if (Character.isWhitespace(fileNameChar)) {
while (((a + 1) < fileNameChars.length) && Character.isWhitespace(fileNameChars[(a + 1)])) {
a++;
}
if (!fileNameBuilder.isEmpty() && ((a + 2) < fileNameChars.length)) {
fileNameBuilder.append(StringUtils.SPACE);
}
} else if (Character.isLetterOrDigit(fileNameChar) || (fileNameChar == CrigttStringUtils.HYPHEN_CHAR)
|| (fileNameChar == CrigttStringUtils.PERIOD_CHAR) || (fileNameChar == CrigttStringUtils.UNDERSCORE_CHAR)) {
fileNameBuilder.append(fileNameChar);
}
}
return fileNameBuilder.build();
}
项目:mathosphere
文件:UnicodeMap.java
public static String char2TeX(int codePoint) {
if ( MAP == null){
buildMap();
}
if (CharUtils.isAsciiPrintable((char) codePoint)) {
return CharUtils.toString((char) codePoint);
}
final String tex = MAP.get(codePoint);
if (tex != null) {
if (tex.endsWith("}") || tex.length() == 1) {
return tex;
}
return "{" + tex + "}";
}
LOGGER.debug("invalid char", codePoint);
return "";
}
项目:gwt-commons-lang3
文件:StrBuilder.java
/**
* Updates the length of the builder by either dropping the last characters
* or adding filler of Unicode zero.
*
* @param length the length to set to, must be zero or positive
* @return this, to enable chaining
* @throws IndexOutOfBoundsException if the length is negative
*/
public StrBuilder setLength(final int length) {
if (length < 0) {
throw new StringIndexOutOfBoundsException(length);
}
if (length < size) {
size = length;
} else if (length > size) {
ensureCapacity(length);
final int oldEnd = size;
final int newEnd = length;
size = length;
for (int i = oldEnd; i < newEnd; i++) {
buffer[i] = CharUtils.NUL;
}
}
return this;
}
项目:ScreenSlicer
文件:HtmlCoder.java
public static String encode(String string) {
try {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < string.length();) {
int codePoint = string.codePointAt(i);
String symbol = codePointToSymbol(codePoint);
char[] chars = symbol.toCharArray();
if (chars.length == 1 && CharUtils.isAscii(chars[0])) {
builder.append(StringEscapeUtils.escapeHtml4(Character.toString(chars[0])));
} else {
builder.append(symbol);
}
i += chars.length;
}
return builder.toString();
} catch (Throwable t) {
Log.exception(t);
return string;
}
}
项目: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;
}
项目: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;
}
}
}
项目:quorrabot
文件:IrcMessageEvent.java
public int getCapsCount() {
int count = 0;
for (int i = 0, l = message.length(); i < l; ++i) {
if (CharUtils.isAsciiAlphaUpper(message.charAt(i))) {
++count;
}
}
return count;
}
项目: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();
}
项目:springmock
文件:DoubleNameResolver.java
private String generateNameFromClass(Class<?> doubleClass) {
final String className = doubleClass.getSimpleName();
final String classFirstLetter = CharUtils.toString(className.charAt(0));
final String restOfClassName =StringUtils.substring(doubleClass.getSimpleName(), 1);
return classFirstLetter.toLowerCase() + restOfClassName;
}
项目: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();
}
项目: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;
}
项目:Arcade2
文件:WorldNameGenerator.java
public String normalizeWorldName(String worldName) {
char[] array = StringUtils.stripAccents(worldName).toCharArray();
char[] result = new char[array.length];
for (int i = 0; i < array.length; i++) {
char c = array[i];
if (CharUtils.isAsciiAlphanumeric(c)) {
result[i] = Character.toLowerCase(c);
} else {
result[i] = SLUG_MAGIC_KEY;
}
}
return String.valueOf(result);
}
项目:atsd-jdbc
文件:UnivocityParserRowContext.java
private static int findLineFeedIndex(String line) {
for (int i = line.length() - 1; i >= 0; --i) {
if (!CharUtils.isAsciiControl(line.charAt(i))) {
return i + 1;
}
}
throw new IllegalArgumentException("line <<" + line + ">> is empty or contains only control characters");
}
项目: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(Charsets.UTF_8), Charsets.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();
}
项目:PhantomBot
文件:IrcMessageEvent.java
public int getCapsCount()
{
int count = 0;
for (int i = 0, l = message.length(); i < l; ++i)
{
if (CharUtils.isAsciiAlphaUpper(message.charAt(i)))
{
++count;
}
}
return count;
}
项目:openmeetings
文件:OmKeyEvent.java
public OmKeyEvent(Map<String, Object> obj) {
alt = TRUE.equals(obj.get("alt"));
ctrl = TRUE.equals(obj.get("ctrl"));
shift = TRUE.equals(obj.get("shift")) || isUpperCase(ch);
ch = (char)getInt(obj, "char");
key = inKey = getInt(obj, "key");
Integer _key = null;
if (CharUtils.isAsciiPrintable(ch)) {
boolean alpha = Character.isAlphabetic(ch);
if (alpha) { // can't be combined due to different types
key = getKeyStroke(toUpperCase(ch), 0).getKeyCode();
} else {
key = getKeyStroke(Character.valueOf(ch), 0).getKeyCode();
}
if (key == 0) {
_key = CHAR_MAP.get(ch);
if (_key == null) {
// fallback
key = inKey;
}
}
if (!alpha && _key == null) {
_key = KEY_MAP.get(key);
}
} else {
_key = KEY_MAP.get(key);
}
this.key = _key == null ? key : _key;
log.debug("sequence:: shift {}, ch {}, orig {} -> key {}({}), map {}", shift, ch == 0 ? ' ' : ch, inKey, key, Integer.toHexString(key), _key);
}
项目:OpenEstate-IO
文件:RandomStringUtilsTest.java
private static boolean isAsciiAlpha( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiAlpha( c ))
return false;
}
return true;
}
项目:OpenEstate-IO
文件:RandomStringUtilsTest.java
private static boolean isAsciiAlphanumeric( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiAlphanumeric( c ))
return false;
}
return true;
}
项目:OpenEstate-IO
文件:RandomStringUtilsTest.java
private static boolean isAsciiNumeric( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiNumeric( c ))
return false;
}
return true;
}
项目:appformer
文件:ValidationUtils.java
public static boolean isJavaIdentifier(final String value) {
if (StringUtils.isBlank(value)) {
return false;
}
if (!SourceVersion.isIdentifier(value) || SourceVersion.isKeyword(value)) {
return false;
}
for (int i = 0; i < value.length(); i++) {
if (!CharUtils.isAsciiPrintable(value.charAt(i))) {
return false;
}
}
return true;
}
项目:mathosphere
文件:MathMLUtils.java
private static List<String> listOfStrings(char from, int amount) {
List<String> result = Lists.newArrayListWithCapacity(amount);
for (char c = from; c < from + amount; c++) {
result.add(CharUtils.toString(c));
}
return result;
}
项目:mathosphere
文件:UnicodeUtils.java
private static String codePointToString(int codePoint) {
if (Character.isBmpCodePoint(codePoint)) {
return CharUtils.toString((char) codePoint);
}
char[] chars = Character.toChars(codePoint);
return new String(chars);
}
项目:japt-proxy
文件:RpmPackageVersionComparator.java
/**
* Returns the order for a single character. The order is digits,
* then alpha, then non-ascii. If {@code pos} >=
* {@code ca.length}, then the order is the same as for digits.
*
* @param ca the character array
* @param pos the position in the character array
* @return the order for the given character
*/
@Override
protected int order(final char[] ca, final int pos) {
if (pos >= ca.length) {
return 0;
}
final char c = ca[pos];
return CharUtils.isAsciiNumeric(c) ? 0 : CharUtils.isAsciiAlpha(c) ? c : c + NON_ASCII_OFFSET;
}
项目:japt-proxy
文件:DebianPackageVersionComparator.java
/**
* Returns the order for a single character. The order is ~, then digits,
* then alpha, then non-ascii. If {@code pos} >=
* {@code ca.length}, then the order is the same as for digits.
*
* @param ca the character array
* @param pos the position in the character array
* @return the order for the given character
*/
@Override
protected int order(final char[] ca, final int pos) {
if (pos >= ca.length) {
return 0;
}
final char c = ca[pos];
return c == '~' ? -1 : CharUtils.isAsciiNumeric(c) ? 0 : CharUtils.isAsciiAlpha(c) ? c : c + NON_ASCII_OFFSET;
}
项目:OpenEstate-IS24-REST
文件:RandomStringUtilsTest.java
private static boolean isAsciiAlpha( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiAlpha( c ))
return false;
}
return true;
}
项目:OpenEstate-IS24-REST
文件:RandomStringUtilsTest.java
private static boolean isAsciiAlphanumeric( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiAlphanumeric( c ))
return false;
}
return true;
}
项目:OpenEstate-IS24-REST
文件:RandomStringUtilsTest.java
private static boolean isAsciiNumeric( String value )
{
for (char c : value.toCharArray())
{
if (!CharUtils.isAsciiNumeric( c ))
return false;
}
return true;
}
项目: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();
}
项目:gwt-commons-lang3
文件:WordUtils.java
/**
* <p>Swaps the case of a String using a word based algorithm.</p>
*
* <ul>
* <li>Upper case character converts to Lower case</li>
* <li>Title case character converts to Lower case</li>
* <li>Lower case character after Whitespace or at start converts to Title case</li>
* <li>Other Lower case character converts to Upper case</li>
* </ul>
*
* <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
* A <code>null</code> input String returns <code>null</code>.</p>
*
* <pre>
* StringUtils.swapCase(null) = null
* StringUtils.swapCase("") = ""
* StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
* </pre>
*
* @param str the String to swap case, may be null
* @return the changed String, <code>null</code> if null String input
*/
@GwtIncompatible("incompatible method")
public static String swapCase(final String str) {
if (StringUtils.isEmpty(str)) {
return str;
}
final char[] buffer = str.toCharArray();
boolean whitespace = true;
for (int i = 0; i < buffer.length; i++) {
final char ch = buffer[i];
if (Character.isUpperCase(ch)) {
buffer[i] = Character.toLowerCase(ch);
whitespace = false;
} else if (Character.isTitleCase(ch)) {
buffer[i] = Character.toLowerCase(ch);
whitespace = false;
} else if (Character.isLowerCase(ch)) {
if (whitespace) {
buffer[i] = Character.toTitleCase(ch);
whitespace = false;
} else {
buffer[i] = Character.toUpperCase(ch);
}
} else {
whitespace = CharUtils.isWhitespace(ch);
}
}
return new String(buffer);
}
项目:gwt-commons-lang3
文件:WordUtils.java
/**
* Is the character a delimiter.
*
* @param ch the character to check
* @param delimiters the delimiters
* @return true if it is a delimiter
*/
private static boolean isDelimiter(final char ch, final char[] delimiters) {
if (delimiters == null) {
return CharUtils.isWhitespace(ch);
}
for (final char delimiter : delimiters) {
if (ch == delimiter) {
return true;
}
}
return false;
}
项目:commons-text
文件:CsvTranslatorsTest.java
@Test
public void csvEscaperCRTest() throws IOException {
final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
final Writer writer = new StringWriter();
final String input = "hi,this,is,a,CR,test" + String.valueOf(CharUtils.CR);
escaper.translateWhole(input, writer);
final String data = writer.toString();
assertThat(data).isEqualTo("\"hi,this,is,a,CR,test" + String.valueOf(CharUtils.CR) + "\"");
}
项目:commons-text
文件:CsvTranslatorsTest.java
@Test
public void csvEscaperLFTest() throws IOException {
final CsvTranslators.CsvEscaper escaper = new CsvTranslators.CsvEscaper();
final Writer writer = new StringWriter();
final String input = "hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF);
escaper.translateWhole(input, writer);
final String data = writer.toString();
assertThat(data).isEqualTo("\"hi,this,is,a,LF,test" + String.valueOf(CharUtils.LF) + "\"");
}
项目: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);
}
}