use super::config;
cfg_if! {
if #[cfg(not(feature = "format"))] {
bitflags! {
#[doc(hidden)]
#[derive(Default)]
pub struct NumberFormat: u32 {
const __NONEXHAUSTIVE = 0;
}
}
impl NumberFormat {
#[inline]
pub fn standard() -> Option<NumberFormat> {
Some(NumberFormat::default())
}
#[inline]
pub fn digit_separator(&self) -> u8 {
0
}
}
} else {
#[inline]
fn is_ascii(ch: u8) -> bool {
ch.is_ascii()
}
#[inline]
#[cfg(not(feature = "radix"))]
#[allow(unknown_lints, ellipsis_inclusive_range_patterns)]
fn is_valid_separator(ch: u8) -> bool {
match ch {
b'0' ... b'9' => false,
b'+' | b'.' | b'-' => false,
_ => (
is_ascii(ch)
&& ch != config::get_exponent_default_char()
)
}
}
#[inline]
#[cfg(feature = "radix")]
#[allow(unknown_lints, ellipsis_inclusive_range_patterns)]
fn is_valid_separator(ch: u8) -> bool {
match ch {
b'A' ... b'Z' => false,
b'a' ... b'z' => false,
b'0' ... b'9' => false,
b'+' | b'.' | b'-' => false,
_ => (
is_ascii(ch)
&& ch != config::get_exponent_default_char()
&& ch != config::get_exponent_backup_char()
)
}
}
macro_rules! digit_separator_to_flags {
($ch:expr) => {
($ch as u32) << 24
};
}
#[inline]
fn digit_separator_from_flags(flag: u32) -> u8 {
(flag >> 24) as u8
}
bitflags! {
#[derive(Default)]
pub struct NumberFormat: u32 {
#[doc(hidden)]
const FLAG_MASK = (
Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::REQUIRED_MANTISSA_SIGN.bits
| Self::NO_EXPONENT_NOTATION.bits
| Self::NO_POSITIVE_EXPONENT_SIGN.bits
| Self::REQUIRED_EXPONENT_SIGN.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::NO_SPECIAL.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::SPECIAL_DIGIT_SEPARATOR.bits
);
const INTERFACE_FLAG_MASK = (
Self::REQUIRED_DIGITS.bits
| Self::NO_EXPONENT_NOTATION.bits
| Self::NO_POSITIVE_EXPONENT_SIGN.bits
| Self::REQUIRED_EXPONENT_SIGN.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const DIGIT_SEPARATOR_FLAG_MASK = (
Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::SPECIAL_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const INTEGER_DIGIT_SEPARATOR_FLAG_MASK = (
Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
| Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits
| Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
| Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const FRACTION_DIGIT_SEPARATOR_FLAG_MASK = (
Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
| Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const EXPONENT_DIGIT_SEPARATOR_FLAG_MASK = (
Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
| Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const EXPONENT_FLAG_MASK = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_POSITIVE_EXPONENT_SIGN.bits
| Self::REQUIRED_EXPONENT_SIGN.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
| Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const REQUIRED_INTEGER_DIGITS = 0b000000000000000000000001;
#[doc(hidden)]
const REQUIRED_FRACTION_DIGITS = 0b000000000000000000000010;
#[doc(hidden)]
const REQUIRED_EXPONENT_DIGITS = 0b000000000000000000000100;
#[doc(hidden)]
const REQUIRED_DIGITS = (
Self::REQUIRED_INTEGER_DIGITS.bits
| Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
);
#[doc(hidden)]
const NO_POSITIVE_MANTISSA_SIGN = 0b000000000000000000001000;
#[doc(hidden)]
const REQUIRED_MANTISSA_SIGN = 0b000000000000000000010000;
#[doc(hidden)]
const NO_EXPONENT_NOTATION = 0b000000000000000000100000;
#[doc(hidden)]
const NO_POSITIVE_EXPONENT_SIGN = 0b000000000000000001000000;
#[doc(hidden)]
const REQUIRED_EXPONENT_SIGN = 0b000000000000000010000000;
#[doc(hidden)]
const NO_EXPONENT_WITHOUT_FRACTION = 0b000000000000000100000000;
#[doc(hidden)]
const NO_SPECIAL = 0b000000000000001000000000;
#[doc(hidden)]
const CASE_SENSITIVE_SPECIAL = 0b000000000000010000000000;
#[doc(hidden)]
const INTEGER_INTERNAL_DIGIT_SEPARATOR = 0b000000000000100000000000;
#[doc(hidden)]
const FRACTION_INTERNAL_DIGIT_SEPARATOR = 0b000000000001000000000000;
#[doc(hidden)]
const EXPONENT_INTERNAL_DIGIT_SEPARATOR = 0b000000000010000000000000;
#[doc(hidden)]
const INTERNAL_DIGIT_SEPARATOR = (
Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
| Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const INTEGER_LEADING_DIGIT_SEPARATOR = 0b000000000100000000000000;
#[doc(hidden)]
const FRACTION_LEADING_DIGIT_SEPARATOR = 0b000000001000000000000000;
#[doc(hidden)]
const EXPONENT_LEADING_DIGIT_SEPARATOR = 0b000000010000000000000000;
#[doc(hidden)]
const LEADING_DIGIT_SEPARATOR = (
Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const INTEGER_TRAILING_DIGIT_SEPARATOR = 0b000000100000000000000000;
#[doc(hidden)]
const FRACTION_TRAILING_DIGIT_SEPARATOR = 0b000001000000000000000000;
#[doc(hidden)]
const EXPONENT_TRAILING_DIGIT_SEPARATOR = 0b000010000000000000000000;
#[doc(hidden)]
const TRAILING_DIGIT_SEPARATOR = (
Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
| Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
);
#[doc(hidden)]
const INTEGER_CONSECUTIVE_DIGIT_SEPARATOR = 0b000100000000000000000000;
#[doc(hidden)]
const FRACTION_CONSECUTIVE_DIGIT_SEPARATOR = 0b001000000000000000000000;
#[doc(hidden)]
const EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR = 0b010000000000000000000000;
#[doc(hidden)]
const SPECIAL_DIGIT_SEPARATOR = 0b100000000000000000000000;
#[doc(hidden)]
const CONSECUTIVE_DIGIT_SEPARATOR = (
Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const RUST_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const RUST_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const RUST_STRING_STRICT = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const PYTHON_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const PYTHON_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CXX17_LITERAL = (
digit_separator_to_flags!(b'\'')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const CXX17_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CXX14_LITERAL = (
digit_separator_to_flags!(b'\'')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const CXX14_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CXX11_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CXX11_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CXX03_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CXX03_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CXX98_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CXX98_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const C18_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const C18_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const C11_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const C11_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const C99_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const C99_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const C90_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const C90_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const C89_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const C89_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const RUBY_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const RUBY_STRING = (
digit_separator_to_flags!(b'_')
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const SWIFT_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const SWIFT_STRING = Self::REQUIRED_FRACTION_DIGITS.bits;
const GO_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const GO_STRING = Self::REQUIRED_FRACTION_DIGITS.bits;
const HASKELL_LITERAL = (
Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::NO_SPECIAL.bits
);
const HASKELL_STRING = (
Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const JAVASCRIPT_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const JAVASCRIPT_STRING = Self::CASE_SENSITIVE_SPECIAL.bits;
const PERL_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const PERL_STRING = 0;
const PHP_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const PHP_STRING = Self::NO_SPECIAL.bits;
const JAVA_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const JAVA_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const R_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const R_STRING = 0;
const KOTLIN_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const KOTLIN_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const JULIA_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
);
const JULIA_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const CSHARP7_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const CSHARP7_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP6_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP6_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP5_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP5_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP4_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP4_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP3_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP3_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP2_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP2_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const CSHARP1_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CSHARP1_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const KAWA_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const KAWA_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const GAMBITC_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const GAMBITC_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const GUILE_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const GUILE_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CLOJURE_LITERAL = (
Self::REQUIRED_INTEGER_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const CLOJURE_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const ERLANG_LITERAL = (
Self::REQUIRED_DIGITS.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const ERLANG_STRING = (
Self::REQUIRED_DIGITS.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::NO_SPECIAL.bits
);
const ELM_LITERAL = (
Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
);
const ELM_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const SCALA_LITERAL = (
Self::REQUIRED_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const SCALA_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const ELIXIR_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_DIGITS.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const ELIXIR_STRING = (
Self::REQUIRED_DIGITS.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::NO_SPECIAL.bits
);
const FORTRAN_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const FORTRAN_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;
const D_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const D_STRING = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
| Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
| Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
);
const COFFEESCRIPT_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const COFFEESCRIPT_STRING = Self::CASE_SENSITIVE_SPECIAL.bits;
const COBOL_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_EXPONENT_WITHOUT_FRACTION.bits
| Self::NO_SPECIAL.bits
);
const COBOL_STRING = (
Self::REQUIRED_EXPONENT_SIGN.bits
| Self::NO_SPECIAL.bits
);
const FSHARP_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_INTEGER_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const FSHARP_STRING = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::SPECIAL_DIGIT_SEPARATOR.bits
);
const VB_LITERAL = (
Self::REQUIRED_FRACTION_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const VB_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const OCAML_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_INTEGER_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const OCAML_STRING = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::SPECIAL_DIGIT_SEPARATOR.bits
);
const OBJECTIVEC_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const OBJECTIVEC_STRING = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const REASONML_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_INTEGER_DIGITS.bits
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const REASONML_STRING = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
| Self::SPECIAL_DIGIT_SEPARATOR.bits
);
const OCTAVE_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const OCTAVE_STRING = (
digit_separator_to_flags!(b',')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const MATLAB_LITERAL = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const MATLAB_STRING = (
digit_separator_to_flags!(b',')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
| Self::LEADING_DIGIT_SEPARATOR.bits
| Self::TRAILING_DIGIT_SEPARATOR.bits
| Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
);
const ZIG_LITERAL = (
Self::REQUIRED_INTEGER_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::NO_SPECIAL.bits
);
const ZIG_STRING = 0;
const SAGE_LITERAL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
const SAGE_STRING = (
digit_separator_to_flags!(b'_')
| Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const JSON = (
Self::REQUIRED_DIGITS.bits
| Self::NO_POSITIVE_MANTISSA_SIGN.bits
| Self::NO_SPECIAL.bits
);
const TOML = (
Self::REQUIRED_DIGITS.bits
| Self::NO_SPECIAL.bits
| Self::INTERNAL_DIGIT_SEPARATOR.bits
);
const YAML = Self::JSON.bits;
const XML = Self::CASE_SENSITIVE_SPECIAL.bits;
const SQLITE = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const POSTGRESQL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const MYSQL = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::NO_SPECIAL.bits
);
const MONGODB = (
Self::REQUIRED_EXPONENT_DIGITS.bits
| Self::CASE_SENSITIVE_SPECIAL.bits
);
#[doc(hidden)]
const PERMISSIVE = 0;
#[doc(hidden)]
const PERMISSIVE_INTERFACE = Self::PERMISSIVE.bits & Self::INTERFACE_FLAG_MASK.bits;
#[doc(hidden)]
const STANDARD = Self::RUST_STRING.bits;
#[doc(hidden)]
const STANDARD_INTERFACE = Self::STANDARD.bits & Self::INTERFACE_FLAG_MASK.bits;
#[doc(hidden)]
const IGNORE = Self::DIGIT_SEPARATOR_FLAG_MASK.bits;
#[doc(hidden)]
const IGNORE_INTERFACE = Self::IGNORE.bits & Self::INTERFACE_FLAG_MASK.bits;
#[doc(hidden)]
const INTEGER_I = Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const INTEGER_L = Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const INTEGER_T = Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const INTEGER_C = Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const INTEGER_IL = Self::INTEGER_I.bits | Self::INTEGER_L.bits;
#[doc(hidden)]
const INTEGER_IT = Self::INTEGER_I.bits | Self::INTEGER_T.bits;
#[doc(hidden)]
const INTEGER_LT = Self::INTEGER_L.bits | Self::INTEGER_T.bits;
#[doc(hidden)]
const INTEGER_ILT = Self::INTEGER_IL.bits | Self::INTEGER_T.bits;
#[doc(hidden)]
const INTEGER_IC = Self::INTEGER_I.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_LC = Self::INTEGER_L.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_TC = Self::INTEGER_T.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_ILC = Self::INTEGER_IL.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_ITC = Self::INTEGER_IT.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_LTC = Self::INTEGER_LT.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const INTEGER_ILTC = Self::INTEGER_ILT.bits | Self::INTEGER_C.bits;
#[doc(hidden)]
const FRACTION_I = Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const FRACTION_L = Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const FRACTION_T = Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const FRACTION_C = Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const FRACTION_IL = Self::FRACTION_I.bits | Self::FRACTION_L.bits;
#[doc(hidden)]
const FRACTION_IT = Self::FRACTION_I.bits | Self::FRACTION_T.bits;
#[doc(hidden)]
const FRACTION_LT = Self::FRACTION_L.bits | Self::FRACTION_T.bits;
#[doc(hidden)]
const FRACTION_ILT = Self::FRACTION_IL.bits | Self::FRACTION_T.bits;
#[doc(hidden)]
const FRACTION_IC = Self::FRACTION_I.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_LC = Self::FRACTION_L.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_TC = Self::FRACTION_T.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_ILC = Self::FRACTION_IL.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_ITC = Self::FRACTION_IT.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_LTC = Self::FRACTION_LT.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const FRACTION_ILTC = Self::FRACTION_ILT.bits | Self::FRACTION_C.bits;
#[doc(hidden)]
const EXPONENT_I = Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const EXPONENT_L = Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const EXPONENT_T = Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const EXPONENT_C = Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits;
#[doc(hidden)]
const EXPONENT_IL = Self::EXPONENT_I.bits | Self::EXPONENT_L.bits;
#[doc(hidden)]
const EXPONENT_IT = Self::EXPONENT_I.bits | Self::EXPONENT_T.bits;
#[doc(hidden)]
const EXPONENT_LT = Self::EXPONENT_L.bits | Self::EXPONENT_T.bits;
#[doc(hidden)]
const EXPONENT_ILT = Self::EXPONENT_IL.bits | Self::EXPONENT_T.bits;
#[doc(hidden)]
const EXPONENT_IC = Self::EXPONENT_I.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_LC = Self::EXPONENT_L.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_TC = Self::EXPONENT_T.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_ILC = Self::EXPONENT_IL.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_ITC = Self::EXPONENT_IT.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_LTC = Self::EXPONENT_LT.bits | Self::EXPONENT_C.bits;
#[doc(hidden)]
const EXPONENT_ILTC = Self::EXPONENT_ILT.bits | Self::EXPONENT_C.bits;
}
}
macro_rules! check_subsequent_flags {
($name:ident; $x:ident, $y:ident) => (
const_assert!($name; NumberFormat::$x.bits << 1 == NumberFormat::$y.bits);
);
}
check_subsequent_flags!(flags0; REQUIRED_INTEGER_DIGITS, REQUIRED_FRACTION_DIGITS);
check_subsequent_flags!(flags1; REQUIRED_FRACTION_DIGITS, REQUIRED_EXPONENT_DIGITS);
check_subsequent_flags!(flags2; REQUIRED_EXPONENT_DIGITS, NO_POSITIVE_MANTISSA_SIGN);
check_subsequent_flags!(flags3; NO_POSITIVE_MANTISSA_SIGN, REQUIRED_MANTISSA_SIGN);
check_subsequent_flags!(flags4; REQUIRED_MANTISSA_SIGN, NO_EXPONENT_NOTATION);
check_subsequent_flags!(flags5; NO_EXPONENT_NOTATION, NO_POSITIVE_EXPONENT_SIGN);
check_subsequent_flags!(flags6; NO_POSITIVE_EXPONENT_SIGN, REQUIRED_EXPONENT_SIGN);
check_subsequent_flags!(flags7; REQUIRED_EXPONENT_SIGN, NO_EXPONENT_WITHOUT_FRACTION);
check_subsequent_flags!(flags8; NO_EXPONENT_WITHOUT_FRACTION, NO_SPECIAL);
check_subsequent_flags!(flags9; NO_SPECIAL, CASE_SENSITIVE_SPECIAL);
check_subsequent_flags!(flags10; CASE_SENSITIVE_SPECIAL, INTEGER_INTERNAL_DIGIT_SEPARATOR);
check_subsequent_flags!(flags11; INTEGER_INTERNAL_DIGIT_SEPARATOR, FRACTION_INTERNAL_DIGIT_SEPARATOR);
check_subsequent_flags!(flags12; FRACTION_INTERNAL_DIGIT_SEPARATOR, EXPONENT_INTERNAL_DIGIT_SEPARATOR);
check_subsequent_flags!(flags13; EXPONENT_INTERNAL_DIGIT_SEPARATOR, INTEGER_LEADING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags14; INTEGER_LEADING_DIGIT_SEPARATOR, FRACTION_LEADING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags15; FRACTION_LEADING_DIGIT_SEPARATOR, EXPONENT_LEADING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags16; EXPONENT_LEADING_DIGIT_SEPARATOR, INTEGER_TRAILING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags17; INTEGER_TRAILING_DIGIT_SEPARATOR, FRACTION_TRAILING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags18; FRACTION_TRAILING_DIGIT_SEPARATOR, EXPONENT_TRAILING_DIGIT_SEPARATOR);
check_subsequent_flags!(flags19; EXPONENT_TRAILING_DIGIT_SEPARATOR, INTEGER_CONSECUTIVE_DIGIT_SEPARATOR);
check_subsequent_flags!(flags20; INTEGER_CONSECUTIVE_DIGIT_SEPARATOR, FRACTION_CONSECUTIVE_DIGIT_SEPARATOR);
check_subsequent_flags!(flags21; FRACTION_CONSECUTIVE_DIGIT_SEPARATOR, EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR);
check_subsequent_flags!(flags22; EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR, SPECIAL_DIGIT_SEPARATOR);
macro_rules! add_flag {
($flags:ident, $bool:ident, $flag:ident) => {
if $bool {
$flags |= NumberFormat::$flag;
}
};
}
impl NumberFormat {
#[cfg_attr(feature = "radix", doc = " Digit separators must not be in the character group `[A-Za-z0-9+.-]`, nor be equal to")]
#[cfg_attr(feature = "radix", doc = " [`get_exponent_default_char`](fn.get_exponent_default_char.html) or")]
#[cfg_attr(feature = "radix", doc = " [`get_exponent_backup_char`](fn.get_exponent_backup_char.html).")]
#[cfg_attr(not(feature = "radix"), doc = " Digit separators must not be in the character group `[0-9+.-]`, nor be equal to")]
#[cfg_attr(not(feature = "radix"), doc = " [get_exponent_default_char](fn.get_exponent_default_char.html).")]
#[inline]
pub fn compile(
digit_separator: u8,
required_integer_digits: bool,
required_fraction_digits: bool,
required_exponent_digits: bool,
no_positive_mantissa_sign: bool,
required_mantissa_sign: bool,
no_exponent_notation: bool,
no_positive_exponent_sign: bool,
required_exponent_sign: bool,
no_exponent_without_fraction: bool,
no_special: bool,
case_sensitive_special: bool,
integer_internal_digit_separator: bool,
fraction_internal_digit_separator: bool,
exponent_internal_digit_separator: bool,
integer_leading_digit_separator: bool,
fraction_leading_digit_separator: bool,
exponent_leading_digit_separator: bool,
integer_trailing_digit_separator: bool,
fraction_trailing_digit_separator: bool,
exponent_trailing_digit_separator: bool,
integer_consecutive_digit_separator: bool,
fraction_consecutive_digit_separator: bool,
exponent_consecutive_digit_separator: bool,
special_digit_separator: bool
) -> Option<NumberFormat> {
let mut format = NumberFormat::default();
add_flag!(format, required_integer_digits, REQUIRED_INTEGER_DIGITS);
add_flag!(format, required_fraction_digits, REQUIRED_FRACTION_DIGITS);
add_flag!(format, required_exponent_digits, REQUIRED_EXPONENT_DIGITS);
add_flag!(format, no_positive_mantissa_sign, NO_POSITIVE_MANTISSA_SIGN);
add_flag!(format, required_mantissa_sign, REQUIRED_MANTISSA_SIGN);
add_flag!(format, no_exponent_notation, NO_EXPONENT_NOTATION);
add_flag!(format, no_positive_exponent_sign, NO_POSITIVE_EXPONENT_SIGN);
add_flag!(format, required_exponent_sign, REQUIRED_EXPONENT_SIGN);
add_flag!(format, no_exponent_without_fraction, NO_EXPONENT_WITHOUT_FRACTION);
add_flag!(format, no_special, NO_SPECIAL);
add_flag!(format, case_sensitive_special, CASE_SENSITIVE_SPECIAL);
add_flag!(format, integer_internal_digit_separator, INTEGER_INTERNAL_DIGIT_SEPARATOR);
add_flag!(format, fraction_internal_digit_separator, FRACTION_INTERNAL_DIGIT_SEPARATOR);
add_flag!(format, exponent_internal_digit_separator, EXPONENT_INTERNAL_DIGIT_SEPARATOR);
add_flag!(format, integer_leading_digit_separator, INTEGER_LEADING_DIGIT_SEPARATOR);
add_flag!(format, fraction_leading_digit_separator, FRACTION_LEADING_DIGIT_SEPARATOR);
add_flag!(format, exponent_leading_digit_separator, EXPONENT_LEADING_DIGIT_SEPARATOR);
add_flag!(format, integer_trailing_digit_separator, INTEGER_TRAILING_DIGIT_SEPARATOR);
add_flag!(format, fraction_trailing_digit_separator, FRACTION_TRAILING_DIGIT_SEPARATOR);
add_flag!(format, exponent_trailing_digit_separator, EXPONENT_TRAILING_DIGIT_SEPARATOR);
add_flag!(format, integer_consecutive_digit_separator, INTEGER_CONSECUTIVE_DIGIT_SEPARATOR);
add_flag!(format, fraction_consecutive_digit_separator, FRACTION_CONSECUTIVE_DIGIT_SEPARATOR);
add_flag!(format, exponent_consecutive_digit_separator, EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR);
add_flag!(format, special_digit_separator, SPECIAL_DIGIT_SEPARATOR);
if format.intersects(NumberFormat::DIGIT_SEPARATOR_FLAG_MASK) {
format.bits |= digit_separator_to_flags!(digit_separator);
}
let is_invalid =
!is_valid_separator(digit_separator)
|| format.intersects(NumberFormat::NO_EXPONENT_NOTATION) && format.intersects(NumberFormat::EXPONENT_FLAG_MASK)
|| no_positive_mantissa_sign && required_mantissa_sign
|| no_positive_exponent_sign && required_exponent_sign
|| no_special && (case_sensitive_special || special_digit_separator)
|| format & NumberFormat::INTEGER_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR
|| format & NumberFormat::FRACTION_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR
|| format & NumberFormat::EXPONENT_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR;
match is_invalid {
true => None,
false => Some(format)
}
}
pub fn permissive() -> Option<NumberFormat> {
Some(NumberFormat::PERMISSIVE)
}
pub fn standard() -> Option<NumberFormat> {
Some(NumberFormat::STANDARD)
}
pub fn ignore(digit_separator: u8) -> Option<NumberFormat> {
if !is_valid_separator(digit_separator) {
return None
}
let mut format = NumberFormat::IGNORE;
format.bits |= digit_separator_to_flags!(digit_separator);
Some(format)
}
#[cfg(test)]
#[inline]
pub(crate) fn from_separator(digit_separator: u8) -> NumberFormat {
NumberFormat { bits: digit_separator_to_flags!(digit_separator) }
}
#[inline]
pub fn flags(self) -> NumberFormat {
return self & NumberFormat::FLAG_MASK
}
#[inline]
pub(crate) fn interface_flags(self) -> NumberFormat {
return self & NumberFormat::INTERFACE_FLAG_MASK
}
#[inline]
pub fn digit_separator(self) -> u8 {
digit_separator_from_flags(self.bits)
}
#[inline]
pub fn required_integer_digits(self) -> bool {
self.intersects(NumberFormat::REQUIRED_INTEGER_DIGITS)
}
#[inline]
pub fn required_fraction_digits(self) -> bool {
self.intersects(NumberFormat::REQUIRED_FRACTION_DIGITS)
}
#[inline]
pub fn required_exponent_digits(self) -> bool {
self.intersects(NumberFormat::REQUIRED_EXPONENT_DIGITS)
}
#[inline]
pub fn required_digits(self) -> bool {
self.intersects(NumberFormat::REQUIRED_DIGITS)
}
#[inline]
pub fn no_positive_mantissa_sign(self) -> bool {
self.intersects(NumberFormat::NO_POSITIVE_MANTISSA_SIGN)
}
#[inline]
pub fn required_mantissa_sign(self) -> bool {
self.intersects(NumberFormat::REQUIRED_MANTISSA_SIGN)
}
#[inline]
pub fn no_exponent_notation(self) -> bool {
self.intersects(NumberFormat::NO_EXPONENT_NOTATION)
}
#[inline]
pub fn no_positive_exponent_sign(self) -> bool {
self.intersects(NumberFormat::NO_POSITIVE_EXPONENT_SIGN)
}
#[inline]
pub fn required_exponent_sign(self) -> bool {
self.intersects(NumberFormat::REQUIRED_EXPONENT_SIGN)
}
#[inline]
pub fn no_exponent_without_fraction(self) -> bool {
self.intersects(NumberFormat::NO_EXPONENT_WITHOUT_FRACTION)
}
#[inline]
pub fn no_special(self) -> bool {
self.intersects(NumberFormat::NO_SPECIAL)
}
#[inline]
pub fn case_sensitive_special(self) -> bool {
self.intersects(NumberFormat::CASE_SENSITIVE_SPECIAL)
}
#[inline]
pub fn integer_internal_digit_separator(self) -> bool {
self.intersects(NumberFormat::INTEGER_INTERNAL_DIGIT_SEPARATOR)
}
#[inline]
pub fn fraction_internal_digit_separator(self) -> bool {
self.intersects(NumberFormat::FRACTION_INTERNAL_DIGIT_SEPARATOR)
}
#[inline]
pub fn exponent_internal_digit_separator(self) -> bool {
self.intersects(NumberFormat::EXPONENT_INTERNAL_DIGIT_SEPARATOR)
}
#[inline]
pub fn internal_digit_separator(self) -> bool {
self.intersects(NumberFormat::INTERNAL_DIGIT_SEPARATOR)
}
#[inline]
pub fn integer_leading_digit_separator(self) -> bool {
self.intersects(NumberFormat::INTEGER_LEADING_DIGIT_SEPARATOR)
}
#[inline]
pub fn fraction_leading_digit_separator(self) -> bool {
self.intersects(NumberFormat::FRACTION_LEADING_DIGIT_SEPARATOR)
}
#[inline]
pub fn exponent_leading_digit_separator(self) -> bool {
self.intersects(NumberFormat::EXPONENT_LEADING_DIGIT_SEPARATOR)
}
#[inline]
pub fn leading_digit_separator(self) -> bool {
self.intersects(NumberFormat::LEADING_DIGIT_SEPARATOR)
}
#[inline]
pub fn integer_trailing_digit_separator(self) -> bool {
self.intersects(NumberFormat::INTEGER_TRAILING_DIGIT_SEPARATOR)
}
#[inline]
pub fn fraction_trailing_digit_separator(self) -> bool {
self.intersects(NumberFormat::FRACTION_TRAILING_DIGIT_SEPARATOR)
}
#[inline]
pub fn exponent_trailing_digit_separator(self) -> bool {
self.intersects(NumberFormat::EXPONENT_TRAILING_DIGIT_SEPARATOR)
}
#[inline]
pub fn trailing_digit_separator(self) -> bool {
self.intersects(NumberFormat::TRAILING_DIGIT_SEPARATOR)
}
#[inline]
pub fn integer_consecutive_digit_separator(self) -> bool {
self.intersects(NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR)
}
#[inline]
pub fn fraction_consecutive_digit_separator(self) -> bool {
self.intersects(NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR)
}
#[inline]
pub fn exponent_consecutive_digit_separator(self) -> bool {
self.intersects(NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR)
}
#[inline]
pub fn consecutive_digit_separator(self) -> bool {
self.intersects(NumberFormat::CONSECUTIVE_DIGIT_SEPARATOR)
}
#[inline]
pub fn special_digit_separator(self) -> bool {
self.intersects(NumberFormat::SPECIAL_DIGIT_SEPARATOR)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_valid_separator() {
assert_eq!(is_valid_separator(b'_'), true);
assert_eq!(is_valid_separator(b'\''), true);
assert_eq!(is_valid_separator(b'0'), false);
assert_eq!(is_valid_separator(128), false);
}
#[test]
fn test_compile() {
let flags = NumberFormat::compile(b'_', false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false).unwrap();
assert_eq!(flags.flags(), NumberFormat::default());
assert_eq!(flags.digit_separator(), 0);
}
#[test]
fn test_permissive() {
let flags = NumberFormat::ignore(b'_').unwrap();
assert_eq!(flags.flags(), NumberFormat::DIGIT_SEPARATOR_FLAG_MASK);
}
#[test]
fn test_ignore() {
let flags = NumberFormat::ignore(b'_').unwrap();
assert_eq!(flags.flags(), NumberFormat::DIGIT_SEPARATOR_FLAG_MASK);
assert_eq!(flags.digit_separator(), b'_');
assert_eq!(flags.required_integer_digits(), false);
assert_eq!(flags.required_fraction_digits(), false);
assert_eq!(flags.required_exponent_digits(), false);
assert_eq!(flags.required_digits(), false);
assert_eq!(flags.no_positive_mantissa_sign(), false);
assert_eq!(flags.required_mantissa_sign(), false);
assert_eq!(flags.no_exponent_notation(), false);
assert_eq!(flags.no_positive_exponent_sign(), false);
assert_eq!(flags.required_exponent_sign(), false);
assert_eq!(flags.no_exponent_without_fraction(), false);
assert_eq!(flags.no_special(), false);
assert_eq!(flags.case_sensitive_special(), false);
assert_eq!(flags.integer_internal_digit_separator(), true);
assert_eq!(flags.fraction_internal_digit_separator(), true);
assert_eq!(flags.exponent_internal_digit_separator(), true);
assert_eq!(flags.internal_digit_separator(), true);
assert_eq!(flags.integer_leading_digit_separator(), true);
assert_eq!(flags.fraction_leading_digit_separator(), true);
assert_eq!(flags.exponent_leading_digit_separator(), true);
assert_eq!(flags.leading_digit_separator(), true);
assert_eq!(flags.integer_trailing_digit_separator(), true);
assert_eq!(flags.fraction_trailing_digit_separator(), true);
assert_eq!(flags.exponent_trailing_digit_separator(), true);
assert_eq!(flags.trailing_digit_separator(), true);
assert_eq!(flags.integer_consecutive_digit_separator(), true);
assert_eq!(flags.fraction_consecutive_digit_separator(), true);
assert_eq!(flags.exponent_consecutive_digit_separator(), true);
assert_eq!(flags.consecutive_digit_separator(), true);
assert_eq!(flags.special_digit_separator(), true);
}
#[test]
fn test_flags() {
let flags = [
NumberFormat::REQUIRED_INTEGER_DIGITS,
NumberFormat::REQUIRED_FRACTION_DIGITS,
NumberFormat::REQUIRED_EXPONENT_DIGITS,
NumberFormat::NO_POSITIVE_MANTISSA_SIGN,
NumberFormat::REQUIRED_MANTISSA_SIGN,
NumberFormat::NO_EXPONENT_NOTATION,
NumberFormat::NO_POSITIVE_EXPONENT_SIGN,
NumberFormat::REQUIRED_EXPONENT_SIGN,
NumberFormat::NO_EXPONENT_WITHOUT_FRACTION,
NumberFormat::NO_SPECIAL,
NumberFormat::CASE_SENSITIVE_SPECIAL,
NumberFormat::INTEGER_INTERNAL_DIGIT_SEPARATOR,
NumberFormat::FRACTION_INTERNAL_DIGIT_SEPARATOR,
NumberFormat::EXPONENT_INTERNAL_DIGIT_SEPARATOR,
NumberFormat::INTEGER_LEADING_DIGIT_SEPARATOR,
NumberFormat::FRACTION_LEADING_DIGIT_SEPARATOR,
NumberFormat::EXPONENT_LEADING_DIGIT_SEPARATOR,
NumberFormat::INTEGER_TRAILING_DIGIT_SEPARATOR,
NumberFormat::FRACTION_TRAILING_DIGIT_SEPARATOR,
NumberFormat::EXPONENT_TRAILING_DIGIT_SEPARATOR,
NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR,
NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR,
NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR,
NumberFormat::SPECIAL_DIGIT_SEPARATOR
];
for &flag in flags.iter() {
assert_eq!(flag.flags(), flag);
assert_eq!(flag.digit_separator(), 0);
}
}
#[test]
fn test_constants() {
let flags = [
NumberFormat::RUST_LITERAL,
NumberFormat::RUST_STRING,
NumberFormat::RUST_STRING_STRICT,
NumberFormat::PYTHON_LITERAL,
NumberFormat::PYTHON_STRING,
NumberFormat::CXX17_LITERAL,
NumberFormat::CXX17_STRING,
NumberFormat::CXX14_LITERAL,
NumberFormat::CXX14_STRING,
NumberFormat::CXX11_LITERAL,
NumberFormat::CXX11_STRING,
NumberFormat::CXX03_LITERAL,
NumberFormat::CXX03_STRING,
NumberFormat::CXX98_LITERAL,
NumberFormat::CXX98_STRING,
NumberFormat::C18_LITERAL,
NumberFormat::C18_STRING,
NumberFormat::C11_LITERAL,
NumberFormat::C11_STRING,
NumberFormat::C99_LITERAL,
NumberFormat::C99_STRING,
NumberFormat::C90_LITERAL,
NumberFormat::C90_STRING,
NumberFormat::C89_LITERAL,
NumberFormat::C89_STRING,
NumberFormat::RUBY_LITERAL,
NumberFormat::RUBY_STRING,
NumberFormat::SWIFT_LITERAL,
NumberFormat::SWIFT_STRING,
NumberFormat::GO_LITERAL,
NumberFormat::GO_STRING,
NumberFormat::HASKELL_LITERAL,
NumberFormat::HASKELL_STRING,
NumberFormat::JAVASCRIPT_LITERAL,
NumberFormat::JAVASCRIPT_STRING,
NumberFormat::PERL_LITERAL,
NumberFormat::PERL_STRING,
NumberFormat::PHP_LITERAL,
NumberFormat::PHP_STRING,
NumberFormat::JAVA_LITERAL,
NumberFormat::JAVA_STRING,
NumberFormat::R_LITERAL,
NumberFormat::R_STRING,
NumberFormat::KOTLIN_LITERAL,
NumberFormat::KOTLIN_STRING,
NumberFormat::JULIA_LITERAL,
NumberFormat::JULIA_STRING,
NumberFormat::CSHARP7_LITERAL,
NumberFormat::CSHARP7_STRING,
NumberFormat::CSHARP6_LITERAL,
NumberFormat::CSHARP6_STRING,
NumberFormat::CSHARP5_LITERAL,
NumberFormat::CSHARP5_STRING,
NumberFormat::CSHARP4_LITERAL,
NumberFormat::CSHARP4_STRING,
NumberFormat::CSHARP3_LITERAL,
NumberFormat::CSHARP3_STRING,
NumberFormat::CSHARP2_LITERAL,
NumberFormat::CSHARP2_STRING,
NumberFormat::CSHARP1_LITERAL,
NumberFormat::CSHARP1_STRING,
NumberFormat::KAWA_LITERAL,
NumberFormat::KAWA_STRING,
NumberFormat::GAMBITC_LITERAL,
NumberFormat::GAMBITC_STRING,
NumberFormat::GUILE_LITERAL,
NumberFormat::GUILE_STRING,
NumberFormat::CLOJURE_LITERAL,
NumberFormat::CLOJURE_STRING,
NumberFormat::ERLANG_LITERAL,
NumberFormat::ERLANG_STRING,
NumberFormat::ELM_LITERAL,
NumberFormat::ELM_STRING,
NumberFormat::SCALA_LITERAL,
NumberFormat::SCALA_STRING,
NumberFormat::ELIXIR_LITERAL,
NumberFormat::ELIXIR_STRING,
NumberFormat::FORTRAN_LITERAL,
NumberFormat::FORTRAN_STRING,
NumberFormat::D_LITERAL,
NumberFormat::D_STRING,
NumberFormat::COFFEESCRIPT_LITERAL,
NumberFormat::COFFEESCRIPT_STRING,
NumberFormat::COBOL_LITERAL,
NumberFormat::COBOL_STRING,
NumberFormat::FSHARP_LITERAL,
NumberFormat::FSHARP_STRING,
NumberFormat::VB_LITERAL,
NumberFormat::VB_STRING,
NumberFormat::OCAML_LITERAL,
NumberFormat::OCAML_STRING,
NumberFormat::OBJECTIVEC_LITERAL,
NumberFormat::OBJECTIVEC_STRING,
NumberFormat::REASONML_LITERAL,
NumberFormat::REASONML_STRING,
NumberFormat::OCTAVE_LITERAL,
NumberFormat::OCTAVE_STRING,
NumberFormat::MATLAB_LITERAL,
NumberFormat::MATLAB_STRING,
NumberFormat::ZIG_LITERAL,
NumberFormat::ZIG_STRING,
NumberFormat::SAGE_LITERAL,
NumberFormat::SAGE_STRING,
NumberFormat::JSON,
NumberFormat::TOML,
NumberFormat::YAML,
NumberFormat::XML,
NumberFormat::SQLITE,
NumberFormat::POSTGRESQL,
NumberFormat::MYSQL,
NumberFormat::MONGODB
];
for &flag in flags.iter() {
assert!((flag.bits == 0) | true);
assert!((flag.digit_separator() == 0) | true);
}
}
}
}}