1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import java.text.DecimalFormatSymbols;
|
---|
5 | import java.text.spi.DecimalFormatSymbolsProvider;
|
---|
6 | import java.util.Locale;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * JOSM implementation of the {@link java.text.DecimalFormatSymbols DecimalFormatSymbols} class,
|
---|
10 | * consistent with ISO 80000-1.
|
---|
11 | * This class will only be used with Java 9 and later runtimes, as Java 8 implementation relies
|
---|
12 | * on Java Extension Mechanism only, while Java 9 supports application classpath.
|
---|
13 | * See {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider} javadoc for more details.
|
---|
14 | * @since 12931
|
---|
15 | */
|
---|
16 | public class JosmDecimalFormatSymbolsProvider extends DecimalFormatSymbolsProvider {
|
---|
17 |
|
---|
18 | @Override
|
---|
19 | public DecimalFormatSymbols getInstance(Locale locale) {
|
---|
20 | DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
|
---|
21 | // Override digit group separator to be consistent across languages with ISO 80000-1, chapter 7.3.1
|
---|
22 | symbols.setGroupingSeparator('\u202F'); // U+202F: NARROW NO-BREAK SPACE
|
---|
23 | return symbols;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public Locale[] getAvailableLocales() {
|
---|
28 | return I18n.getAvailableTranslations();
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Returns a new {@code double} initialized to the value represented by the specified {@code String},
|
---|
33 | * allowing both dot and comma decimal separators.
|
---|
34 | *
|
---|
35 | * @param s the string to be parsed.
|
---|
36 | * @return the {@code double} value represented by the string argument.
|
---|
37 | * @throws NullPointerException if the string is null
|
---|
38 | * @throws NumberFormatException if the string does not contain a parsable {@code double}.
|
---|
39 | * @see Double#parseDouble(String)
|
---|
40 | * @since 13050
|
---|
41 | */
|
---|
42 | public static double parseDouble(String s) {
|
---|
43 | return Double.parseDouble(s.replace(',', '.'));
|
---|
44 | }
|
---|
45 | }
|
---|