Tweak performance of RelaxedNames.separatedToCamelCase

Closes gh-6661
pull/6728/head
Andy Wilkinson 8 years ago
parent 53374ec51d
commit a16aa767dc

@ -200,23 +200,29 @@ public final class RelaxedNames implements Iterable<String> {
};
private static final char[] SUFFIXES = new char[] { '_', '-', '.' };
public abstract String apply(String value);
private static String separatedToCamelCase(String value,
boolean caseInsensitive) {
if (value.length() == 0) {
return value;
}
StringBuilder builder = new StringBuilder();
for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) {
field = (caseInsensitive ? field.toLowerCase() : field);
builder.append(
builder.length() == 0 ? field : StringUtils.capitalize(field));
}
for (String suffix : new String[] { "_", "-", "." }) {
if (value.endsWith(suffix)) {
char lastChar = value.charAt(value.length() - 1);
for (char suffix : SUFFIXES) {
if (lastChar == suffix) {
builder.append(suffix);
break;
}
}
return builder.toString();
}
}

Loading…
Cancel
Save