Merge pull request #15779 from Christoph Dreiss
* gh-15779: Polish "Optimize BeanPropertyName.toDashedForm()" Optimize BeanPropertyName.toDashedForm() Closes gh-15779
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,12 +44,12 @@ abstract class BeanPropertyName {
|
||||
*/
|
||||
public static String toDashedForm(String name, int start) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
char[] chars = name.replace("_", "-").toCharArray();
|
||||
for (int i = start; i < chars.length; i++) {
|
||||
char ch = chars[i];
|
||||
String replaced = name.replace('_', '-');
|
||||
for (int i = start; i < replaced.length(); i++) {
|
||||
char ch = replaced.charAt(i);
|
||||
if (Character.isUpperCase(ch) && result.length() > 0
|
||||
&& result.charAt(result.length() - 1) != '-') {
|
||||
result.append("-");
|
||||
result.append('-');
|
||||
}
|
||||
result.append(Character.toLowerCase(ch));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user