Skip to main content

parse_subscript_digits

Function parse_subscript_digits 

Source
pub fn parse_subscript_digits(s: &str) -> Option<u64>
Expand description

Reads a number written as a run of Unicode subscript digits.

This accepts exactly what fmt_subscript_digits writes, and nothing else: the empty string, a string holding anything but a subscript digit, a string with a leading zero, and a number too large for a u64 are all rejected. Accepting only the one spelling of a number is what makes the two functions inverse to each other.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is s.len().

§Examples

use malachite_base::chars::scripts::parse_subscript_digits;

assert_eq!(parse_subscript_digits("₀"), Some(0));
assert_eq!(parse_subscript_digits("₁₀"), Some(10));
assert_eq!(parse_subscript_digits(""), None);
assert_eq!(parse_subscript_digits("10"), None);
assert_eq!(parse_subscript_digits("₀₁"), None);