Skip to main content

Module strnum

Module strnum 

Source
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§

ParsedNumber
What str_to_number produced, including the per-language side effects Python stashes on self for 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 because has_decimal checks "." in str(number) and to_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 ch as a Unicode decimal digit, as Python’s int() / 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.