Skip to main content

normalize_draft

Function normalize_draft 

Source
pub fn normalize_draft(
    raw: &str,
    locale: &NumberLocale,
    kind: NumberKind,
) -> Result<NormalizedDraft, InputError>
Expand description

Normalizes locale tokens without coercing integer values through floats.

Empty input, lone signs/decimal separators, and exponent prefixes remain incomplete. Grouping is accepted only in the mantissa’s integer part, with the locale’s primary/secondary group widths. Space-grouping locales accept ordinary, nonbreaking, and narrow nonbreaking spaces interchangeably. Complete integer input uses decimal integer syntax; incomplete prefixes remain local even when their eventual spelling would require a float.

  • Complexity: O(raw bytes + locale token bytes) time and space.

§Errors

Returns Lexical for malformed syntax/grouping, TypeRange for overflow, nonfinite conversion, or nonzero values rounded to zero, UnsupportedEditor for unknown widths, and Locale for ambiguous or malformed vocabularies.

§Examples

use adam_web_ui::{components::number::*, input::NumberKind};
fn incomplete_prefix(locale: &NumberLocale) {
    assert_eq!(normalize_draft("-", locale, NumberKind::F64),
        Ok(NormalizedDraft::Incomplete));
}