lexical_parse_float/
options.rs

1//! Configuration options for parsing floats.
2
3use lexical_util::ascii::{is_valid_ascii, is_valid_letter_slice};
4use lexical_util::error::Error;
5use lexical_util::options::{self, ParseOptions};
6use lexical_util::result::Result;
7use static_assertions::const_assert;
8
9/// Maximum length for a special string.
10const MAX_SPECIAL_STRING_LENGTH: usize = 50;
11
12/// Builder for `Options`.
13#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
14pub struct OptionsBuilder {
15    /// Disable the use of arbitrary-precision arithmetic, and always
16    /// return the results from the fast or intermediate path algorithms.
17    lossy: bool,
18    /// Character to designate the exponent component of a float.
19    exponent: u8,
20    /// Character to separate the integer from the fraction components.
21    decimal_point: u8,
22    /// String representation of Not A Number, aka `NaN`.
23    nan_string: Option<&'static [u8]>,
24    /// Short string representation of `Infinity`.
25    inf_string: Option<&'static [u8]>,
26    /// Long string representation of `Infinity`.
27    infinity_string: Option<&'static [u8]>,
28}
29
30impl OptionsBuilder {
31    /// Create new options builder with default options.
32    #[inline(always)]
33    pub const fn new() -> Self {
34        Self {
35            lossy: false,
36            exponent: b'e',
37            decimal_point: b'.',
38            nan_string: Some(b"NaN"),
39            inf_string: Some(b"inf"),
40            infinity_string: Some(b"infinity"),
41        }
42    }
43
44    // GETTERS
45
46    /// Get if we disable the use of arbitrary-precision arithmetic.
47    #[inline(always)]
48    pub const fn get_lossy(&self) -> bool {
49        self.lossy
50    }
51
52    /// Get the character to designate the exponent component of a float.
53    #[inline(always)]
54    pub const fn get_exponent(&self) -> u8 {
55        self.exponent
56    }
57
58    /// Get the character to separate the integer from the fraction components.
59    #[inline(always)]
60    pub const fn get_decimal_point(&self) -> u8 {
61        self.decimal_point
62    }
63
64    /// Get the string representation for `NaN`.
65    #[inline(always)]
66    pub const fn get_nan_string(&self) -> Option<&'static [u8]> {
67        self.nan_string
68    }
69
70    /// Get the short string representation for `Infinity`.
71    #[inline(always)]
72    pub const fn get_inf_string(&self) -> Option<&'static [u8]> {
73        self.inf_string
74    }
75
76    /// Get the long string representation for `Infinity`.
77    #[inline(always)]
78    pub const fn get_infinity_string(&self) -> Option<&'static [u8]> {
79        self.infinity_string
80    }
81
82    // SETTERS
83
84    /// Set if we disable the use of arbitrary-precision arithmetic.
85    #[inline(always)]
86    pub const fn lossy(mut self, lossy: bool) -> Self {
87        self.lossy = lossy;
88        self
89    }
90
91    /// Set the character to designate the exponent component of a float.
92    #[inline(always)]
93    pub const fn exponent(mut self, exponent: u8) -> Self {
94        self.exponent = exponent;
95        self
96    }
97
98    /// Set the character to separate the integer from the fraction components.
99    #[inline(always)]
100    pub const fn decimal_point(mut self, decimal_point: u8) -> Self {
101        self.decimal_point = decimal_point;
102        self
103    }
104
105    /// Set the string representation for `NaN`.
106    #[inline(always)]
107    pub const fn nan_string(mut self, nan_string: Option<&'static [u8]>) -> Self {
108        self.nan_string = nan_string;
109        self
110    }
111
112    /// Set the short string representation for `Infinity`.
113    #[inline(always)]
114    pub const fn inf_string(mut self, inf_string: Option<&'static [u8]>) -> Self {
115        self.inf_string = inf_string;
116        self
117    }
118
119    /// Set the long string representation for `Infinity`.
120    #[inline(always)]
121    pub const fn infinity_string(mut self, infinity_string: Option<&'static [u8]>) -> Self {
122        self.infinity_string = infinity_string;
123        self
124    }
125
126    // BUILDERS
127
128    /// Determine if `nan_str` is valid.
129    #[inline(always)]
130    #[allow(clippy::if_same_then_else, clippy::needless_bool)]
131    pub const fn nan_str_is_valid(&self) -> bool {
132        if self.nan_string.is_none() {
133            return true;
134        }
135
136        let nan = unwrap_str(self.nan_string);
137        let length = nan.len();
138        if length == 0 || length > MAX_SPECIAL_STRING_LENGTH {
139            false
140        } else if !matches!(nan[0], b'N' | b'n') {
141            false
142        } else if !is_valid_letter_slice(nan) {
143            false
144        } else {
145            true
146        }
147    }
148
149    /// Determine if `inf_str` is valid.
150    #[inline(always)]
151    #[allow(clippy::if_same_then_else, clippy::needless_bool)]
152    pub const fn inf_str_is_valid(&self) -> bool {
153        if self.infinity_string.is_none() && self.inf_string.is_some() {
154            return false;
155        } else if self.inf_string.is_none() {
156            return true;
157        }
158
159        let inf = unwrap_str(self.inf_string);
160        let length = inf.len();
161        let infinity = unwrap_str(self.infinity_string);
162        if length == 0 || length > MAX_SPECIAL_STRING_LENGTH {
163            false
164        } else if !matches!(inf[0], b'I' | b'i') {
165            false
166        } else if length > infinity.len() {
167            false
168        } else if !is_valid_letter_slice(inf) {
169            false
170        } else {
171            true
172        }
173    }
174
175    /// Determine if `infinity_string` is valid.
176    #[inline(always)]
177    #[allow(clippy::if_same_then_else, clippy::needless_bool)]
178    pub const fn infinity_string_is_valid(&self) -> bool {
179        if self.infinity_string.is_none() && self.inf_string.is_some() {
180            return false;
181        } else if self.infinity_string.is_none() {
182            return true;
183        }
184        let inf = unwrap_str(self.inf_string);
185        let infinity = unwrap_str(self.infinity_string);
186        let length = infinity.len();
187        if length == 0 || length > MAX_SPECIAL_STRING_LENGTH {
188            false
189        } else if !matches!(infinity[0], b'I' | b'i') {
190            false
191        } else if length < inf.len() {
192            false
193        } else if !is_valid_letter_slice(infinity) {
194            false
195        } else {
196            true
197        }
198    }
199
200    /// Check if the builder state is valid.
201    #[inline(always)]
202    #[allow(clippy::if_same_then_else, clippy::needless_bool)]
203    pub const fn is_valid(&self) -> bool {
204        if !is_valid_ascii(self.exponent) {
205            false
206        } else if !is_valid_ascii(self.decimal_point) {
207            false
208        } else if !self.nan_str_is_valid() {
209            false
210        } else if !self.inf_str_is_valid() {
211            false
212        } else if !self.infinity_string_is_valid() {
213            false
214        } else {
215            true
216        }
217    }
218
219    /// Build the Options struct without validation.
220    ///
221    /// # Safety
222    ///
223    /// Always safe, just marked as unsafe for API compatibility.
224    /// The result may be invalid if `is_valid` is not true.
225    #[inline(always)]
226    pub const unsafe fn build_unchecked(&self) -> Options {
227        Options {
228            lossy: self.lossy,
229            exponent: self.exponent,
230            decimal_point: self.decimal_point,
231            nan_string: self.nan_string,
232            inf_string: self.inf_string,
233            infinity_string: self.infinity_string,
234        }
235    }
236
237    /// Build the Options struct.
238    #[inline(always)]
239    #[allow(clippy::if_same_then_else)]
240    pub const fn build(&self) -> Result<Options> {
241        if !is_valid_ascii(self.exponent) {
242            return Err(Error::InvalidExponentSymbol);
243        } else if !is_valid_ascii(self.decimal_point) {
244            return Err(Error::InvalidDecimalPoint);
245        }
246
247        if self.nan_string.is_some() {
248            let nan = unwrap_str(self.nan_string);
249            if nan.is_empty() || !matches!(nan[0], b'N' | b'n') {
250                return Err(Error::InvalidNanString);
251            } else if !is_valid_letter_slice(nan) {
252                return Err(Error::InvalidNanString);
253            } else if nan.len() > MAX_SPECIAL_STRING_LENGTH {
254                return Err(Error::NanStringTooLong);
255            }
256        }
257
258        if self.inf_string.is_some() && self.infinity_string.is_none() {
259            return Err(Error::InfinityStringTooShort);
260        }
261
262        if self.inf_string.is_some() {
263            let inf = unwrap_str(self.inf_string);
264            if inf.is_empty() || !matches!(inf[0], b'I' | b'i') {
265                return Err(Error::InvalidInfString);
266            } else if !is_valid_letter_slice(inf) {
267                return Err(Error::InvalidInfString);
268            } else if inf.len() > MAX_SPECIAL_STRING_LENGTH {
269                return Err(Error::InfStringTooLong);
270            }
271        }
272
273        if self.infinity_string.is_some() {
274            let inf = unwrap_str(self.inf_string);
275            let infinity = unwrap_str(self.infinity_string);
276            if infinity.is_empty() || !matches!(infinity[0], b'I' | b'i') {
277                return Err(Error::InvalidInfinityString);
278            } else if !is_valid_letter_slice(infinity) {
279                return Err(Error::InvalidInfinityString);
280            } else if infinity.len() > MAX_SPECIAL_STRING_LENGTH {
281                return Err(Error::InfinityStringTooLong);
282            } else if infinity.len() < inf.len() {
283                return Err(Error::InfinityStringTooShort);
284            }
285        }
286
287        // SAFETY: always safe, since it must be valid.
288        Ok(unsafe { self.build_unchecked() })
289    }
290}
291
292impl Default for OptionsBuilder {
293    #[inline(always)]
294    fn default() -> Self {
295        Self::new()
296    }
297}
298
299/// Options to customize parsing floats.
300///
301/// # Examples
302///
303/// ```rust
304/// use lexical_parse_float::Options;
305///
306/// # pub fn main() {
307/// let options = Options::builder()
308///     .lossy(true)
309///     .nan_string(Some(b"NaN"))
310///     .inf_string(Some(b"Inf"))
311///     .infinity_string(Some(b"Infinity"))
312///     .build()
313///     .unwrap();
314/// # }
315/// ```
316#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
317pub struct Options {
318    /// Disable the use of arbitrary-precision arithmetic, and always
319    /// return the results from the fast or intermediate path algorithms.
320    lossy: bool,
321    /// Character to designate the exponent component of a float.
322    exponent: u8,
323    /// Character to separate the integer from the fraction components.
324    decimal_point: u8,
325    /// String representation of Not A Number, aka `NaN`.
326    nan_string: Option<&'static [u8]>,
327    /// Short string representation of `Infinity`.
328    inf_string: Option<&'static [u8]>,
329    /// Long string representation of `Infinity`.
330    infinity_string: Option<&'static [u8]>,
331}
332
333impl Options {
334    // CONSTRUCTORS
335
336    /// Create options with default values.
337    #[inline(always)]
338    pub const fn new() -> Self {
339        // SAFETY: always safe since it uses the default arguments.
340        unsafe { Self::builder().build_unchecked() }
341    }
342
343    /// Create the default options for a given radix.
344    #[inline(always)]
345    #[cfg(feature = "power-of-two")]
346    pub const fn from_radix(radix: u8) -> Self {
347        // Need to determine the correct exponent character ('e' or '^'),
348        // since the default character is `e` normally, but this is a valid
349        // digit for radix >= 15.
350        let mut builder = Self::builder();
351        if radix >= 15 {
352            builder = builder.exponent(b'^');
353        }
354        // SAFETY: always safe since it uses the default arguments.
355        unsafe { builder.build_unchecked() }
356    }
357
358    // GETTERS
359
360    /// Check if the options state is valid.
361    #[inline(always)]
362    pub const fn is_valid(&self) -> bool {
363        self.rebuild().is_valid()
364    }
365
366    /// Get if we disable the use of arbitrary-precision arithmetic.
367    #[inline(always)]
368    pub const fn lossy(&self) -> bool {
369        self.lossy
370    }
371
372    /// Get the character to designate the exponent component of a float.
373    #[inline(always)]
374    pub const fn exponent(&self) -> u8 {
375        self.exponent
376    }
377
378    /// Get the character to separate the integer from the fraction components.
379    #[inline(always)]
380    pub const fn decimal_point(&self) -> u8 {
381        self.decimal_point
382    }
383
384    /// Get the string representation for `NaN`.
385    #[inline(always)]
386    pub const fn nan_string(&self) -> Option<&'static [u8]> {
387        self.nan_string
388    }
389
390    /// Get the short string representation for `Infinity`.
391    #[inline(always)]
392    pub const fn inf_string(&self) -> Option<&'static [u8]> {
393        self.inf_string
394    }
395
396    /// Get the long string representation for `Infinity`.
397    #[inline(always)]
398    pub const fn infinity_string(&self) -> Option<&'static [u8]> {
399        self.infinity_string
400    }
401
402    // SETTERS
403
404    /// Set if we disable the use of arbitrary-precision arithmetic.
405    ///
406    /// # Safety
407    ///
408    /// Always safe, just marked as unsafe for API compatibility.
409    #[inline(always)]
410    pub unsafe fn set_lossy(&mut self, lossy: bool) {
411        self.lossy = lossy
412    }
413
414    /// Set the character to designate the exponent component of a float.
415    ///
416    /// # Safety
417    ///
418    /// Always safe, but may produce invalid output if the exponent
419    /// is not a valid ASCII character.
420    #[inline(always)]
421    pub unsafe fn set_exponent(&mut self, exponent: u8) {
422        self.exponent = exponent;
423    }
424
425    /// Set the character to separate the integer from the fraction components.
426    ///
427    /// # Safety
428    ///
429    /// Always safe, but may produce invalid output if the decimal point
430    /// is not a valid ASCII character.
431    #[inline(always)]
432    pub unsafe fn set_decimal_point(&mut self, decimal_point: u8) {
433        self.decimal_point = decimal_point;
434    }
435
436    /// Set the string representation for `NaN`.
437    /// Unsafe, use the builder API for option validation.
438    ///
439    /// # Safety
440    ///
441    /// Always safe, just marked as unsafe for API compatibility.
442    #[inline(always)]
443    pub unsafe fn set_nan_string(&mut self, nan_string: Option<&'static [u8]>) {
444        self.nan_string = nan_string
445    }
446
447    /// Set the short string representation for `Infinity`
448    /// Unsafe, use the builder API for option validation.
449    ///
450    /// # Safety
451    ///
452    /// Always safe, just marked as unsafe for API compatibility.
453    #[inline(always)]
454    pub unsafe fn set_inf_string(&mut self, inf_string: Option<&'static [u8]>) {
455        self.inf_string = inf_string
456    }
457
458    /// Set the long string representation for `Infinity`
459    /// Unsafe, use the builder API for option validation.
460    ///
461    /// # Safety
462    ///
463    /// Always safe, just marked as unsafe for API compatibility.
464    #[inline(always)]
465    pub unsafe fn set_infinity_string(&mut self, infinity_string: Option<&'static [u8]>) {
466        self.infinity_string = infinity_string
467    }
468
469    // BUILDERS
470
471    /// Get OptionsBuilder as a static function.
472    #[inline(always)]
473    pub const fn builder() -> OptionsBuilder {
474        OptionsBuilder::new()
475    }
476
477    /// Create OptionsBuilder using existing values.
478    #[inline(always)]
479    pub const fn rebuild(&self) -> OptionsBuilder {
480        OptionsBuilder {
481            lossy: self.lossy,
482            exponent: self.exponent,
483            decimal_point: self.decimal_point,
484            nan_string: self.nan_string,
485            inf_string: self.inf_string,
486            infinity_string: self.infinity_string,
487        }
488    }
489}
490
491impl Default for Options {
492    #[inline(always)]
493    fn default() -> Self {
494        Self::new()
495    }
496}
497
498impl ParseOptions for Options {
499    #[inline(always)]
500    fn is_valid(&self) -> bool {
501        Self::is_valid(self)
502    }
503}
504
505/// Unwrap `Option` as a const fn.
506#[inline(always)]
507const fn unwrap_str(option: Option<&'static [u8]>) -> &'static [u8] {
508    match option {
509        Some(x) => x,
510        None => &[],
511    }
512}
513
514// PRE-DEFINED CONSTANTS
515// ---------------------
516
517// Only constants that differ from the standard version are included.
518// SAFETY: all of these are safe, since they are checked to be valid
519// after calling `build_unchecked`. Furthermore, even though the methods
520// are marked as `unsafe`, none of the produced options can cause memory
521// safety issues.
522
523/// Standard number format.
524#[rustfmt::skip]
525pub const STANDARD: Options = Options::new();
526const_assert!(STANDARD.is_valid());
527
528/// Numerical format with a decimal comma.
529/// This is the standard numerical format for most of the world.
530#[rustfmt::skip]
531pub const DECIMAL_COMMA: Options = unsafe {
532    Options::builder()
533        .decimal_point(b',')
534        .build_unchecked()
535};
536const_assert!(DECIMAL_COMMA.is_valid());
537
538/// Numerical format for hexadecimal floats, which use a `p` exponent.
539#[rustfmt::skip]
540pub const HEX_FLOAT: Options = unsafe {
541    Options::builder()
542        .exponent(b'p')
543        .build_unchecked()
544};
545const_assert!(HEX_FLOAT.is_valid());
546
547/// Numerical format where `^` is used as the exponent notation character.
548/// This isn't very common, but is useful when `e` or `p` are valid digits.
549#[rustfmt::skip]
550pub const CARAT_EXPONENT: Options = unsafe {
551    Options::builder()
552        .exponent(b'^')
553        .build_unchecked()
554};
555const_assert!(CARAT_EXPONENT.is_valid());
556
557/// Number format for a Rust literal floating-point number.
558#[rustfmt::skip]
559pub const RUST_LITERAL: Options = unsafe {
560    Options::builder()
561        .nan_string(options::RUST_LITERAL)
562        .inf_string(options::RUST_LITERAL)
563        .infinity_string(options::RUST_LITERAL)
564        .build_unchecked()
565};
566const_assert!(RUST_LITERAL.is_valid());
567
568/// Number format for a Python literal floating-point number.
569#[rustfmt::skip]
570pub const PYTHON_LITERAL: Options = unsafe {
571    Options::builder()
572        .nan_string(options::PYTHON_LITERAL)
573        .inf_string(options::PYTHON_LITERAL)
574        .infinity_string(options::PYTHON_LITERAL)
575        .build_unchecked()
576};
577const_assert!(PYTHON_LITERAL.is_valid());
578
579/// Number format for a C++ literal floating-point number.
580#[rustfmt::skip]
581pub const CXX_LITERAL: Options = unsafe {
582    Options::builder()
583        .nan_string(options::CXX_LITERAL_NAN)
584        .inf_string(options::CXX_LITERAL_INF)
585        .infinity_string(options::CXX_LITERAL_INFINITY)
586        .build_unchecked()
587};
588const_assert!(CXX_LITERAL.is_valid());
589
590/// Number format for a C literal floating-point number.
591#[rustfmt::skip]
592pub const C_LITERAL: Options = unsafe {
593    Options::builder()
594        .nan_string(options::C_LITERAL_NAN)
595        .inf_string(options::C_LITERAL_INF)
596        .infinity_string(options::C_LITERAL_INFINITY)
597        .build_unchecked()
598};
599const_assert!(CXX_LITERAL.is_valid());
600
601/// Number format for a Ruby literal floating-point number.
602#[rustfmt::skip]
603pub const RUBY_LITERAL: Options = unsafe {
604    Options::builder()
605        .nan_string(options::RUBY)
606        .inf_string(options::RUBY)
607        .infinity_string(options::RUBY)
608        .build_unchecked()
609};
610const_assert!(RUBY_LITERAL.is_valid());
611
612/// Number format to parse a Ruby float from string.
613#[rustfmt::skip]
614pub const RUBY_STRING: Options = unsafe {
615    Options::builder()
616        .nan_string(options::RUBY)
617        .inf_string(options::RUBY)
618        .infinity_string(options::RUBY)
619        .build_unchecked()
620};
621const_assert!(RUBY_STRING.is_valid());
622
623/// Number format for a Swift literal floating-point number.
624#[rustfmt::skip]
625pub const SWIFT_LITERAL: Options = unsafe {
626    Options::builder()
627        .nan_string(options::SWIFT_LITERAL)
628        .inf_string(options::SWIFT_LITERAL)
629        .infinity_string(options::SWIFT_LITERAL)
630        .build_unchecked()
631};
632const_assert!(SWIFT_LITERAL.is_valid());
633
634/// Number format for a Go literal floating-point number.
635#[rustfmt::skip]
636pub const GO_LITERAL: Options = unsafe {
637    Options::builder()
638        .nan_string(options::GO_LITERAL)
639        .inf_string(options::GO_LITERAL)
640        .infinity_string(options::GO_LITERAL)
641        .build_unchecked()
642};
643const_assert!(GO_LITERAL.is_valid());
644
645/// Number format for a Haskell literal floating-point number.
646#[rustfmt::skip]
647pub const HASKELL_LITERAL: Options = unsafe {
648    Options::builder()
649        .nan_string(options::HASKELL_LITERAL)
650        .inf_string(options::HASKELL_LITERAL)
651        .infinity_string(options::HASKELL_LITERAL)
652        .build_unchecked()
653};
654const_assert!(HASKELL_LITERAL.is_valid());
655
656/// Number format to parse a Haskell float from string.
657#[rustfmt::skip]
658pub const HASKELL_STRING: Options = unsafe {
659    Options::builder()
660        .inf_string(options::HASKELL_STRING_INF)
661        .infinity_string(options::HASKELL_STRING_INFINITY)
662        .build_unchecked()
663};
664const_assert!(HASKELL_STRING.is_valid());
665
666/// Number format for a Javascript literal floating-point number.
667#[rustfmt::skip]
668pub const JAVASCRIPT_LITERAL: Options = unsafe {
669    Options::builder()
670        .inf_string(options::JAVASCRIPT_INF)
671        .infinity_string(options::JAVASCRIPT_INFINITY)
672        .build_unchecked()
673};
674const_assert!(JAVASCRIPT_LITERAL.is_valid());
675
676/// Number format to parse a Javascript float from string.
677#[rustfmt::skip]
678pub const JAVASCRIPT_STRING: Options = unsafe {
679    Options::builder()
680        .inf_string(options::JAVASCRIPT_INF)
681        .infinity_string(options::JAVASCRIPT_INFINITY)
682        .build_unchecked()
683};
684const_assert!(JAVASCRIPT_STRING.is_valid());
685
686/// Number format for a Perl literal floating-point number.
687#[rustfmt::skip]
688pub const PERL_LITERAL: Options = unsafe {
689    Options::builder()
690        .nan_string(options::PERL_LITERAL)
691        .inf_string(options::PERL_LITERAL)
692        .infinity_string(options::PERL_LITERAL)
693        .build_unchecked()
694};
695const_assert!(PERL_LITERAL.is_valid());
696
697/// Number format for a PHP literal floating-point number.
698#[rustfmt::skip]
699pub const PHP_LITERAL: Options = unsafe {
700    Options::builder()
701        .nan_string(options::PHP_LITERAL_NAN)
702        .inf_string(options::PHP_LITERAL_INF)
703        .infinity_string(options::PHP_LITERAL_INFINITY)
704        .build_unchecked()
705};
706const_assert!(PHP_LITERAL.is_valid());
707
708/// Number format for a Java literal floating-point number.
709#[rustfmt::skip]
710pub const JAVA_LITERAL: Options = unsafe {
711    Options::builder()
712        .nan_string(options::JAVA_LITERAL)
713        .inf_string(options::JAVA_LITERAL)
714        .infinity_string(options::JAVA_LITERAL)
715        .build_unchecked()
716};
717const_assert!(JAVA_LITERAL.is_valid());
718
719/// Number format to parse a Java float from string.
720#[rustfmt::skip]
721pub const JAVA_STRING: Options = unsafe {
722    Options::builder()
723        .inf_string(options::JAVA_STRING_INF)
724        .infinity_string(options::JAVA_STRING_INFINITY)
725        .build_unchecked()
726};
727const_assert!(JAVA_STRING.is_valid());
728
729/// Number format for an R literal floating-point number.
730#[rustfmt::skip]
731pub const R_LITERAL: Options = unsafe {
732    Options::builder()
733        .inf_string(options::R_LITERAL_INF)
734        .infinity_string(options::R_LITERAL_INFINITY)
735        .build_unchecked()
736};
737const_assert!(R_LITERAL.is_valid());
738
739/// Number format for a Kotlin literal floating-point number.
740#[rustfmt::skip]
741pub const KOTLIN_LITERAL: Options = unsafe {
742    Options::builder()
743        .nan_string(options::KOTLIN_LITERAL)
744        .inf_string(options::KOTLIN_LITERAL)
745        .infinity_string(options::KOTLIN_LITERAL)
746        .build_unchecked()
747};
748const_assert!(KOTLIN_LITERAL.is_valid());
749
750/// Number format to parse a Kotlin float from string.
751#[rustfmt::skip]
752pub const KOTLIN_STRING: Options = unsafe {
753    Options::builder()
754        .inf_string(options::KOTLIN_STRING_INF)
755        .infinity_string(options::KOTLIN_STRING_INFINITY)
756        .build_unchecked()
757};
758const_assert!(KOTLIN_STRING.is_valid());
759
760/// Number format for a Julia literal floating-point number.
761#[rustfmt::skip]
762pub const JULIA_LITERAL: Options = unsafe {
763    Options::builder()
764        .inf_string(options::JULIA_LITERAL_INF)
765        .infinity_string(options::JULIA_LITERAL_INFINITY)
766        .build_unchecked()
767};
768const_assert!(JULIA_LITERAL.is_valid());
769
770/// Number format for a C# literal floating-point number.
771#[rustfmt::skip]
772pub const CSHARP_LITERAL: Options = unsafe {
773    Options::builder()
774        .nan_string(options::CSHARP_LITERAL)
775        .inf_string(options::CSHARP_LITERAL)
776        .infinity_string(options::CSHARP_LITERAL)
777        .build_unchecked()
778};
779const_assert!(CSHARP_LITERAL.is_valid());
780
781/// Number format to parse a C# float from string.
782#[rustfmt::skip]
783pub const CSHARP_STRING: Options = unsafe {
784    Options::builder()
785        .inf_string(options::CSHARP_STRING_INF)
786        .infinity_string(options::CSHARP_STRING_INFINITY)
787        .build_unchecked()
788};
789const_assert!(CSHARP_STRING.is_valid());
790
791/// Number format for a Kawa literal floating-point number.
792#[rustfmt::skip]
793pub const KAWA_LITERAL: Options = unsafe {
794    Options::builder()
795        .nan_string(options::KAWA)
796        .inf_string(options::KAWA)
797        .infinity_string(options::KAWA)
798        .build_unchecked()
799};
800const_assert!(KAWA_LITERAL.is_valid());
801
802/// Number format to parse a Kawa float from string.
803#[rustfmt::skip]
804pub const KAWA_STRING: Options = unsafe {
805    Options::builder()
806        .nan_string(options::KAWA)
807        .inf_string(options::KAWA)
808        .infinity_string(options::KAWA)
809        .build_unchecked()
810};
811const_assert!(KAWA_STRING.is_valid());
812
813/// Number format for a Gambit-C literal floating-point number.
814#[rustfmt::skip]
815pub const GAMBITC_LITERAL: Options = unsafe {
816    Options::builder()
817        .nan_string(options::GAMBITC)
818        .inf_string(options::GAMBITC)
819        .infinity_string(options::GAMBITC)
820        .build_unchecked()
821};
822const_assert!(GAMBITC_LITERAL.is_valid());
823
824/// Number format to parse a Gambit-C float from string.
825#[rustfmt::skip]
826pub const GAMBITC_STRING: Options = unsafe {
827    Options::builder()
828        .nan_string(options::GAMBITC)
829        .inf_string(options::GAMBITC)
830        .infinity_string(options::GAMBITC)
831        .build_unchecked()
832};
833const_assert!(GAMBITC_STRING.is_valid());
834
835/// Number format for a Guile literal floating-point number.
836#[rustfmt::skip]
837pub const GUILE_LITERAL: Options = unsafe {
838    Options::builder()
839        .nan_string(options::GUILE)
840        .inf_string(options::GUILE)
841        .infinity_string(options::GUILE)
842        .build_unchecked()
843};
844const_assert!(GUILE_LITERAL.is_valid());
845
846/// Number format to parse a Guile float from string.
847#[rustfmt::skip]
848pub const GUILE_STRING: Options = unsafe {
849    Options::builder()
850        .nan_string(options::GUILE)
851        .inf_string(options::GUILE)
852        .infinity_string(options::GUILE)
853        .build_unchecked()
854};
855const_assert!(GUILE_STRING.is_valid());
856
857/// Number format for a Clojure literal floating-point number.
858#[rustfmt::skip]
859pub const CLOJURE_LITERAL: Options = unsafe {
860    Options::builder()
861        .nan_string(options::CLOJURE_LITERAL)
862        .inf_string(options::CLOJURE_LITERAL)
863        .infinity_string(options::CLOJURE_LITERAL)
864        .build_unchecked()
865};
866const_assert!(CLOJURE_LITERAL.is_valid());
867
868/// Number format to parse a Clojure float from string.
869#[rustfmt::skip]
870pub const CLOJURE_STRING: Options = unsafe {
871    Options::builder()
872        .inf_string(options::CLOJURE_STRING_INF)
873        .infinity_string(options::CLOJURE_STRING_INFINITY)
874        .build_unchecked()
875};
876const_assert!(CLOJURE_STRING.is_valid());
877
878/// Number format for an Erlang literal floating-point number.
879#[rustfmt::skip]
880pub const ERLANG_LITERAL: Options = unsafe {
881    Options::builder()
882        .nan_string(options::ERLANG_LITERAL_NAN)
883        .build_unchecked()
884};
885const_assert!(ERLANG_LITERAL.is_valid());
886
887/// Number format to parse an Erlang float from string.
888#[rustfmt::skip]
889pub const ERLANG_STRING: Options = unsafe {
890    Options::builder()
891        .nan_string(options::ERLANG_STRING)
892        .inf_string(options::ERLANG_STRING)
893        .infinity_string(options::ERLANG_STRING)
894        .build_unchecked()
895};
896const_assert!(ERLANG_STRING.is_valid());
897
898/// Number format for an Elm literal floating-point number.
899#[rustfmt::skip]
900pub const ELM_LITERAL: Options = unsafe {
901    Options::builder()
902        .nan_string(options::ELM_LITERAL)
903        .inf_string(options::ELM_LITERAL)
904        .infinity_string(options::ELM_LITERAL)
905        .build_unchecked()
906};
907const_assert!(ELM_LITERAL.is_valid());
908
909/// Number format to parse an Elm float from string.
910#[rustfmt::skip]
911pub const ELM_STRING: Options = unsafe {
912    Options::builder()
913        .nan_string(options::ELM_STRING_NAN)
914        .inf_string(options::ELM_STRING_INF)
915        .infinity_string(options::ELM_STRING_INFINITY)
916        .build_unchecked()
917};
918const_assert!(ELM_STRING.is_valid());
919
920/// Number format for a Scala literal floating-point number.
921#[rustfmt::skip]
922pub const SCALA_LITERAL: Options = unsafe {
923    Options::builder()
924        .nan_string(options::SCALA_LITERAL)
925        .inf_string(options::SCALA_LITERAL)
926        .infinity_string(options::SCALA_LITERAL)
927        .build_unchecked()
928};
929const_assert!(SCALA_LITERAL.is_valid());
930
931/// Number format to parse a Scala float from string.
932#[rustfmt::skip]
933pub const SCALA_STRING: Options = unsafe {
934    Options::builder()
935        .inf_string(options::SCALA_STRING_INF)
936        .infinity_string(options::SCALA_STRING_INFINITY)
937        .build_unchecked()
938};
939const_assert!(SCALA_STRING.is_valid());
940
941/// Number format for an Elixir literal floating-point number.
942#[rustfmt::skip]
943pub const ELIXIR_LITERAL: Options = unsafe {
944    Options::builder()
945        .nan_string(options::ELIXIR)
946        .inf_string(options::ELIXIR)
947        .infinity_string(options::ELIXIR)
948        .build_unchecked()
949};
950const_assert!(ELIXIR_LITERAL.is_valid());
951
952/// Number format to parse an Elixir float from string.
953#[rustfmt::skip]
954pub const ELIXIR_STRING: Options = unsafe {
955    Options::builder()
956        .nan_string(options::ELIXIR)
957        .inf_string(options::ELIXIR)
958        .infinity_string(options::ELIXIR)
959        .build_unchecked()
960};
961const_assert!(ELIXIR_STRING.is_valid());
962
963/// Number format for a FORTRAN literal floating-point number.
964#[rustfmt::skip]
965pub const FORTRAN_LITERAL: Options = unsafe {
966    Options::builder()
967        .nan_string(options::FORTRAN_LITERAL)
968        .inf_string(options::FORTRAN_LITERAL)
969        .infinity_string(options::FORTRAN_LITERAL)
970        .build_unchecked()
971};
972const_assert!(FORTRAN_LITERAL.is_valid());
973
974/// Number format for a D literal floating-point number.
975#[rustfmt::skip]
976pub const D_LITERAL: Options = unsafe {
977    Options::builder()
978        .nan_string(options::D_LITERAL)
979        .inf_string(options::D_LITERAL)
980        .infinity_string(options::D_LITERAL)
981        .build_unchecked()
982};
983const_assert!(D_LITERAL.is_valid());
984
985/// Number format for a Coffeescript literal floating-point number.
986#[rustfmt::skip]
987pub const COFFEESCRIPT_LITERAL: Options = unsafe {
988    Options::builder()
989        .inf_string(options::COFFEESCRIPT_INF)
990        .infinity_string(options::COFFEESCRIPT_INFINITY)
991        .build_unchecked()
992};
993const_assert!(COFFEESCRIPT_LITERAL.is_valid());
994
995/// Number format to parse a Coffeescript float from string.
996#[rustfmt::skip]
997pub const COFFEESCRIPT_STRING: Options = unsafe {
998    Options::builder()
999        .inf_string(options::COFFEESCRIPT_INF)
1000        .infinity_string(options::COFFEESCRIPT_INFINITY)
1001        .build_unchecked()
1002};
1003const_assert!(COFFEESCRIPT_STRING.is_valid());
1004
1005/// Number format for a COBOL literal floating-point number.
1006#[rustfmt::skip]
1007pub const COBOL_LITERAL: Options = unsafe {
1008    Options::builder()
1009        .nan_string(options::COBOL)
1010        .inf_string(options::COBOL)
1011        .infinity_string(options::COBOL)
1012        .build_unchecked()
1013};
1014const_assert!(COBOL_LITERAL.is_valid());
1015
1016/// Number format to parse a COBOL float from string.
1017#[rustfmt::skip]
1018pub const COBOL_STRING: Options = unsafe {
1019    Options::builder()
1020        .nan_string(options::COBOL)
1021        .inf_string(options::COBOL)
1022        .infinity_string(options::COBOL)
1023        .build_unchecked()
1024};
1025const_assert!(COBOL_STRING.is_valid());
1026
1027/// Number format for an F# literal floating-point number.
1028#[rustfmt::skip]
1029pub const FSHARP_LITERAL: Options = unsafe {
1030    Options::builder()
1031        .nan_string(options::FSHARP_LITERAL_NAN)
1032        .inf_string(options::FSHARP_LITERAL_INF)
1033        .infinity_string(options::FSHARP_LITERAL_INFINITY)
1034        .build_unchecked()
1035};
1036const_assert!(FSHARP_LITERAL.is_valid());
1037
1038/// Number format for a Visual Basic literal floating-point number.
1039#[rustfmt::skip]
1040pub const VB_LITERAL: Options = unsafe {
1041    Options::builder()
1042        .nan_string(options::VB_LITERAL)
1043        .inf_string(options::VB_LITERAL)
1044        .infinity_string(options::VB_LITERAL)
1045        .build_unchecked()
1046};
1047const_assert!(VB_LITERAL.is_valid());
1048
1049/// Number format to parse a Visual Basic float from string.
1050#[rustfmt::skip]
1051pub const VB_STRING: Options = unsafe {
1052    Options::builder()
1053        .inf_string(options::VB_STRING_INF)
1054        .infinity_string(options::VB_STRING_INFINITY)
1055        .build_unchecked()
1056};
1057const_assert!(VB_STRING.is_valid());
1058
1059/// Number format for an OCaml literal floating-point number.
1060#[rustfmt::skip]
1061pub const OCAML_LITERAL: Options = unsafe {
1062    Options::builder()
1063        .nan_string(options::OCAML_LITERAL_NAN)
1064        .inf_string(options::OCAML_LITERAL_INF)
1065        .infinity_string(options::OCAML_LITERAL_INFINITY)
1066        .build_unchecked()
1067};
1068const_assert!(OCAML_LITERAL.is_valid());
1069
1070/// Number format for an Objective-C literal floating-point number.
1071#[rustfmt::skip]
1072pub const OBJECTIVEC_LITERAL: Options = unsafe {
1073    Options::builder()
1074        .nan_string(options::OBJECTIVEC)
1075        .inf_string(options::OBJECTIVEC)
1076        .infinity_string(options::OBJECTIVEC)
1077        .build_unchecked()
1078};
1079const_assert!(OBJECTIVEC_LITERAL.is_valid());
1080
1081/// Number format to parse an Objective-C float from string.
1082#[rustfmt::skip]
1083pub const OBJECTIVEC_STRING: Options = unsafe {
1084    Options::builder()
1085        .nan_string(options::OBJECTIVEC)
1086        .inf_string(options::OBJECTIVEC)
1087        .infinity_string(options::OBJECTIVEC)
1088        .build_unchecked()
1089};
1090const_assert!(OBJECTIVEC_STRING.is_valid());
1091
1092/// Number format for an ReasonML literal floating-point number.
1093#[rustfmt::skip]
1094pub const REASONML_LITERAL: Options = unsafe {
1095    Options::builder()
1096        .nan_string(options::REASONML_LITERAL_NAN)
1097        .inf_string(options::REASONML_LITERAL_INF)
1098        .infinity_string(options::REASONML_LITERAL_INFINITY)
1099        .build_unchecked()
1100};
1101const_assert!(REASONML_LITERAL.is_valid());
1102
1103/// Number format for a MATLAB literal floating-point number.
1104#[rustfmt::skip]
1105pub const MATLAB_LITERAL: Options = unsafe {
1106    Options::builder()
1107        .inf_string(options::MATLAB_LITERAL_INF)
1108        .infinity_string(options::MATLAB_LITERAL_INFINITY)
1109        .build_unchecked()
1110};
1111const_assert!(MATLAB_LITERAL.is_valid());
1112
1113/// Number format for a Zig literal floating-point number.
1114#[rustfmt::skip]
1115pub const ZIG_LITERAL: Options = unsafe {
1116    Options::builder()
1117        .nan_string(options::ZIG_LITERAL)
1118        .inf_string(options::ZIG_LITERAL)
1119        .infinity_string(options::ZIG_LITERAL)
1120        .build_unchecked()
1121};
1122const_assert!(ZIG_LITERAL.is_valid());
1123
1124/// Number format for a Safe literal floating-point number.
1125#[rustfmt::skip]
1126pub const SAGE_LITERAL: Options = unsafe {
1127    Options::builder()
1128        .inf_string(options::SAGE_LITERAL_INF)
1129        .infinity_string(options::SAGE_LITERAL_INFINITY)
1130        .build_unchecked()
1131};
1132const_assert!(SAGE_LITERAL.is_valid());
1133
1134/// Number format for a JSON literal floating-point number.
1135#[rustfmt::skip]
1136pub const JSON: Options = unsafe {
1137    Options::builder()
1138        .nan_string(options::JSON)
1139        .inf_string(options::JSON)
1140        .infinity_string(options::JSON)
1141        .build_unchecked()
1142};
1143const_assert!(JSON.is_valid());
1144
1145/// Number format for a TOML literal floating-point number.
1146#[rustfmt::skip]
1147pub const TOML: Options = unsafe {
1148    Options::builder()
1149        .nan_string(options::TOML)
1150        .inf_string(options::TOML)
1151        .infinity_string(options::TOML)
1152        .build_unchecked()
1153};
1154const_assert!(TOML.is_valid());
1155
1156/// Number format for a YAML literal floating-point number.
1157#[rustfmt::skip]
1158pub const YAML: Options = JSON;
1159
1160/// Number format for an XML literal floating-point number.
1161#[rustfmt::skip]
1162pub const XML: Options = unsafe {
1163    Options::builder()
1164        .inf_string(options::XML_INF)
1165        .infinity_string(options::XML_INFINITY)
1166        .build_unchecked()
1167};
1168const_assert!(XML.is_valid());
1169
1170/// Number format for a SQLite literal floating-point number.
1171#[rustfmt::skip]
1172pub const SQLITE: Options = unsafe {
1173    Options::builder()
1174        .nan_string(options::SQLITE)
1175        .inf_string(options::SQLITE)
1176        .infinity_string(options::SQLITE)
1177        .build_unchecked()
1178};
1179const_assert!(SQLITE.is_valid());
1180
1181/// Number format for a PostgreSQL literal floating-point number.
1182#[rustfmt::skip]
1183pub const POSTGRESQL: Options = unsafe {
1184    Options::builder()
1185        .nan_string(options::POSTGRESQL)
1186        .inf_string(options::POSTGRESQL)
1187        .infinity_string(options::POSTGRESQL)
1188        .build_unchecked()
1189};
1190const_assert!(POSTGRESQL.is_valid());
1191
1192/// Number format for a MySQL literal floating-point number.
1193#[rustfmt::skip]
1194pub const MYSQL: Options = unsafe {
1195    Options::builder()
1196        .nan_string(options::MYSQL)
1197        .inf_string(options::MYSQL)
1198        .infinity_string(options::MYSQL)
1199        .build_unchecked()
1200};
1201const_assert!(MYSQL.is_valid());
1202
1203/// Number format for a MongoDB literal floating-point number.
1204#[rustfmt::skip]
1205pub const MONGODB: Options = unsafe {
1206    Options::builder()
1207        .inf_string(options::MONGODB_INF)
1208        .infinity_string(options::MONGODB_INFINITY)
1209        .build_unchecked()
1210};
1211const_assert!(MONGODB.is_valid());