@@ -81,7 +81,10 @@ struct parsed_number_string {
81
81
// Assuming that you use no more than 19 digits, this will
82
82
// parse an ASCII string.
83
83
fastfloat_really_inline
84
- parsed_number_string parse_number_string (const char *p, const char *pend, chars_format fmt) noexcept {
84
+ parsed_number_string parse_number_string (const char *p, const char *pend, parse_options options) noexcept {
85
+ const chars_format fmt = options.format ;
86
+ const char decimal_point = options.decimal_point ;
87
+
85
88
parsed_number_string answer;
86
89
answer.valid = false ;
87
90
answer.too_many_digits = false ;
@@ -91,7 +94,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
91
94
if (p == pend) {
92
95
return answer;
93
96
}
94
- if (!is_integer (*p) && (*p != ' . ' )) { // a sign must be followed by an integer or the dot
97
+ if (!is_integer (*p) && (*p != decimal_point )) { // a sign must be followed by an integer or the dot
95
98
return answer;
96
99
}
97
100
}
@@ -109,7 +112,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
109
112
const char *const end_of_integer_part = p;
110
113
int64_t digit_count = int64_t (end_of_integer_part - start_digits);
111
114
int64_t exponent = 0 ;
112
- if ((p != pend) && (*p == ' . ' )) {
115
+ if ((p != pend) && (*p == decimal_point )) {
113
116
++p;
114
117
// Fast approach only tested under little endian systems
115
118
if ((p + 8 <= pend) && is_made_of_eight_digits_fast (p)) {
@@ -179,7 +182,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
179
182
// We need to be mindful of the case where we only have zeroes...
180
183
// E.g., 0.000000000...000.
181
184
const char *start = start_digits;
182
- while ((start != pend) && (*start == ' 0' || *start == ' . ' )) {
185
+ while ((start != pend) && (*start == ' 0' || *start == decimal_point )) {
183
186
if (*start == ' 0' ) { digit_count --; }
184
187
start++;
185
188
}
@@ -196,7 +199,7 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
196
199
if (i >= minimal_nineteen_digit_integer) { // We have a big integers
197
200
exponent = end_of_integer_part - p + exp_number;
198
201
} else { // We have a value with a fractional component.
199
- p++; // skip the '.'
202
+ p++; // skip the dot
200
203
const char *first_after_period = p;
201
204
while ((i < minimal_nineteen_digit_integer) && (p != pend) && is_integer (*p)) {
202
205
i = i * 10 + uint64_t (*p - ' 0' );
@@ -217,7 +220,9 @@ parsed_number_string parse_number_string(const char *p, const char *pend, chars_
217
220
// This function could be optimized. In particular, we could stop after 19 digits
218
221
// and try to bail out. Furthermore, we should be able to recover the computed
219
222
// exponent from the pass in parse_number_string.
220
- fastfloat_really_inline decimal parse_decimal (const char *p, const char *pend) noexcept {
223
+ fastfloat_really_inline decimal parse_decimal (const char *p, const char *pend, parse_options options) noexcept {
224
+ const char decimal_point = options.decimal_point ;
225
+
221
226
decimal answer;
222
227
answer.num_digits = 0 ;
223
228
answer.decimal_point = 0 ;
@@ -237,7 +242,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
237
242
answer.num_digits ++;
238
243
++p;
239
244
}
240
- if ((p != pend) && (*p == ' . ' )) {
245
+ if ((p != pend) && (*p == decimal_point )) {
241
246
++p;
242
247
const char *first_after_period = p;
243
248
// if we have not yet encountered a zero, we have to skip it as well
@@ -276,7 +281,7 @@ fastfloat_really_inline decimal parse_decimal(const char *p, const char *pend) n
276
281
// we have at least one non-zero digit.
277
282
const char *preverse = p - 1 ;
278
283
int32_t trailing_zeros = 0 ;
279
- while ((*preverse == ' 0' ) || (*preverse == ' . ' )) {
284
+ while ((*preverse == ' 0' ) || (*preverse == decimal_point )) {
280
285
if (*preverse == ' 0' ) { trailing_zeros++; };
281
286
--preverse;
282
287
}
0 commit comments