@@ -22,21 +22,22 @@ private val logger = KotlinLogging.logger {}
22
22
* support different locales and fallback symbols.
23
23
*
24
24
* Public, so it can be used in other modules.
25
- * Open, so it may be modified.
26
25
*
27
26
* @param parserOptions can be supplied to configure the parser.
28
27
* We'll only use [ParserOptions.locale] and [ParserOptions.useFastDoubleParser].
29
28
*/
30
29
@Suppress(" ktlint:standard:comment-wrapping" )
31
- public open class DoubleParser (private val parserOptions : ParserOptions ) {
30
+ public class FastDoubleParser (private val parserOptions : ParserOptions ) {
32
31
33
- protected val locale: Locale = parserOptions.locale ? : Locale .getDefault()
34
- protected val supportedFastCharsets: Set <Charset > = setOf (Charsets .UTF_8 , Charsets .ISO_8859_1 , Charsets .US_ASCII )
32
+ private val supportedFastCharsets = setOf (Charsets .UTF_8 , Charsets .ISO_8859_1 , Charsets .US_ASCII )
35
33
36
- protected val localDecimalFormatSymbols : DecimalFormatSymbols = DecimalFormatSymbols .getInstance( locale)
37
- protected val fallbackDecimalFormatSymbols : DecimalFormatSymbols = DecimalFormatSymbols .getInstance( Locale .ROOT )
34
+ private val locale : Locale = parserOptions. locale ? : Locale .getDefault( )
35
+ private val fallbackLocale : Locale = Locale .ROOT
38
36
39
- protected open val parser: ConfigurableDoubleParser =
37
+ private val localDecimalFormatSymbols: DecimalFormatSymbols = DecimalFormatSymbols .getInstance(locale)
38
+ private val fallbackDecimalFormatSymbols: DecimalFormatSymbols = DecimalFormatSymbols .getInstance(fallbackLocale)
39
+
40
+ private val parser: ConfigurableDoubleParser =
40
41
ConfigurableDoubleParser (
41
42
/* symbols = */ setupNumberFormatSymbols(),
42
43
/* ignoreCase = */ true ,
@@ -48,20 +49,20 @@ public open class DoubleParser(private val parserOptions: ParserOptions) {
48
49
*
49
50
* Fallback characters/strings are only added if they're not clashing with local characters/strings.
50
51
*/
51
- protected fun setupNumberFormatSymbols (): NumberFormatSymbols {
52
+ private fun setupNumberFormatSymbols (): NumberFormatSymbols {
52
53
// collect all chars and strings that are locale-specific such that we can check whether
53
54
// fallback chars and strings are safe to add
54
- val localChars = buildSet {
55
- with (localDecimalFormatSymbols) {
55
+ val localChars = with (localDecimalFormatSymbols) {
56
+ buildSet {
56
57
add(decimalSeparator.lowercaseChar())
57
58
add(groupingSeparator.lowercaseChar())
58
59
add(minusSign.lowercaseChar())
59
60
add(' +' )
60
61
add(zeroDigit.lowercaseChar())
61
62
}
62
63
}
63
- val localStrings = buildSet {
64
- with (localDecimalFormatSymbols) {
64
+ val localStrings = with (localDecimalFormatSymbols) {
65
+ buildSet {
65
66
add(exponentSeparator.lowercase())
66
67
add(infinity.lowercase())
67
68
add(naN.lowercase())
@@ -137,7 +138,7 @@ public open class DoubleParser(private val parserOptions: ParserOptions) {
137
138
}
138
139
139
140
/* * Fallback method for parsing doubles. */
140
- protected open fun String.parseToDoubleOrNullFallback (): Double? =
141
+ private fun String.parseToDoubleOrNullFallback (): Double? =
141
142
when (lowercase()) {
142
143
" inf" , " +inf" , " infinity" , " +infinity" , " infty" , " +infty" , " ∞" , " +∞" -> Double .POSITIVE_INFINITY
143
144
@@ -168,7 +169,7 @@ public open class DoubleParser(private val parserOptions: ParserOptions) {
168
169
* It uses the [fast double parser][ConfigurableDoubleParser] if [ParserOptions.useFastDoubleParser] is enabled,
169
170
* else, or if that fails, it uses [parseToDoubleOrNullFallback].
170
171
*/
171
- public open fun parseOrNull (
172
+ public fun parseOrNull (
172
173
ba : ByteArray ,
173
174
offset : Int = 0,
174
175
length : Int = ba.size,
@@ -195,7 +196,7 @@ public open class DoubleParser(private val parserOptions: ParserOptions) {
195
196
* It uses the [fast double parser][ConfigurableDoubleParser] if [ParserOptions.useFastDoubleParser] is enabled,
196
197
* else, or if that fails, it uses [parseToDoubleOrNullFallback].
197
198
*/
198
- public open fun parseOrNull (cs : CharSequence ): Double? {
199
+ public fun parseOrNull (cs : CharSequence ): Double? {
199
200
if (parserOptions.useFastDoubleParser) {
200
201
try {
201
202
return parser.parseDouble(cs)
@@ -215,7 +216,7 @@ public open class DoubleParser(private val parserOptions: ParserOptions) {
215
216
* It uses the [fast double parser][ConfigurableDoubleParser] if [ParserOptions.useFastDoubleParser] is enabled,
216
217
* else, or if that fails, it uses [parseToDoubleOrNullFallback].
217
218
*/
218
- public open fun parseOrNull (ca : CharArray , offset : Int = 0, length : Int = ca.size): Double? {
219
+ public fun parseOrNull (ca : CharArray , offset : Int = 0, length : Int = ca.size): Double? {
219
220
if (parserOptions.useFastDoubleParser) {
220
221
try {
221
222
return parser.parseDouble(ca, offset, length)
0 commit comments