Skip to content

Commit

Permalink
text-minimessage: Changed syntax of Decimal Formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Joo200 committed Mar 4, 2022
1 parent 75d7cd1 commit 9d3966f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.function.Consumer;
Expand Down Expand Up @@ -216,5 +217,21 @@ default boolean isFalse() {
return OptionalDouble.empty();
}
}

/**
* Try to return this argument as a {@code char}.
*
* <p>The optional will only be present if the value is a valid char.</p>
*
* @return an optional providing the value of this argument as an integer
* @since 4.10.0
*/
default @NotNull Optional<Character> asChar() {
if (this.value().length() == 1) {
return Optional.of(this.value().charAt(0));
} else {
return Optional.empty();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ public static TagResolver formatNumber(final @NotNull String key, final Number n
final DecimalFormat decimalFormat = new DecimalFormat(format);
final DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(Locale.ROOT);
if (argumentQueue.hasNext()) {
final String symbols = argumentQueue.pop().value();
if (symbols.length() >= 1) {
formatSymbols.setDecimalSeparator(symbols.charAt(0));
}
if (symbols.length() >= 2) {
formatSymbols.setGroupingSeparator(symbols.charAt(1));
argumentQueue.pop().asChar().ifPresent(formatSymbols::setDecimalSeparator);
if (argumentQueue.hasNext()) {
argumentQueue.pop().asChar().ifPresent(formatSymbols::setGroupingSeparator);
}
}
decimalFormat.setDecimalFormatSymbols(formatSymbols);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testNumberFormatter() {

@Test
void testNumberFormatterWithDecimal() {
final String input = "<double:'#,##0.00':',.'> is a nice number";
final String input = "<double:'#,##0.00':,:.> is a nice number";
final Component expected = text("2.000,00 is a nice number");

this.assertParsedEquals(
Expand Down

0 comments on commit 9d3966f

Please sign in to comment.