/src/rust-lexical/lexical-parse-float/src/options.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Configuration options for parsing floats. |
2 | | //! |
3 | | //! This enables extensive control over how the float is parsed, from |
4 | | //! control characters like the decimal point and the valid non-finite |
5 | | //! float representations. |
6 | | //! |
7 | | //! # Examples |
8 | | //! |
9 | | //! For example, to parse a European-style float: |
10 | | //! |
11 | | //! ```rust |
12 | | //! use lexical_parse_float::{FromLexicalWithOptions, Options}; |
13 | | //! use lexical_parse_float::format::STANDARD; |
14 | | //! |
15 | | //! const OPTIONS: Options = Options::builder() |
16 | | //! .decimal_point(b',') |
17 | | //! .build_strict(); |
18 | | //! let value = "1,2345e300"; |
19 | | //! let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS); |
20 | | //! assert_eq!(result, Ok(1.2345e300)); |
21 | | //! ``` |
22 | | //! |
23 | | //! # Pre-Defined Formats |
24 | | //! |
25 | | //! These are the pre-defined formats for parsing numbers from various |
26 | | //! programming, markup, and data languages. |
27 | | //! |
28 | | //! - [`STANDARD`]: Standard number format. |
29 | | //! - [`DECIMAL_COMMA`]: Numerical format with a decimal comma. |
30 | | //! - [`HEX_FLOAT`]: Numerical format for hexadecimal floats, which use a `p` |
31 | | //! exponent. |
32 | | //! - [`RUST_LITERAL`]: Number format for a [`Rust`] literal floating-point |
33 | | //! number. |
34 | | //! - [`PYTHON_LITERAL`]: Number format for a [`Python`] literal floating-point |
35 | | //! number. |
36 | | //! - [`CXX_LITERAL`]: Number format for a [`C++`] literal floating-point |
37 | | //! number. |
38 | | //! - [`C_LITERAL`]: Number format for a [`C`] literal floating-point number. |
39 | | //! - [`RUBY_LITERAL`]: Number format for a [`Ruby`] literal floating-point |
40 | | //! number. |
41 | | //! - [`RUBY_STRING`]: Number format to parse a [`Ruby`] float from string. |
42 | | //! - [`SWIFT_LITERAL`]: Number format for a [`Swift`] literal floating-point |
43 | | //! number. |
44 | | //! - [`GO_LITERAL`]: Number format for a [`Golang`] literal floating-point |
45 | | //! number. |
46 | | //! - [`HASKELL_LITERAL`]: Number format for a [`Haskell`] literal |
47 | | //! floating-point number. |
48 | | //! - [`HASKELL_STRING`]: Number format to parse a [`Haskell`] float from |
49 | | //! string. |
50 | | //! - [`JAVASCRIPT_LITERAL`]: Number format for a [`Javascript`] literal |
51 | | //! floating-point number. |
52 | | //! - [`JAVASCRIPT_STRING`]: Number format to parse a [`Javascript`] float from |
53 | | //! string. |
54 | | //! - [`PERL_LITERAL`]: Number format for a [`Perl`] literal floating-point |
55 | | //! number. |
56 | | //! - [`PHP_LITERAL`]: Number format for a [`PHP`] literal floating-point |
57 | | //! number. |
58 | | //! - [`JAVA_LITERAL`]: Number format for a [`Java`] literal floating-point |
59 | | //! number. |
60 | | //! - [`JAVA_STRING`]: Number format to parse a [`Java`] float from string. |
61 | | //! - [`R_LITERAL`]: Number format for an [`R`] literal floating-point number. |
62 | | //! - [`KOTLIN_LITERAL`]: Number format for a [`Kotlin`] literal floating-point |
63 | | //! number. |
64 | | //! - [`KOTLIN_STRING`]: Number format to parse a [`Kotlin`] float from string. |
65 | | //! - [`JULIA_LITERAL`]: Number format for a [`Julia`] literal floating-point |
66 | | //! number. |
67 | | //! - [`CSHARP_LITERAL`]: Number format for a [`C#`] literal floating-point |
68 | | //! number. |
69 | | //! - [`CSHARP_STRING`]: Number format to parse a [`C#`] float from string. |
70 | | //! - [`KAWA_LITERAL`]: Number format for a [`Kawa`] literal floating-point |
71 | | //! number. |
72 | | //! - [`KAWA_STRING`]: Number format to parse a [`Kawa`] float from string. |
73 | | //! - [`GAMBITC_LITERAL`]: Number format for a [`Gambit-C`] literal |
74 | | //! floating-point number. |
75 | | //! - [`GAMBITC_STRING`]: Number format to parse a [`Gambit-C`] float from |
76 | | //! string. |
77 | | //! - [`GUILE_LITERAL`]: Number format for a [`Guile`] literal floating-point |
78 | | //! number. |
79 | | //! - [`GUILE_STRING`]: Number format to parse a [`Guile`] float from string. |
80 | | //! - [`CLOJURE_LITERAL`]: Number format for a [`Clojure`] literal |
81 | | //! floating-point number. |
82 | | //! - [`CLOJURE_STRING`]: Number format to parse a [`Clojure`] float from |
83 | | //! string. |
84 | | //! - [`ERLANG_LITERAL`]: Number format for an [`Erlang`] literal floating-point |
85 | | //! number. |
86 | | //! - [`ERLANG_STRING`]: Number format to parse an [`Erlang`] float from string. |
87 | | //! - [`ELM_LITERAL`]: Number format for an [`Elm`] literal floating-point |
88 | | //! number. |
89 | | //! - [`ELM_STRING`]: Number format to parse an [`Elm`] float from string. |
90 | | //! - [`SCALA_LITERAL`]: Number format for a [`Scala`] literal floating-point |
91 | | //! number. |
92 | | //! - [`SCALA_STRING`]: Number format to parse a [`Scala`] float from string. |
93 | | //! - [`ELIXIR_LITERAL`]: Number format for an [`Elixir`] literal floating-point |
94 | | //! number. |
95 | | //! - [`ELIXIR_STRING`]: Number format to parse an [`Elixir`] float from string. |
96 | | //! - [`FORTRAN_LITERAL`]: Number format for a [`FORTRAN`] literal |
97 | | //! floating-point number. |
98 | | //! - [`D_LITERAL`]: Number format for a [`D`] literal floating-point number. |
99 | | //! - [`COFFEESCRIPT_LITERAL`]: Number format for a [`Coffeescript`] literal |
100 | | //! floating-point number. |
101 | | //! - [`COFFEESCRIPT_STRING`]: Number format to parse a [`Coffeescript`] float |
102 | | //! from string. |
103 | | //! - [`COBOL_LITERAL`]: Number format for a [`COBOL`] literal floating-point |
104 | | //! number. |
105 | | //! - [`COBOL_STRING`]: Number format to parse a [`COBOL`] float from string. |
106 | | //! - [`FSHARP_LITERAL`]: Number format for an [`F#`] literal floating-point |
107 | | //! number. |
108 | | //! - [`VB_LITERAL`]: Number format for a [`Visual Basic`] literal |
109 | | //! floating-point number. |
110 | | //! - [`VB_STRING`]: Number format to parse a [`Visual Basic`] float from |
111 | | //! string. |
112 | | //! - [`OCAML_LITERAL`]: Number format for an [`OCaml`] literal floating-point |
113 | | //! number. |
114 | | //! - [`OBJECTIVEC_LITERAL`]: Number format for an [`Objective-C`] literal |
115 | | //! floating-point number. |
116 | | //! - [`OBJECTIVEC_STRING`]: Number format to parse an [`Objective-C`] float |
117 | | //! from string. |
118 | | //! - [`REASONML_LITERAL`]: Number format for an [`ReasonML`] literal |
119 | | //! floating-point number. |
120 | | //! - [`MATLAB_LITERAL`]: Number format for a [`MATLAB`] literal floating-point |
121 | | //! number. |
122 | | //! - [`ZIG_LITERAL`]: Number format for a [`Zig`] literal floating-point |
123 | | //! number. |
124 | | //! - [`SAGE_LITERAL`]: Number format for a [`Sage`] literal floating-point |
125 | | //! number. |
126 | | //! - [`JSON`]: Number format for a [`JSON`][`JSON-REF`] literal floating-point |
127 | | //! number. |
128 | | //! - [`TOML`]: Number format for a [`TOML`][`TOML-REF`] literal floating-point |
129 | | //! number. |
130 | | //! - [`YAML`]: Number format for a [`YAML`][`YAML-REF`] literal floating-point |
131 | | //! number. |
132 | | //! - [`XML`]: Number format for an [`XML`][`XML-REF`] literal floating-point |
133 | | //! number. |
134 | | //! - [`SQLITE`]: Number format for a [`SQLite`] literal floating-point number. |
135 | | //! - [`POSTGRESQL`]: Number format for a [`PostgreSQL`] literal floating-point |
136 | | //! number. |
137 | | //! - [`MYSQL`]: Number format for a [`MySQL`] literal floating-point number. |
138 | | //! - [`MONGODB`]: Number format for a [`MongoDB`] literal floating-point |
139 | | //! number. |
140 | | //! |
141 | | //! <!-- References --> |
142 | | //! |
143 | | //! [`Rust`]: https://www.rust-lang.org/ |
144 | | //! [`Python`]: https://www.python.org/ |
145 | | //! [`C++`]: https://en.cppreference.com/w/ |
146 | | //! [`C`]: https://en.cppreference.com/w/c |
147 | | //! [`Ruby`]: https://www.ruby-lang.org/en/ |
148 | | //! [`Swift`]: https://developer.apple.com/swift/ |
149 | | //! [`Golang`]: https://go.dev/ |
150 | | //! [`Haskell`]: https://www.haskell.org/ |
151 | | //! [`Javascript`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript |
152 | | //! [`Perl`]: https://www.perl.org/ |
153 | | //! [`PHP`]: https://www.php.net/ |
154 | | //! [`Java`]: https://www.java.com/en/ |
155 | | //! [`R`]: https://www.r-project.org/ |
156 | | //! [`Kotlin`]: https://kotlinlang.org/ |
157 | | //! [`Julia`]: https://julialang.org/ |
158 | | //! [`C#`]: https://learn.microsoft.com/en-us/dotnet/csharp/ |
159 | | //! [`Kawa`]: https://www.gnu.org/software/kawa/ |
160 | | //! [`Gambit-C`]: https://gambitscheme.org/ |
161 | | //! [`Guile`]: https://www.gnu.org/software/guile/ |
162 | | //! [`Clojure`]: https://clojure.org/ |
163 | | //! [`Erlang`]: https://www.erlang.org/ |
164 | | //! [`Elm`]: https://elm-lang.org/ |
165 | | //! [`Scala`]: https://www.scala-lang.org/ |
166 | | //! [`Elixir`]: https://elixir-lang.org/ |
167 | | //! [`FORTRAN`]: https://fortran-lang.org/ |
168 | | //! [`D`]: https://dlang.org/ |
169 | | //! [`Coffeescript`]: https://coffeescript.org/ |
170 | | //! [`Cobol`]: https://www.ibm.com/think/topics/cobol |
171 | | //! [`F#`]: https://fsharp.org/ |
172 | | //! [`Visual Basic`]: https://learn.microsoft.com/en-us/dotnet/visual-basic/ |
173 | | //! [`OCaml`]: https://ocaml.org/ |
174 | | //! [`Objective-C`]: https://en.wikipedia.org/wiki/Objective-C |
175 | | //! [`ReasonML`]: https://reasonml.github.io/ |
176 | | //! [`Matlab`]: https://www.mathworks.com/products/matlab.html |
177 | | //! [`Zig`]: https://ziglang.org/ |
178 | | //! [`Sage`]: https://www.sagemath.org/ |
179 | | //! [`JSON-REF`]: https://www.json.org/json-en.html |
180 | | //! [`TOML-REF`]: https://toml.io/en/ |
181 | | //! [`YAML-REF`]: https://yaml.org/ |
182 | | //! [`XML-REF`]: https://en.wikipedia.org/wiki/XML |
183 | | //! [`SQLite`]: https://www.sqlite.org/ |
184 | | //! [`PostgreSQL`]: https://www.postgresql.org/ |
185 | | //! [`MySQL`]: https://www.mysql.com/ |
186 | | //! [`MongoDB`]: https://www.mongodb.com/ |
187 | | |
188 | | #![allow(clippy::must_use_candidate)] |
189 | | |
190 | | use lexical_util::ascii::{is_valid_ascii, is_valid_letter_slice}; |
191 | | use lexical_util::error::Error; |
192 | | use lexical_util::options::{self, ParseOptions}; |
193 | | use lexical_util::result::Result; |
194 | | |
195 | | /// Maximum length for a special string. |
196 | | pub const MAX_SPECIAL_STRING_LENGTH: usize = 50; |
197 | | |
198 | | /// Builder for [`Options`]. |
199 | | /// |
200 | | /// This enables extensive control over how the float is parsed, from |
201 | | /// control characters like the decimal point and the valid non-finite |
202 | | /// float representations. |
203 | | /// |
204 | | /// # Examples |
205 | | /// |
206 | | /// ```rust |
207 | | /// use lexical_parse_float::{FromLexicalWithOptions, Options}; |
208 | | /// use lexical_parse_float::format::STANDARD; |
209 | | /// |
210 | | /// const OPTIONS: Options = Options::builder() |
211 | | /// .decimal_point(b',') |
212 | | /// .build_strict(); |
213 | | /// let value = "1,2345e300"; |
214 | | /// let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS); |
215 | | /// assert_eq!(result, Ok(1.2345e300)); |
216 | | /// ``` |
217 | | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] |
218 | | pub struct OptionsBuilder { |
219 | | /// Disable the use of arbitrary-precision arithmetic, and always |
220 | | /// return the results from the fast or intermediate path algorithms. |
221 | | lossy: bool, |
222 | | /// Character to designate the exponent component of a float. |
223 | | exponent: u8, |
224 | | /// Character to separate the integer from the fraction components. |
225 | | decimal_point: u8, |
226 | | /// String representation of Not A Number, aka `NaN`. |
227 | | nan_string: Option<&'static [u8]>, |
228 | | /// Short string representation of `Infinity`. |
229 | | inf_string: Option<&'static [u8]>, |
230 | | /// Long string representation of `Infinity`. |
231 | | infinity_string: Option<&'static [u8]>, |
232 | | } |
233 | | |
234 | | impl OptionsBuilder { |
235 | | /// Create new options builder with default options. |
236 | | #[inline(always)] |
237 | 0 | pub const fn new() -> Self { |
238 | 0 | Self { |
239 | 0 | lossy: false, |
240 | 0 | exponent: b'e', |
241 | 0 | decimal_point: b'.', |
242 | 0 | nan_string: Some(b"NaN"), |
243 | 0 | inf_string: Some(b"inf"), |
244 | 0 | infinity_string: Some(b"infinity"), |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | | // GETTERS |
249 | | |
250 | | /// Get if we disable the use of arbitrary-precision arithmetic. |
251 | | /// |
252 | | /// Lossy algorithms never use the fallback, slow algorithm. Defaults to |
253 | | /// [`false`]. |
254 | | /// |
255 | | /// # Examples |
256 | | /// |
257 | | /// ```rust |
258 | | /// use lexical_parse_float::options::Options; |
259 | | /// |
260 | | /// assert_eq!(Options::builder().get_lossy(), false); |
261 | | /// ``` |
262 | | #[inline(always)] |
263 | 0 | pub const fn get_lossy(&self) -> bool { |
264 | 0 | self.lossy |
265 | 0 | } |
266 | | |
267 | | /// Get the character to designate the exponent component of a float. |
268 | | /// |
269 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
270 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `e`. |
271 | | /// |
272 | | /// # Examples |
273 | | /// |
274 | | /// ```rust |
275 | | /// use lexical_parse_float::options::Options; |
276 | | /// |
277 | | /// assert_eq!(Options::builder().get_exponent(), b'e'); |
278 | | /// ``` |
279 | | #[inline(always)] |
280 | 0 | pub const fn get_exponent(&self) -> u8 { |
281 | 0 | self.exponent |
282 | 0 | } |
283 | | |
284 | | /// Get the character to separate the integer from the fraction components. |
285 | | /// |
286 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
287 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `.`. |
288 | | /// |
289 | | /// # Examples |
290 | | /// |
291 | | /// ```rust |
292 | | /// use lexical_parse_float::options::Options; |
293 | | /// |
294 | | /// assert_eq!(Options::builder().get_decimal_point(), b'.'); |
295 | | /// ``` |
296 | | #[inline(always)] |
297 | 0 | pub const fn get_decimal_point(&self) -> u8 { |
298 | 0 | self.decimal_point |
299 | 0 | } |
300 | | |
301 | | /// Get the string representation for `NaN`. |
302 | | /// |
303 | | /// The first character must start with `N` or `n` and all characters must |
304 | | /// be valid ASCII letters (`A-Z` or `a-z`). Defaults to `NaN`. |
305 | | /// |
306 | | /// # Examples |
307 | | /// |
308 | | /// ```rust |
309 | | /// use lexical_parse_float::Options; |
310 | | /// |
311 | | /// let builder = Options::builder(); |
312 | | /// assert_eq!(builder.get_nan_string(), Some("NaN".as_bytes())); |
313 | | /// ``` |
314 | | #[inline(always)] |
315 | 0 | pub const fn get_nan_string(&self) -> Option<&'static [u8]> { |
316 | 0 | self.nan_string |
317 | 0 | } |
318 | | |
319 | | /// Get the short string representation for `Infinity`. |
320 | | /// |
321 | | /// The first character must start with `I` or `i` and all characters must |
322 | | /// be valid ASCII letters (`A-Z` or `a-z`). Defaults to `inf`. |
323 | | /// |
324 | | /// # Examples |
325 | | /// |
326 | | /// ```rust |
327 | | /// use lexical_parse_float::Options; |
328 | | /// |
329 | | /// let builder = Options::builder(); |
330 | | /// assert_eq!(builder.get_inf_string(), Some("inf".as_bytes())); |
331 | | /// ``` |
332 | | #[inline(always)] |
333 | 0 | pub const fn get_inf_string(&self) -> Option<&'static [u8]> { |
334 | 0 | self.inf_string |
335 | 0 | } |
336 | | |
337 | | /// Get the long string representation for `Infinity`. |
338 | | /// |
339 | | /// The first character must start with `I` or `i` and all characters must |
340 | | /// be valid ASCII letters (`A-Z` or `a-z`). Defaults to `infinity`. |
341 | | /// |
342 | | /// [`get_inf_string`]: Self::get_inf_string |
343 | | /// |
344 | | /// # Examples |
345 | | /// |
346 | | /// ```rust |
347 | | /// use lexical_parse_float::Options; |
348 | | /// |
349 | | /// let builder = Options::builder(); |
350 | | /// assert_eq!(builder.get_infinity_string(), Some("infinity".as_bytes())); |
351 | | /// ``` |
352 | | #[inline(always)] |
353 | 0 | pub const fn get_infinity_string(&self) -> Option<&'static [u8]> { |
354 | 0 | self.infinity_string |
355 | 0 | } |
356 | | |
357 | | // SETTERS |
358 | | |
359 | | /// Set if we disable the use of arbitrary-precision arithmetic. |
360 | | /// |
361 | | /// Lossy algorithms never use the fallback, slow algorithm. Defaults to |
362 | | /// [`false`]. |
363 | | /// |
364 | | /// # Examples |
365 | | /// |
366 | | /// ```rust |
367 | | /// use lexical_parse_float::options::Options; |
368 | | /// |
369 | | /// const OPTIONS: Options = Options::builder() |
370 | | /// .lossy(true) |
371 | | /// .build_strict(); |
372 | | /// assert_eq!(OPTIONS.lossy(), true); |
373 | | /// ``` |
374 | | #[must_use] |
375 | | #[inline(always)] |
376 | 0 | pub const fn lossy(mut self, lossy: bool) -> Self { |
377 | 0 | self.lossy = lossy; |
378 | 0 | self |
379 | 0 | } |
380 | | |
381 | | /// Set the character to designate the exponent component of a float. |
382 | | /// |
383 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
384 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `e`. |
385 | | /// |
386 | | /// # Examples |
387 | | /// |
388 | | /// ```rust |
389 | | /// use lexical_parse_float::options::Options; |
390 | | /// |
391 | | /// const OPTIONS: Options = Options::builder() |
392 | | /// .exponent(b'^') |
393 | | /// .build_strict(); |
394 | | /// assert_eq!(OPTIONS.exponent(), b'^'); |
395 | | /// ``` |
396 | | #[must_use] |
397 | | #[inline(always)] |
398 | 0 | pub const fn exponent(mut self, exponent: u8) -> Self { |
399 | 0 | self.exponent = exponent; |
400 | 0 | self |
401 | 0 | } |
402 | | |
403 | | /// Set the character to separate the integer from the fraction components. |
404 | | /// |
405 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
406 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `.`. |
407 | | /// |
408 | | /// # Examples |
409 | | /// |
410 | | /// ```rust |
411 | | /// use lexical_parse_float::options::Options; |
412 | | /// |
413 | | /// const OPTIONS: Options = Options::builder() |
414 | | /// .exponent(b',') |
415 | | /// .build_strict(); |
416 | | /// assert_eq!(OPTIONS.exponent(), b','); |
417 | | /// ``` |
418 | | #[must_use] |
419 | | #[inline(always)] |
420 | 0 | pub const fn decimal_point(mut self, decimal_point: u8) -> Self { |
421 | 0 | self.decimal_point = decimal_point; |
422 | 0 | self |
423 | 0 | } |
424 | | |
425 | | /// Set the string representation for `NaN`. |
426 | | /// |
427 | | /// The first character must start with `N` or `n` and all characters must |
428 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
429 | | /// [`NaN`][f64::NAN] returns an error. Defaults to `NaN`. |
430 | | /// |
431 | | /// # Examples |
432 | | /// |
433 | | /// ```rust |
434 | | /// use lexical_parse_float::Options; |
435 | | /// |
436 | | /// const OPTIONS: Options = Options::builder() |
437 | | /// .nan_string(Some(b"nan")) |
438 | | /// .build_strict(); |
439 | | /// assert_eq!(OPTIONS.nan_string(), Some(b"nan".as_ref())); |
440 | | /// ``` |
441 | | /// |
442 | | /// Panics |
443 | | /// |
444 | | /// Setting a value with more than 50 elements will panic at runtime. You |
445 | | /// should always build the format using [`build_strict`] or checking |
446 | | /// [`is_valid`] prior to using the format, to avoid unexpected panics. |
447 | | /// |
448 | | /// [`build_strict`]: Self::build_strict |
449 | | /// [`is_valid`]: Self::is_valid |
450 | | #[must_use] |
451 | | #[inline(always)] |
452 | 0 | pub const fn nan_string(mut self, nan_string: Option<&'static [u8]>) -> Self { |
453 | 0 | self.nan_string = nan_string; |
454 | 0 | self |
455 | 0 | } |
456 | | |
457 | | /// Set the short string representation for `Infinity`. |
458 | | /// |
459 | | /// The first character must start with `I` or `i` and all characters must |
460 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
461 | | /// [`Infinity`][f64::INFINITY] returns an error. Defaults to `inf`. |
462 | | /// |
463 | | /// # Examples |
464 | | /// |
465 | | /// ```rust |
466 | | /// use lexical_parse_float::Options; |
467 | | /// |
468 | | /// const OPTIONS: Options = Options::builder() |
469 | | /// .inf_string(Some(b"Infinity")) |
470 | | /// .build_strict(); |
471 | | /// assert_eq!(OPTIONS.inf_string(), Some(b"Infinity".as_ref())); |
472 | | /// ``` |
473 | | /// |
474 | | /// Panics |
475 | | /// |
476 | | /// Setting a value with more than 50 elements or one that is longer than |
477 | | /// [`infinity_string`] will panic at runtime. You should always build |
478 | | /// the format using [`build_strict`] or checking [`is_valid`] prior to |
479 | | /// using the format, to avoid unexpected panics. |
480 | | /// |
481 | | /// [`infinity_string`]: Self::infinity_string |
482 | | /// [`build_strict`]: Self::build_strict |
483 | | /// [`is_valid`]: Self::is_valid |
484 | | #[must_use] |
485 | | #[inline(always)] |
486 | 0 | pub const fn inf_string(mut self, inf_string: Option<&'static [u8]>) -> Self { |
487 | 0 | self.inf_string = inf_string; |
488 | 0 | self |
489 | 0 | } |
490 | | |
491 | | /// Set the long string representation for `Infinity`. |
492 | | /// |
493 | | /// The first character must start with `I` or `i` and all characters must |
494 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
495 | | /// [`Infinity`][f64::INFINITY] returns an error. Defaults to `infinity`. |
496 | | /// |
497 | | /// # Examples |
498 | | /// |
499 | | /// ```rust |
500 | | /// use lexical_parse_float::Options; |
501 | | /// |
502 | | /// const OPTIONS: Options = Options::builder() |
503 | | /// .infinity_string(Some(b"Infinity")) |
504 | | /// .build_strict(); |
505 | | /// assert_eq!(OPTIONS.infinity_string(), Some(b"Infinity".as_ref())); |
506 | | /// ``` |
507 | | /// |
508 | | /// Panics |
509 | | /// |
510 | | /// Setting a value with more than 50 elements or one that is shorter than |
511 | | /// [`inf_string`] will panic at runtime. You should always build the format |
512 | | /// using [`build_strict`] or checking [`is_valid`] prior to |
513 | | /// using the format, to avoid unexpected panics. |
514 | | /// |
515 | | /// [`inf_string`]: Self::inf_string |
516 | | /// [`build_strict`]: Self::build_strict |
517 | | /// [`is_valid`]: Self::is_valid |
518 | | #[must_use] |
519 | | #[inline(always)] |
520 | 0 | pub const fn infinity_string(mut self, infinity_string: Option<&'static [u8]>) -> Self { |
521 | 0 | self.infinity_string = infinity_string; |
522 | 0 | self |
523 | 0 | } |
524 | | |
525 | | // BUILDERS |
526 | | |
527 | | /// Determine if [`nan_string`] is valid. |
528 | | /// |
529 | | /// [`nan_string`]: Self::nan_string |
530 | | #[doc(hidden)] |
531 | | #[inline(always)] |
532 | | #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" |
533 | 0 | pub const fn nan_str_is_valid(&self) -> bool { |
534 | 0 | if self.nan_string.is_none() { |
535 | 0 | return true; |
536 | 0 | } |
537 | 0 |
|
538 | 0 | let nan = unwrap_str(self.nan_string); |
539 | 0 | let length = nan.len(); |
540 | 0 | if length == 0 || length > MAX_SPECIAL_STRING_LENGTH { |
541 | 0 | false |
542 | 0 | } else if !matches!(nan[0], b'N' | b'n') { |
543 | 0 | false |
544 | 0 | } else if !is_valid_letter_slice(nan) { |
545 | 0 | false |
546 | | } else { |
547 | 0 | true |
548 | | } |
549 | 0 | } |
550 | | |
551 | | /// Determine if [`inf_string`] is valid. |
552 | | /// |
553 | | /// [`inf_string`]: Self::inf_string |
554 | | #[doc(hidden)] |
555 | | #[inline(always)] |
556 | | #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" |
557 | 0 | pub const fn inf_str_is_valid(&self) -> bool { |
558 | 0 | if self.infinity_string.is_none() && self.inf_string.is_some() { |
559 | 0 | return false; |
560 | 0 | } else if self.inf_string.is_none() { |
561 | 0 | return true; |
562 | 0 | } |
563 | 0 |
|
564 | 0 | let inf = unwrap_str(self.inf_string); |
565 | 0 | let length = inf.len(); |
566 | 0 | let infinity = unwrap_str(self.infinity_string); |
567 | 0 | if length == 0 || length > MAX_SPECIAL_STRING_LENGTH { |
568 | 0 | false |
569 | 0 | } else if !matches!(inf[0], b'I' | b'i') { |
570 | 0 | false |
571 | 0 | } else if length > infinity.len() { |
572 | 0 | false |
573 | 0 | } else if !is_valid_letter_slice(inf) { |
574 | 0 | false |
575 | | } else { |
576 | 0 | true |
577 | | } |
578 | 0 | } |
579 | | |
580 | | /// Determine if [`infinity_string`] is valid. |
581 | | /// |
582 | | /// [`infinity_string`]: Self::infinity_string |
583 | | #[doc(hidden)] |
584 | | #[inline(always)] |
585 | | #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" |
586 | 0 | pub const fn infinity_string_is_valid(&self) -> bool { |
587 | 0 | if self.infinity_string.is_none() && self.inf_string.is_some() { |
588 | 0 | return false; |
589 | 0 | } else if self.infinity_string.is_none() { |
590 | 0 | return true; |
591 | 0 | } |
592 | 0 | let inf = unwrap_str(self.inf_string); |
593 | 0 | let infinity = unwrap_str(self.infinity_string); |
594 | 0 | let length = infinity.len(); |
595 | 0 | if length == 0 || length > MAX_SPECIAL_STRING_LENGTH { |
596 | 0 | false |
597 | 0 | } else if !matches!(infinity[0], b'I' | b'i') { |
598 | 0 | false |
599 | 0 | } else if length < inf.len() { |
600 | 0 | false |
601 | 0 | } else if !is_valid_letter_slice(infinity) { |
602 | 0 | false |
603 | | } else { |
604 | 0 | true |
605 | | } |
606 | 0 | } |
607 | | |
608 | | /// Check if the builder state is valid. |
609 | | #[inline(always)] |
610 | | #[allow(clippy::if_same_then_else, clippy::needless_bool)] // reason = "more idiomatic" |
611 | 0 | pub const fn is_valid(&self) -> bool { |
612 | 0 | if !is_valid_ascii(self.exponent) { |
613 | 0 | false |
614 | 0 | } else if !is_valid_ascii(self.decimal_point) { |
615 | 0 | false |
616 | 0 | } else if !self.nan_str_is_valid() { |
617 | 0 | false |
618 | 0 | } else if !self.inf_str_is_valid() { |
619 | 0 | false |
620 | 0 | } else if !self.infinity_string_is_valid() { |
621 | 0 | false |
622 | | } else { |
623 | 0 | true |
624 | | } |
625 | 0 | } |
626 | | |
627 | | /// Build the [`Options`] struct without validation. |
628 | | /// |
629 | | /// # Panics |
630 | | /// |
631 | | /// This is completely safe, however, misusing this, especially |
632 | | /// the [`nan_string`], [`inf_string`], and [`infinity_string`] could |
633 | | /// panic at runtime. Always use [`is_valid`] prior to using the built |
634 | | /// options. |
635 | | /// |
636 | | /// [`inf_string`]: Self::inf_string |
637 | | /// [`nan_string`]: Self::nan_string |
638 | | /// [`infinity_string`]: Self::infinity_string |
639 | | /// [`is_valid`]: Self::is_valid |
640 | | #[inline(always)] |
641 | 0 | pub const fn build_unchecked(&self) -> Options { |
642 | 0 | Options { |
643 | 0 | lossy: self.lossy, |
644 | 0 | exponent: self.exponent, |
645 | 0 | decimal_point: self.decimal_point, |
646 | 0 | nan_string: self.nan_string, |
647 | 0 | inf_string: self.inf_string, |
648 | 0 | infinity_string: self.infinity_string, |
649 | 0 | } |
650 | 0 | } |
651 | | |
652 | | /// Build the [`Options`] struct, panicking if the builder is invalid. |
653 | | /// |
654 | | /// # Panics |
655 | | /// |
656 | | /// If the built options are not valid. |
657 | | #[inline(always)] |
658 | 0 | pub const fn build_strict(&self) -> Options { |
659 | 0 | match self.build() { |
660 | 0 | Ok(value) => value, |
661 | 0 | Err(error) => core::panic!("{}", error.description()), |
662 | | } |
663 | 0 | } |
664 | | |
665 | | /// Build the [`Options`] struct. |
666 | | /// |
667 | | /// # Errors |
668 | | /// |
669 | | /// If the NaN, Inf, or Infinity strings are too long or invalid |
670 | | /// digits/characters are provided for some numerical formats. |
671 | | #[inline(always)] |
672 | | #[allow(clippy::if_same_then_else)] // reason = "more idiomatic" |
673 | 0 | pub const fn build(&self) -> Result<Options> { |
674 | 0 | if !is_valid_ascii(self.exponent) { |
675 | 0 | return Err(Error::InvalidExponentSymbol); |
676 | 0 | } else if !is_valid_ascii(self.decimal_point) { |
677 | 0 | return Err(Error::InvalidDecimalPoint); |
678 | 0 | } |
679 | 0 |
|
680 | 0 | if self.nan_string.is_some() { |
681 | 0 | let nan = unwrap_str(self.nan_string); |
682 | 0 | if nan.is_empty() || !matches!(nan[0], b'N' | b'n') { |
683 | 0 | return Err(Error::InvalidNanString); |
684 | 0 | } else if !is_valid_letter_slice(nan) { |
685 | 0 | return Err(Error::InvalidNanString); |
686 | 0 | } else if nan.len() > MAX_SPECIAL_STRING_LENGTH { |
687 | 0 | return Err(Error::NanStringTooLong); |
688 | 0 | } |
689 | 0 | } |
690 | | |
691 | 0 | if self.inf_string.is_some() && self.infinity_string.is_none() { |
692 | 0 | return Err(Error::InfinityStringTooShort); |
693 | 0 | } |
694 | 0 |
|
695 | 0 | if self.inf_string.is_some() { |
696 | 0 | let inf = unwrap_str(self.inf_string); |
697 | 0 | if inf.is_empty() || !matches!(inf[0], b'I' | b'i') { |
698 | 0 | return Err(Error::InvalidInfString); |
699 | 0 | } else if !is_valid_letter_slice(inf) { |
700 | 0 | return Err(Error::InvalidInfString); |
701 | 0 | } else if inf.len() > MAX_SPECIAL_STRING_LENGTH { |
702 | 0 | return Err(Error::InfStringTooLong); |
703 | 0 | } |
704 | 0 | } |
705 | | |
706 | 0 | if self.infinity_string.is_some() { |
707 | 0 | let inf = unwrap_str(self.inf_string); |
708 | 0 | let infinity = unwrap_str(self.infinity_string); |
709 | 0 | if infinity.is_empty() || !matches!(infinity[0], b'I' | b'i') { |
710 | 0 | return Err(Error::InvalidInfinityString); |
711 | 0 | } else if !is_valid_letter_slice(infinity) { |
712 | 0 | return Err(Error::InvalidInfinityString); |
713 | 0 | } else if infinity.len() > MAX_SPECIAL_STRING_LENGTH { |
714 | 0 | return Err(Error::InfinityStringTooLong); |
715 | 0 | } else if infinity.len() < inf.len() { |
716 | 0 | return Err(Error::InfinityStringTooShort); |
717 | 0 | } |
718 | 0 | } |
719 | | |
720 | 0 | Ok(self.build_unchecked()) |
721 | 0 | } |
722 | | } |
723 | | |
724 | | impl Default for OptionsBuilder { |
725 | | #[inline(always)] |
726 | 0 | fn default() -> Self { |
727 | 0 | Self::new() |
728 | 0 | } |
729 | | } |
730 | | |
731 | | /// Options to customize parsing floats. |
732 | | /// |
733 | | /// This enables extensive control over how the float is parsed, from |
734 | | /// control characters like the decimal point and the valid non-finite |
735 | | /// float representations. |
736 | | /// |
737 | | /// # Examples |
738 | | /// |
739 | | /// ```rust |
740 | | /// use lexical_parse_float::{FromLexicalWithOptions, Options}; |
741 | | /// use lexical_parse_float::format::STANDARD; |
742 | | /// |
743 | | /// const OPTIONS: Options = Options::builder() |
744 | | /// .lossy(true) |
745 | | /// .nan_string(Some(b"NaN")) |
746 | | /// .inf_string(Some(b"Inf")) |
747 | | /// .infinity_string(Some(b"Infinity")) |
748 | | /// .build_strict(); |
749 | | /// |
750 | | /// let value = "1.2345e300"; |
751 | | /// let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS); |
752 | | /// assert_eq!(result, Ok(1.2345e300)); |
753 | | /// |
754 | | /// let value = "NaN"; |
755 | | /// let result = f64::from_lexical_with_options::<STANDARD>(value.as_bytes(), &OPTIONS); |
756 | | /// assert_eq!(result.map(|x| x.is_nan()), Ok(true)); |
757 | | /// ``` |
758 | | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] |
759 | | pub struct Options { |
760 | | /// Disable the use of arbitrary-precision arithmetic, and always |
761 | | /// return the results from the fast or intermediate path algorithms. |
762 | | lossy: bool, |
763 | | /// Character to designate the exponent component of a float. |
764 | | exponent: u8, |
765 | | /// Character to separate the integer from the fraction components. |
766 | | decimal_point: u8, |
767 | | /// String representation of Not A Number, aka `NaN`. |
768 | | nan_string: Option<&'static [u8]>, |
769 | | /// Short string representation of `Infinity`. |
770 | | inf_string: Option<&'static [u8]>, |
771 | | /// Long string representation of `Infinity`. |
772 | | infinity_string: Option<&'static [u8]>, |
773 | | } |
774 | | |
775 | | impl Options { |
776 | | // CONSTRUCTORS |
777 | | |
778 | | /// Create options with default values. |
779 | | #[inline(always)] |
780 | 0 | pub const fn new() -> Self { |
781 | 0 | Self::builder().build_unchecked() |
782 | 0 | } |
783 | | |
784 | | /// Create the default options for a given radix. |
785 | | /// |
786 | | /// This sets the exponent to `^` for any radix where `e` |
787 | | /// would be a valid digit. |
788 | | #[inline(always)] |
789 | | #[cfg(feature = "power-of-two")] |
790 | | pub const fn from_radix(radix: u8) -> Self { |
791 | | // Need to determine the correct exponent character ('e' or '^'), |
792 | | // since the default character is `e` normally, but this is a valid |
793 | | // digit for radix >= 15. |
794 | | let mut builder = Self::builder(); |
795 | | if radix >= 15 { |
796 | | builder = builder.exponent(b'^'); |
797 | | } |
798 | | builder.build_unchecked() |
799 | | } |
800 | | |
801 | | // GETTERS |
802 | | |
803 | | /// Check if the options state is valid. |
804 | | #[inline(always)] |
805 | 0 | pub const fn is_valid(&self) -> bool { |
806 | 0 | self.rebuild().is_valid() |
807 | 0 | } |
808 | | |
809 | | /// Get if we disable the use of arbitrary-precision arithmetic. |
810 | | /// |
811 | | /// Lossy algorithms never use the fallback, slow algorithm. Defaults to |
812 | | /// [`false`]. |
813 | | /// |
814 | | /// # Examples |
815 | | /// |
816 | | /// ```rust |
817 | | /// use lexical_parse_float::options::Options; |
818 | | /// |
819 | | /// assert_eq!(Options::new().lossy(), false); |
820 | | /// ``` |
821 | | #[inline(always)] |
822 | 4.03k | pub const fn lossy(&self) -> bool { |
823 | 4.03k | self.lossy |
824 | 4.03k | } |
825 | | |
826 | | /// Get the character to designate the exponent component of a float. |
827 | | /// |
828 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
829 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `e`. |
830 | | /// |
831 | | /// # Examples |
832 | | /// |
833 | | /// ```rust |
834 | | /// use lexical_parse_float::options::Options; |
835 | | /// |
836 | | /// assert_eq!(Options::new().exponent(), b'e'); |
837 | | /// ``` |
838 | | #[inline(always)] |
839 | 4.61k | pub const fn exponent(&self) -> u8 { |
840 | 4.61k | self.exponent |
841 | 4.61k | } |
842 | | |
843 | | /// Get the character to separate the integer from the fraction components. |
844 | | /// |
845 | | /// Any non-control character is valid, but `\t` to `\r` are also valid. |
846 | | /// The full range is `[0x09, 0x0D]` and `[0x20, 0x7F]`. Defaults to `.`. |
847 | | /// |
848 | | /// # Examples |
849 | | /// |
850 | | /// ```rust |
851 | | /// use lexical_parse_float::options::Options; |
852 | | /// |
853 | | /// assert_eq!(Options::new().decimal_point(), b'.'); |
854 | | /// ``` |
855 | | #[inline(always)] |
856 | 4.61k | pub const fn decimal_point(&self) -> u8 { |
857 | 4.61k | self.decimal_point |
858 | 4.61k | } |
859 | | |
860 | | /// Get the string representation for `NaN`. |
861 | | /// |
862 | | /// The first character must start with `N` or `n` and all characters must |
863 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
864 | | /// [`NaN`][f64::NAN] returns an error. Defaults to `NaN`. |
865 | | /// |
866 | | /// # Examples |
867 | | /// |
868 | | /// ```rust |
869 | | /// use lexical_parse_float::options::Options; |
870 | | /// |
871 | | /// assert_eq!(Options::new().nan_string(), Some(b"NaN".as_ref())); |
872 | | /// ``` |
873 | | #[inline(always)] |
874 | 239 | pub const fn nan_string(&self) -> Option<&'static [u8]> { |
875 | 239 | self.nan_string |
876 | 239 | } |
877 | | |
878 | | /// Get the short string representation for `Infinity`. |
879 | | /// |
880 | | /// The first character must start with `I` or `i` and all characters must |
881 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
882 | | /// [`Infinity`][f64::INFINITY] returns an error. Defaults to `inf`. |
883 | | /// |
884 | | /// # Examples |
885 | | /// |
886 | | /// ```rust |
887 | | /// use lexical_parse_float::options::Options; |
888 | | /// |
889 | | /// assert_eq!(Options::new().inf_string(), Some(b"inf".as_ref())); |
890 | | /// ``` |
891 | | #[inline(always)] |
892 | 239 | pub const fn inf_string(&self) -> Option<&'static [u8]> { |
893 | 239 | self.inf_string |
894 | 239 | } |
895 | | |
896 | | /// Get the long string representation for `Infinity`. |
897 | | /// |
898 | | /// The first character must start with `I` or `i` and all characters must |
899 | | /// be valid ASCII letters (`A-Z` or `a-z`). If set to `None`, then parsing |
900 | | /// [`Infinity`][f64::INFINITY] returns an error. Defaults to `infinity`. |
901 | | /// |
902 | | /// # Examples |
903 | | /// |
904 | | /// ```rust |
905 | | /// use lexical_parse_float::options::Options; |
906 | | /// |
907 | | /// assert_eq!(Options::new().infinity_string(), Some(b"infinity".as_ref())); |
908 | | /// ``` |
909 | | #[inline(always)] |
910 | 239 | pub const fn infinity_string(&self) -> Option<&'static [u8]> { |
911 | 239 | self.infinity_string |
912 | 239 | } |
913 | | |
914 | | // SETTERS |
915 | | |
916 | | /// Set if we disable the use of arbitrary-precision arithmetic. |
917 | | #[inline(always)] |
918 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
919 | 0 | pub fn set_lossy(&mut self, lossy: bool) { |
920 | 0 | self.lossy = lossy; |
921 | 0 | } |
922 | | |
923 | | /// Set the character to designate the exponent component of a float. |
924 | | #[inline(always)] |
925 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
926 | 0 | pub fn set_exponent(&mut self, exponent: u8) { |
927 | 0 | self.exponent = exponent; |
928 | 0 | } |
929 | | |
930 | | /// Set the character to separate the integer from the fraction components. |
931 | | #[inline(always)] |
932 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
933 | 0 | pub fn set_decimal_point(&mut self, decimal_point: u8) { |
934 | 0 | self.decimal_point = decimal_point; |
935 | 0 | } |
936 | | |
937 | | /// Set the string representation for `NaN`. |
938 | | #[inline(always)] |
939 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
940 | 0 | pub fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>) { |
941 | 0 | self.nan_string = nan_string; |
942 | 0 | } |
943 | | |
944 | | /// Set the short string representation for `Infinity` |
945 | | #[inline(always)] |
946 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
947 | 0 | pub fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>) { |
948 | 0 | self.inf_string = inf_string; |
949 | 0 | } |
950 | | |
951 | | /// Set the long string representation for `Infinity` |
952 | | #[inline(always)] |
953 | | #[deprecated = "Options should be treated as immutable, use `OptionsBuilder` instead. Will be removed in 2.0."] |
954 | 0 | pub fn set_infinity_string(&mut self, infinity_string: Option<&'static [u8]>) { |
955 | 0 | self.infinity_string = infinity_string; |
956 | 0 | } |
957 | | |
958 | | // BUILDERS |
959 | | |
960 | | /// Get [`OptionsBuilder`] as a static function. |
961 | | #[must_use] |
962 | | #[inline(always)] |
963 | 0 | pub const fn builder() -> OptionsBuilder { |
964 | 0 | OptionsBuilder::new() |
965 | 0 | } |
966 | | |
967 | | /// Create [`OptionsBuilder`] using existing values. |
968 | | #[must_use] |
969 | | #[inline(always)] |
970 | 0 | pub const fn rebuild(&self) -> OptionsBuilder { |
971 | 0 | OptionsBuilder { |
972 | 0 | lossy: self.lossy, |
973 | 0 | exponent: self.exponent, |
974 | 0 | decimal_point: self.decimal_point, |
975 | 0 | nan_string: self.nan_string, |
976 | 0 | inf_string: self.inf_string, |
977 | 0 | infinity_string: self.infinity_string, |
978 | 0 | } |
979 | 0 | } |
980 | | } |
981 | | |
982 | | impl Default for Options { |
983 | | #[inline(always)] |
984 | 0 | fn default() -> Self { |
985 | 0 | Self::new() |
986 | 0 | } |
987 | | } |
988 | | |
989 | | impl ParseOptions for Options { |
990 | | #[inline(always)] |
991 | 0 | fn is_valid(&self) -> bool { |
992 | 0 | Self::is_valid(self) |
993 | 0 | } |
994 | | } |
995 | | |
996 | | /// Unwrap `Option` as a const fn. |
997 | | #[inline(always)] |
998 | 0 | const fn unwrap_str(option: Option<&'static [u8]>) -> &'static [u8] { |
999 | 0 | match option { |
1000 | 0 | Some(x) => x, |
1001 | 0 | None => &[], |
1002 | | } |
1003 | 0 | } |
1004 | | |
1005 | | // PRE-DEFINED CONSTANTS |
1006 | | // --------------------- |
1007 | | |
1008 | | // Only constants that differ from the standard version are included. |
1009 | | |
1010 | | /// Standard number format. |
1011 | | #[rustfmt::skip] |
1012 | | pub const STANDARD: Options = Options::new(); |
1013 | | |
1014 | | /// Numerical format with a decimal comma. |
1015 | | /// This is the standard numerical format for most of the world. |
1016 | | #[rustfmt::skip] |
1017 | | pub const DECIMAL_COMMA: Options = Options::builder() |
1018 | | .decimal_point(b',') |
1019 | | .build_strict(); |
1020 | | |
1021 | | /// Numerical format for hexadecimal floats, which use a `p` exponent. |
1022 | | #[rustfmt::skip] |
1023 | | pub const HEX_FLOAT: Options = Options::builder() |
1024 | | .exponent(b'p') |
1025 | | .build_strict(); |
1026 | | |
1027 | | /// Numerical format where `^` is used as the exponent notation character. |
1028 | | /// This isn't very common, but is useful when `e` or `p` are valid digits. |
1029 | | #[rustfmt::skip] |
1030 | | pub const CARAT_EXPONENT: Options = Options::builder() |
1031 | | .exponent(b'^') |
1032 | | .build_strict(); |
1033 | | |
1034 | | /// Number format for a `Rust` literal floating-point number. |
1035 | | #[rustfmt::skip] |
1036 | | pub const RUST_LITERAL: Options = Options::builder() |
1037 | | .nan_string(options::RUST_LITERAL) |
1038 | | .inf_string(options::RUST_LITERAL) |
1039 | | .infinity_string(options::RUST_LITERAL) |
1040 | | .build_strict(); |
1041 | | |
1042 | | /// Number format for a `Python` literal floating-point number. |
1043 | | #[rustfmt::skip] |
1044 | | pub const PYTHON_LITERAL: Options = Options::builder() |
1045 | | .nan_string(options::PYTHON_LITERAL) |
1046 | | .inf_string(options::PYTHON_LITERAL) |
1047 | | .infinity_string(options::PYTHON_LITERAL) |
1048 | | .build_strict(); |
1049 | | |
1050 | | /// Number format for a `C++` literal floating-point number. |
1051 | | #[rustfmt::skip] |
1052 | | pub const CXX_LITERAL: Options = Options::builder() |
1053 | | .nan_string(options::CXX_LITERAL_NAN) |
1054 | | .inf_string(options::CXX_LITERAL_INF) |
1055 | | .infinity_string(options::CXX_LITERAL_INFINITY) |
1056 | | .build_strict(); |
1057 | | |
1058 | | /// Number format for a `C` literal floating-point number. |
1059 | | #[rustfmt::skip] |
1060 | | pub const C_LITERAL: Options = Options::builder() |
1061 | | .nan_string(options::C_LITERAL_NAN) |
1062 | | .inf_string(options::C_LITERAL_INF) |
1063 | | .infinity_string(options::C_LITERAL_INFINITY) |
1064 | | .build_strict(); |
1065 | | |
1066 | | /// Number format for a `Ruby` literal floating-point number. |
1067 | | #[rustfmt::skip] |
1068 | | pub const RUBY_LITERAL: Options = Options::builder() |
1069 | | .nan_string(options::RUBY_LITERAL_NAN) |
1070 | | .inf_string(options::RUBY_LITERAL_INF) |
1071 | | .infinity_string(options::RUBY_LITERAL_INF) |
1072 | | .build_strict(); |
1073 | | |
1074 | | /// Number format to parse a `Ruby` float from string. |
1075 | | /// `Ruby` can write NaN and Infinity as strings, but won't round-trip them back to floats. |
1076 | | #[rustfmt::skip] |
1077 | | pub const RUBY_STRING: Options = Options::builder() |
1078 | | .nan_string(options::RUBY_STRING_NONE) |
1079 | | .inf_string(options::RUBY_STRING_NONE) |
1080 | | .infinity_string(options::RUBY_STRING_NONE) |
1081 | | .build_strict(); |
1082 | | |
1083 | | /// Number format for a `Swift` literal floating-point number. |
1084 | | #[rustfmt::skip] |
1085 | | pub const SWIFT_LITERAL: Options = Options::builder() |
1086 | | .nan_string(options::SWIFT_LITERAL) |
1087 | | .inf_string(options::SWIFT_LITERAL) |
1088 | | .infinity_string(options::SWIFT_LITERAL) |
1089 | | .build_strict(); |
1090 | | |
1091 | | /// Number format for a `Go` literal floating-point number. |
1092 | | #[rustfmt::skip] |
1093 | | pub const GO_LITERAL: Options = Options::builder() |
1094 | | .nan_string(options::GO_LITERAL) |
1095 | | .inf_string(options::GO_LITERAL) |
1096 | | .infinity_string(options::GO_LITERAL) |
1097 | | .build_strict(); |
1098 | | |
1099 | | /// Number format for a `Haskell` literal floating-point number. |
1100 | | #[rustfmt::skip] |
1101 | | pub const HASKELL_LITERAL: Options = Options::builder() |
1102 | | .nan_string(options::HASKELL_LITERAL) |
1103 | | .inf_string(options::HASKELL_LITERAL) |
1104 | | .infinity_string(options::HASKELL_LITERAL) |
1105 | | .build_strict(); |
1106 | | |
1107 | | /// Number format to parse a `Haskell` float from string. |
1108 | | #[rustfmt::skip] |
1109 | | pub const HASKELL_STRING: Options = Options::builder() |
1110 | | .inf_string(options::HASKELL_STRING_INF) |
1111 | | .infinity_string(options::HASKELL_STRING_INFINITY) |
1112 | | .build_strict(); |
1113 | | |
1114 | | /// Number format for a `Javascript` literal floating-point number. |
1115 | | #[rustfmt::skip] |
1116 | | pub const JAVASCRIPT_LITERAL: Options = Options::builder() |
1117 | | .inf_string(options::JAVASCRIPT_INF) |
1118 | | .infinity_string(options::JAVASCRIPT_INFINITY) |
1119 | | .build_strict(); |
1120 | | |
1121 | | /// Number format to parse a `Javascript` float from string. |
1122 | | #[rustfmt::skip] |
1123 | | pub const JAVASCRIPT_STRING: Options = Options::builder() |
1124 | | .inf_string(options::JAVASCRIPT_INF) |
1125 | | .infinity_string(options::JAVASCRIPT_INFINITY) |
1126 | | .build_strict(); |
1127 | | |
1128 | | /// Number format for a `Perl` literal floating-point number. |
1129 | | #[rustfmt::skip] |
1130 | | pub const PERL_LITERAL: Options = Options::builder() |
1131 | | .nan_string(options::PERL_LITERAL) |
1132 | | .inf_string(options::PERL_LITERAL) |
1133 | | .infinity_string(options::PERL_LITERAL) |
1134 | | .build_strict(); |
1135 | | |
1136 | | /// Number format for a `PHP` literal floating-point number. |
1137 | | #[rustfmt::skip] |
1138 | | pub const PHP_LITERAL: Options = Options::builder() |
1139 | | .nan_string(options::PHP_LITERAL_NAN) |
1140 | | .inf_string(options::PHP_LITERAL_INF) |
1141 | | .infinity_string(options::PHP_LITERAL_INFINITY) |
1142 | | .build_strict(); |
1143 | | |
1144 | | /// Number format for a `Java` literal floating-point number. |
1145 | | #[rustfmt::skip] |
1146 | | pub const JAVA_LITERAL: Options = Options::builder() |
1147 | | .nan_string(options::JAVA_LITERAL) |
1148 | | .inf_string(options::JAVA_LITERAL) |
1149 | | .infinity_string(options::JAVA_LITERAL) |
1150 | | .build_strict(); |
1151 | | |
1152 | | /// Number format to parse a `Java` float from string. |
1153 | | #[rustfmt::skip] |
1154 | | pub const JAVA_STRING: Options = Options::builder() |
1155 | | .inf_string(options::JAVA_STRING_INF) |
1156 | | .infinity_string(options::JAVA_STRING_INFINITY) |
1157 | | .build_strict(); |
1158 | | |
1159 | | /// Number format for an `R` literal floating-point number. |
1160 | | #[rustfmt::skip] |
1161 | | pub const R_LITERAL: Options = Options::builder() |
1162 | | .inf_string(options::R_LITERAL_INF) |
1163 | | .infinity_string(options::R_LITERAL_INFINITY) |
1164 | | .build_strict(); |
1165 | | |
1166 | | /// Number format for a `Kotlin` literal floating-point number. |
1167 | | #[rustfmt::skip] |
1168 | | pub const KOTLIN_LITERAL: Options = Options::builder() |
1169 | | .nan_string(options::KOTLIN_LITERAL) |
1170 | | .inf_string(options::KOTLIN_LITERAL) |
1171 | | .infinity_string(options::KOTLIN_LITERAL) |
1172 | | .build_strict(); |
1173 | | |
1174 | | /// Number format to parse a `Kotlin` float from string. |
1175 | | #[rustfmt::skip] |
1176 | | pub const KOTLIN_STRING: Options = Options::builder() |
1177 | | .inf_string(options::KOTLIN_STRING_INF) |
1178 | | .infinity_string(options::KOTLIN_STRING_INFINITY) |
1179 | | .build_strict(); |
1180 | | |
1181 | | /// Number format for a `Julia` literal floating-point number. |
1182 | | #[rustfmt::skip] |
1183 | | pub const JULIA_LITERAL: Options = Options::builder() |
1184 | | .inf_string(options::JULIA_LITERAL_INF) |
1185 | | .infinity_string(options::JULIA_LITERAL_INFINITY) |
1186 | | .build_strict(); |
1187 | | |
1188 | | /// Number format for a `C#` literal floating-point number. |
1189 | | #[rustfmt::skip] |
1190 | | pub const CSHARP_LITERAL: Options = Options::builder() |
1191 | | .nan_string(options::CSHARP_LITERAL) |
1192 | | .inf_string(options::CSHARP_LITERAL) |
1193 | | .infinity_string(options::CSHARP_LITERAL) |
1194 | | .build_strict(); |
1195 | | |
1196 | | /// Number format to parse a `C#` float from string. |
1197 | | #[rustfmt::skip] |
1198 | | pub const CSHARP_STRING: Options = Options::builder() |
1199 | | .inf_string(options::CSHARP_STRING_INF) |
1200 | | .infinity_string(options::CSHARP_STRING_INFINITY) |
1201 | | .build_strict(); |
1202 | | |
1203 | | /// Number format for a `Kawa` literal floating-point number. |
1204 | | #[rustfmt::skip] |
1205 | | pub const KAWA_LITERAL: Options = Options::builder() |
1206 | | .nan_string(options::KAWA) |
1207 | | .inf_string(options::KAWA) |
1208 | | .infinity_string(options::KAWA) |
1209 | | .build_strict(); |
1210 | | |
1211 | | /// Number format to parse a `Kawa` float from string. |
1212 | | #[rustfmt::skip] |
1213 | | pub const KAWA_STRING: Options = Options::builder() |
1214 | | .nan_string(options::KAWA) |
1215 | | .inf_string(options::KAWA) |
1216 | | .infinity_string(options::KAWA) |
1217 | | .build_strict(); |
1218 | | |
1219 | | /// Number format for a `Gambit-C` literal floating-point number. |
1220 | | #[rustfmt::skip] |
1221 | | pub const GAMBITC_LITERAL: Options = Options::builder() |
1222 | | .nan_string(options::GAMBITC) |
1223 | | .inf_string(options::GAMBITC) |
1224 | | .infinity_string(options::GAMBITC) |
1225 | | .build_strict(); |
1226 | | |
1227 | | /// Number format to parse a `Gambit-C` float from string. |
1228 | | #[rustfmt::skip] |
1229 | | pub const GAMBITC_STRING: Options = Options::builder() |
1230 | | .nan_string(options::GAMBITC) |
1231 | | .inf_string(options::GAMBITC) |
1232 | | .infinity_string(options::GAMBITC) |
1233 | | .build_strict(); |
1234 | | |
1235 | | /// Number format for a `Guile` literal floating-point number. |
1236 | | #[rustfmt::skip] |
1237 | | pub const GUILE_LITERAL: Options = Options::builder() |
1238 | | .nan_string(options::GUILE) |
1239 | | .inf_string(options::GUILE) |
1240 | | .infinity_string(options::GUILE) |
1241 | | .build_strict(); |
1242 | | |
1243 | | /// Number format to parse a `Guile` float from string. |
1244 | | #[rustfmt::skip] |
1245 | | pub const GUILE_STRING: Options = Options::builder() |
1246 | | .nan_string(options::GUILE) |
1247 | | .inf_string(options::GUILE) |
1248 | | .infinity_string(options::GUILE) |
1249 | | .build_strict(); |
1250 | | |
1251 | | /// Number format for a `Clojure` literal floating-point number. |
1252 | | #[rustfmt::skip] |
1253 | | pub const CLOJURE_LITERAL: Options = Options::builder() |
1254 | | .nan_string(options::CLOJURE_LITERAL) |
1255 | | .inf_string(options::CLOJURE_LITERAL) |
1256 | | .infinity_string(options::CLOJURE_LITERAL) |
1257 | | .build_strict(); |
1258 | | |
1259 | | /// Number format to parse a `Clojure` float from string. |
1260 | | #[rustfmt::skip] |
1261 | | pub const CLOJURE_STRING: Options = Options::builder() |
1262 | | .inf_string(options::CLOJURE_STRING_INF) |
1263 | | .infinity_string(options::CLOJURE_STRING_INFINITY) |
1264 | | .build_strict(); |
1265 | | |
1266 | | /// Number format for an `Erlang` literal floating-point number. |
1267 | | #[rustfmt::skip] |
1268 | | pub const ERLANG_LITERAL: Options = Options::builder() |
1269 | | .nan_string(options::ERLANG_LITERAL_NAN) |
1270 | | .build_strict(); |
1271 | | |
1272 | | /// Number format to parse an `Erlang` float from string. |
1273 | | #[rustfmt::skip] |
1274 | | pub const ERLANG_STRING: Options = Options::builder() |
1275 | | .nan_string(options::ERLANG_STRING) |
1276 | | .inf_string(options::ERLANG_STRING) |
1277 | | .infinity_string(options::ERLANG_STRING) |
1278 | | .build_strict(); |
1279 | | |
1280 | | /// Number format for an `Elm` literal floating-point number. |
1281 | | #[rustfmt::skip] |
1282 | | pub const ELM_LITERAL: Options = Options::builder() |
1283 | | .nan_string(options::ELM_LITERAL) |
1284 | | .inf_string(options::ELM_LITERAL) |
1285 | | .infinity_string(options::ELM_LITERAL) |
1286 | | .build_strict(); |
1287 | | |
1288 | | /// Number format to parse an `Elm` float from string. |
1289 | | #[rustfmt::skip] |
1290 | | pub const ELM_STRING: Options = Options::builder() |
1291 | | .nan_string(options::ELM_STRING_NAN) |
1292 | | .inf_string(options::ELM_STRING_INF) |
1293 | | .infinity_string(options::ELM_STRING_INFINITY) |
1294 | | .build_strict(); |
1295 | | |
1296 | | /// Number format for a `Scala` literal floating-point number. |
1297 | | #[rustfmt::skip] |
1298 | | pub const SCALA_LITERAL: Options = Options::builder() |
1299 | | .nan_string(options::SCALA_LITERAL) |
1300 | | .inf_string(options::SCALA_LITERAL) |
1301 | | .infinity_string(options::SCALA_LITERAL) |
1302 | | .build_strict(); |
1303 | | |
1304 | | /// Number format to parse a `Scala` float from string. |
1305 | | #[rustfmt::skip] |
1306 | | pub const SCALA_STRING: Options = Options::builder() |
1307 | | .inf_string(options::SCALA_STRING_INF) |
1308 | | .infinity_string(options::SCALA_STRING_INFINITY) |
1309 | | .build_strict(); |
1310 | | |
1311 | | /// Number format for an `Elixir` literal floating-point number. |
1312 | | #[rustfmt::skip] |
1313 | | pub const ELIXIR_LITERAL: Options = Options::builder() |
1314 | | .nan_string(options::ELIXIR) |
1315 | | .inf_string(options::ELIXIR) |
1316 | | .infinity_string(options::ELIXIR) |
1317 | | .build_strict(); |
1318 | | |
1319 | | /// Number format to parse an `Elixir` float from string. |
1320 | | #[rustfmt::skip] |
1321 | | pub const ELIXIR_STRING: Options = Options::builder() |
1322 | | .nan_string(options::ELIXIR) |
1323 | | .inf_string(options::ELIXIR) |
1324 | | .infinity_string(options::ELIXIR) |
1325 | | .build_strict(); |
1326 | | |
1327 | | /// Number format for a `FORTRAN` literal floating-point number. |
1328 | | #[rustfmt::skip] |
1329 | | pub const FORTRAN_LITERAL: Options = Options::builder() |
1330 | | .nan_string(options::FORTRAN_LITERAL) |
1331 | | .inf_string(options::FORTRAN_LITERAL) |
1332 | | .infinity_string(options::FORTRAN_LITERAL) |
1333 | | .build_strict(); |
1334 | | |
1335 | | /// Number format for a `D` literal floating-point number. |
1336 | | #[rustfmt::skip] |
1337 | | pub const D_LITERAL: Options = Options::builder() |
1338 | | .nan_string(options::D_LITERAL) |
1339 | | .inf_string(options::D_LITERAL) |
1340 | | .infinity_string(options::D_LITERAL) |
1341 | | .build_strict(); |
1342 | | |
1343 | | /// Number format for a `Coffeescript` literal floating-point number. |
1344 | | #[rustfmt::skip] |
1345 | | pub const COFFEESCRIPT_LITERAL: Options = Options::builder() |
1346 | | .inf_string(options::COFFEESCRIPT_INF) |
1347 | | .infinity_string(options::COFFEESCRIPT_INFINITY) |
1348 | | .build_strict(); |
1349 | | |
1350 | | /// Number format to parse a `Coffeescript` float from string. |
1351 | | #[rustfmt::skip] |
1352 | | pub const COFFEESCRIPT_STRING: Options = Options::builder() |
1353 | | .inf_string(options::COFFEESCRIPT_INF) |
1354 | | .infinity_string(options::COFFEESCRIPT_INFINITY) |
1355 | | .build_strict(); |
1356 | | |
1357 | | /// Number format for a `COBOL` literal floating-point number. |
1358 | | #[rustfmt::skip] |
1359 | | pub const COBOL_LITERAL: Options = Options::builder() |
1360 | | .nan_string(options::COBOL) |
1361 | | .inf_string(options::COBOL) |
1362 | | .infinity_string(options::COBOL) |
1363 | | .build_strict(); |
1364 | | |
1365 | | /// Number format to parse a `COBOL` float from string. |
1366 | | #[rustfmt::skip] |
1367 | | pub const COBOL_STRING: Options = Options::builder() |
1368 | | .nan_string(options::COBOL) |
1369 | | .inf_string(options::COBOL) |
1370 | | .infinity_string(options::COBOL) |
1371 | | .build_strict(); |
1372 | | |
1373 | | /// Number format for an `F#` literal floating-point number. |
1374 | | #[rustfmt::skip] |
1375 | | pub const FSHARP_LITERAL: Options = Options::builder() |
1376 | | .nan_string(options::FSHARP_LITERAL_NAN) |
1377 | | .inf_string(options::FSHARP_LITERAL_INF) |
1378 | | .infinity_string(options::FSHARP_LITERAL_INFINITY) |
1379 | | .build_strict(); |
1380 | | |
1381 | | /// Number format for a Visual Basic literal floating-point number. |
1382 | | #[rustfmt::skip] |
1383 | | pub const VB_LITERAL: Options = Options::builder() |
1384 | | .nan_string(options::VB_LITERAL) |
1385 | | .inf_string(options::VB_LITERAL) |
1386 | | .infinity_string(options::VB_LITERAL) |
1387 | | .build_strict(); |
1388 | | |
1389 | | /// Number format to parse a `Visual Basic` float from string. |
1390 | | #[rustfmt::skip] |
1391 | | pub const VB_STRING: Options = Options::builder() |
1392 | | .inf_string(options::VB_STRING_INF) |
1393 | | .infinity_string(options::VB_STRING_INFINITY) |
1394 | | .build_strict(); |
1395 | | |
1396 | | /// Number format for an `OCaml` literal floating-point number. |
1397 | | #[rustfmt::skip] |
1398 | | pub const OCAML_LITERAL: Options = Options::builder() |
1399 | | .nan_string(options::OCAML_LITERAL_NAN) |
1400 | | .inf_string(options::OCAML_LITERAL_INF) |
1401 | | .infinity_string(options::OCAML_LITERAL_INFINITY) |
1402 | | .build_strict(); |
1403 | | |
1404 | | /// Number format for an `Objective-C` literal floating-point number. |
1405 | | #[rustfmt::skip] |
1406 | | pub const OBJECTIVEC_LITERAL: Options = Options::builder() |
1407 | | .nan_string(options::OBJECTIVEC) |
1408 | | .inf_string(options::OBJECTIVEC) |
1409 | | .infinity_string(options::OBJECTIVEC) |
1410 | | .build_strict(); |
1411 | | |
1412 | | /// Number format to parse an `Objective-C` float from string. |
1413 | | #[rustfmt::skip] |
1414 | | pub const OBJECTIVEC_STRING: Options = Options::builder() |
1415 | | .nan_string(options::OBJECTIVEC) |
1416 | | .inf_string(options::OBJECTIVEC) |
1417 | | .infinity_string(options::OBJECTIVEC) |
1418 | | .build_strict(); |
1419 | | |
1420 | | /// Number format for an `ReasonML` literal floating-point number. |
1421 | | #[rustfmt::skip] |
1422 | | pub const REASONML_LITERAL: Options = Options::builder() |
1423 | | .nan_string(options::REASONML_LITERAL_NAN) |
1424 | | .inf_string(options::REASONML_LITERAL_INF) |
1425 | | .infinity_string(options::REASONML_LITERAL_INFINITY) |
1426 | | .build_strict(); |
1427 | | |
1428 | | /// Number format for a `MATLAB` literal floating-point number. |
1429 | | #[rustfmt::skip] |
1430 | | pub const MATLAB_LITERAL: Options = Options::builder() |
1431 | | .inf_string(options::MATLAB_LITERAL_INF) |
1432 | | .infinity_string(options::MATLAB_LITERAL_INFINITY) |
1433 | | .build_strict(); |
1434 | | |
1435 | | /// Number format for a `Zig` literal floating-point number. |
1436 | | #[rustfmt::skip] |
1437 | | pub const ZIG_LITERAL: Options = Options::builder() |
1438 | | .nan_string(options::ZIG_LITERAL) |
1439 | | .inf_string(options::ZIG_LITERAL) |
1440 | | .infinity_string(options::ZIG_LITERAL) |
1441 | | .build_strict(); |
1442 | | |
1443 | | /// Number format for a `Sage` literal floating-point number. |
1444 | | #[rustfmt::skip] |
1445 | | pub const SAGE_LITERAL: Options = Options::builder() |
1446 | | .inf_string(options::SAGE_LITERAL_INF) |
1447 | | .infinity_string(options::SAGE_LITERAL_INFINITY) |
1448 | | .build_strict(); |
1449 | | |
1450 | | /// Number format for a `JSON` literal floating-point number. |
1451 | | #[rustfmt::skip] |
1452 | | pub const JSON: Options = Options::builder() |
1453 | | .nan_string(options::JSON) |
1454 | | .inf_string(options::JSON) |
1455 | | .infinity_string(options::JSON) |
1456 | | .build_strict(); |
1457 | | |
1458 | | /// Number format for a `TOML` literal floating-point number. |
1459 | | #[rustfmt::skip] |
1460 | | pub const TOML: Options = Options::builder() |
1461 | | .nan_string(options::TOML) |
1462 | | .inf_string(options::TOML) |
1463 | | .infinity_string(options::TOML) |
1464 | | .build_strict(); |
1465 | | |
1466 | | /// Number format for a `YAML` literal floating-point number. |
1467 | | #[rustfmt::skip] |
1468 | | pub const YAML: Options = JSON; |
1469 | | |
1470 | | /// Number format for an `XML` literal floating-point number. |
1471 | | #[rustfmt::skip] |
1472 | | pub const XML: Options = Options::builder() |
1473 | | .inf_string(options::XML_INF) |
1474 | | .infinity_string(options::XML_INFINITY) |
1475 | | .build_strict(); |
1476 | | |
1477 | | /// Number format for a `SQLite` literal floating-point number. |
1478 | | #[rustfmt::skip] |
1479 | | pub const SQLITE: Options = Options::builder() |
1480 | | .nan_string(options::SQLITE) |
1481 | | .inf_string(options::SQLITE) |
1482 | | .infinity_string(options::SQLITE) |
1483 | | .build_strict(); |
1484 | | |
1485 | | /// Number format for a `PostgreSQL` literal floating-point number. |
1486 | | #[rustfmt::skip] |
1487 | | pub const POSTGRESQL: Options = Options::builder() |
1488 | | .nan_string(options::POSTGRESQL) |
1489 | | .inf_string(options::POSTGRESQL) |
1490 | | .infinity_string(options::POSTGRESQL) |
1491 | | .build_strict(); |
1492 | | |
1493 | | /// Number format for a `MySQL` literal floating-point number. |
1494 | | #[rustfmt::skip] |
1495 | | pub const MYSQL: Options = Options::builder() |
1496 | | .nan_string(options::MYSQL) |
1497 | | .inf_string(options::MYSQL) |
1498 | | .infinity_string(options::MYSQL) |
1499 | | .build_strict(); |
1500 | | |
1501 | | /// Number format for a `MongoDB` literal floating-point number. |
1502 | | #[rustfmt::skip] |
1503 | | pub const MONGODB: Options = Options::builder() |
1504 | | .inf_string(options::MONGODB_INF) |
1505 | | .infinity_string(options::MONGODB_INFINITY) |
1506 | | .build_strict(); |