|
|
|
@ -19,6 +19,8 @@ package org.springframework.boot.bind;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
@ -32,6 +34,8 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
*/
|
|
|
|
|
public final class RelaxedNames implements Iterable<String> {
|
|
|
|
|
|
|
|
|
|
private static final Pattern CAMEL_CASE_PATTERN = Pattern.compile("([^A-Z-])([A-Z])");
|
|
|
|
|
|
|
|
|
|
private final String name;
|
|
|
|
|
|
|
|
|
|
private final Set<String> values = new LinkedHashSet<String>();
|
|
|
|
@ -126,17 +130,28 @@ public final class RelaxedNames implements Iterable<String> {
|
|
|
|
|
CAMELCASE_TO_UNDERSCORE {
|
|
|
|
|
@Override
|
|
|
|
|
public String apply(String value) {
|
|
|
|
|
value = value.replaceAll("([^A-Z-])([A-Z])", "$1_$2");
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
for (String field : value.split("_")) {
|
|
|
|
|
if (builder.length() == 0) {
|
|
|
|
|
builder.append(field);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
builder.append("_").append(StringUtils.uncapitalize(field));
|
|
|
|
|
}
|
|
|
|
|
Matcher matcher = CAMEL_CASE_PATTERN.matcher(value);
|
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
|
matcher.appendReplacement(result, matcher.group(1) + '_'
|
|
|
|
|
+ StringUtils.uncapitalize(matcher.group(2)));
|
|
|
|
|
}
|
|
|
|
|
return builder.toString();
|
|
|
|
|
matcher.appendTail(result);
|
|
|
|
|
return result.toString();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
CAMELCASE_TO_HYPHEN {
|
|
|
|
|
@Override
|
|
|
|
|
public String apply(String value) {
|
|
|
|
|
Matcher matcher = CAMEL_CASE_PATTERN.matcher(value);
|
|
|
|
|
StringBuffer result = new StringBuffer();
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
|
matcher.appendReplacement(result, matcher.group(1) + '-'
|
|
|
|
|
+ StringUtils.uncapitalize(matcher.group(2)));
|
|
|
|
|
}
|
|
|
|
|
matcher.appendTail(result);
|
|
|
|
|
return result.toString();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|