Skip to content

Commit

Permalink
#340 String -> StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Jul 19, 2024
1 parent 30944c8 commit 8535cb0
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,31 @@ public String evaluate() {
}

public static String createCounterText(IdentValue listStyle, int listCounter) {
String text;
if (listStyle == IdentValue.LOWER_LATIN || listStyle == IdentValue.LOWER_ALPHA) {
text = toLatin(listCounter).toLowerCase();
return toLatin(listCounter).toLowerCase();
} else if (listStyle == IdentValue.UPPER_LATIN || listStyle == IdentValue.UPPER_ALPHA) {
text = toLatin(listCounter).toUpperCase();
return toLatin(listCounter).toUpperCase();
} else if (listStyle == IdentValue.LOWER_ROMAN) {
text = toRoman(listCounter).toLowerCase();
return toRoman(listCounter).toLowerCase();
} else if (listStyle == IdentValue.UPPER_ROMAN) {
text = toRoman(listCounter).toUpperCase();
return toRoman(listCounter).toUpperCase();
} else if (listStyle == IdentValue.DECIMAL_LEADING_ZERO) {
text = (listCounter >= 10 ? "" : "0") + listCounter;
return (listCounter >= 10 ? "" : "0") + listCounter;
} else { // listStyle == IdentValue.DECIMAL or anything else
text = Integer.toString(listCounter);
return Integer.toString(listCounter);
}
return text;
}


private static String toLatin(int val) {
String result = "";
val -= 1;
private static String toLatin(int index) {
StringBuilder result = new StringBuilder(5);
int val = index - 1;
while (val >= 0) {
int letter = val % 26;
val = val / 26 - 1;
result = ((char) (letter + 65)) + result;
result.insert(0, (char) (letter + 65));
}
return result;
return result.toString();
}

private static String toRoman(int val) {
Expand Down

0 comments on commit 8535cb0

Please sign in to comment.