本文整理汇总了Java中org.apache.commons.lang.CharUtils类的典型用法代码示例。如果您正苦于以下问题:Java CharUtils类的具体用法?Java CharUtils怎么用?Java CharUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharUtils类属于org.apache.commons.lang包,在下文中一共展示了CharUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: propertyToField
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
/**
* 对象属性转换为字段 例如: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();
}
示例2: escapeFileName
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
/**
* 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();
}
}
示例3: sampleAdd
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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);
}
}
}
}
}
示例4: normalize
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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();
}
示例5: generateNodeName
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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";
}
示例6: isAsciiAlphaNumeric
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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;
}
示例7: cleanUpNamedEntityValue
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
/**
* 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();
}
示例8: assertSimilarXml
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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());
}
示例9: keyToField
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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();
}
示例10: checkResourceStyle
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
@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;
}
示例11: getFixedLenth
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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;
}
示例12: testUnicodeEscapedDelimiter
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
@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));
}
}
示例13: testUnescapedDelimiter
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
@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));
}
}
示例14: isJavaIdentifier
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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;
}
示例15: toFormattedString
import org.apache.commons.lang.CharUtils; //导入依赖的package包/类
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();
}