Hey everyone, I have two functions fn parse_as_integer(input: &str) -> Result<i32, String>
that contains .is_numeric() and .parse::<i32>() for (i, y) in input.char_indices() { if !y.is_numeric() … if let Ok(number) = input[...position].parse::<i32>() …
And the function fn format_fraction(num: i32) -> &str
that contains .to_string() s.push_str(&whole_num.to_string());
From the Rust Docs - char the is_numeric() should be able to detect numbers in different languages. My questions are,
Can .parse::<i32>() convert number strings in different languages?
How would I use .to_string() (or another method/s) to convert numbers to a string based on the users language?
p.s. I am using GTK-rs and related libraries for Internationalization and Localization.
p.s.s. I haven't created any tests for these two functions, yet.
While is_numeric() relies on Unicode properties, the FromStr implementations (and thus parse()) use the same logic as from_str_radix(_) and to_digit(_) -- ASCII digits and letters (depending on the radix) only.
You're definitely going to need a library (other than the standard library). Out of curiosity I did some searching and found the ICU RBNF, which can apparently parse as well as display numbers textually. Live examples seem sparse though. I think in general it's a tall order, but maybe someone else knows of a different library.
Bummer, but thanks.
I was hoping the standard library would do the conversion for me.
The first 3 asserts below are true but the last fails with ParseIntError { kind: InvalidDigit }
@quinedot yeah, for the to_string() I don't expect the standard library to handle multiple languages. But hopefully the standard library could handle more unicode numbers within their other functions.
I might see if GTK has something and if gtk-rs has a rust function for it.