mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
better usage of StringBuilder in casing
This commit is contained in:
parent
daac94092c
commit
3a59397306
@ -1166,12 +1166,20 @@ public class Strings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String toCamelCase(String value) {
|
public static String toCamelCase(String value) {
|
||||||
StringBuilder sb = new StringBuilder();
|
return toCamelCase(value, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toCamelCase(String value, StringBuilder sb) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
char c = value.charAt(i);
|
char c = value.charAt(i);
|
||||||
if (c == '_') {
|
if (c == '_') {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
|
if (sb != null) {
|
||||||
|
sb.setLength(0);
|
||||||
|
} else {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
}
|
||||||
// copy it over here
|
// copy it over here
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
sb.append(value.charAt(j));
|
sb.append(value.charAt(j));
|
||||||
@ -1192,12 +1200,20 @@ public class Strings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String toUnderscoreCase(String value) {
|
public static String toUnderscoreCase(String value) {
|
||||||
StringBuilder sb = new StringBuilder();
|
return toUnderscoreCase(value, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toUnderscoreCase(String value, StringBuilder sb) {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
char c = value.charAt(i);
|
char c = value.charAt(i);
|
||||||
if (Character.isUpperCase(c)) {
|
if (Character.isUpperCase(c)) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
|
if (sb != null) {
|
||||||
|
sb.setLength(0);
|
||||||
|
} else {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
}
|
||||||
// copy it over here
|
// copy it over here
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
sb.append(value.charAt(j));
|
sb.append(value.charAt(j));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user