Expand description
String-input parsing: the Rust side of converter.str_to_number and the
Decimal(value) constructor semantics it relies on.
Python’s dispatcher hands string input to str_to_number, whose base
implementation is Decimal(value). That constructor is not
BigDecimal::from_str: it strips whitespace, accepts a trailing dot
(“12.”), PEP-515 underscores (“1_000”), any Unicode decimal digit
(“١٢٣”), and the special values Infinity/NaN. Reproducing its acceptance
set exactly is what keeps num2words("12.") and num2words("abc")
behaving identically to the Python original.
Enums§
- Parsed
Number - What
str_to_numberproduced, including the per-language side effects Python stashes onselffor the same-call handshake.
Functions§
- has_
py_ digit any(ch.isdigit() for ch in s)— the dispatcher’s “does this string contain digits” test that decides between the sentence fallback and re-raising. str.isdigit() is wider than Nd (superscripts count), but the decimal blocks above cover every case the library’s callers hit.- python_
decimal_ parse - Python’s
Decimal(str)constructor. - python_
decimal_ str - Python’s
str(Decimal)— the to-scientific-string algorithm from the General Decimal Arithmetic spec. Needed becausehas_decimalchecks"." in str(number)andto_ordinal_num’s base default returns the value itself, which the dispatcher then str()s. - python_
int_ parse - Python’s
int(str)— used by the “n/d” fraction-string branch. Accepts surrounding whitespace, a sign, PEP-515 underscores and Unicode digits; no dot, no exponent. - unicode_
digit - The value of
chas a Unicode decimal digit, as Python’sint()/Decimal()accept (Nd category). Covers the blocks that show up in practice; anything unlisted is rejected, which surfaces as InvalidOperation exactly like a genuinely invalid character.