Crates.io | ean |
lib.rs | ean |
version | 0.2.0 |
source | src |
created_at | 2022-05-14 12:55:20.71287 |
updated_at | 2022-05-14 15:36:01.73131 |
description | A Rust library that can convert Western Arabic Numerals to Eastern Arabic Numerals |
homepage | https://github.com/0x1eef/ean/blob/master/rust#readme |
repository | https://github.com/0x1eef/ean/blob/master/rust#readme |
max_upload_size | |
id | 586661 |
size | 6,927 |
The ean.rs Rust library can convert Western Arabic Numerals to
Eastern Arabic Numerals. Western Arabic Numerals are represented
by the digits between 0
and 9
, while Eastern Arabic Numerals are
represented by the digits between ٠
(zero) and ٩
(nine).
1. Obtain an Eastern Arabic Numeral
The following examples takes the Western Arabic Numeral, 120
,
and converts it to its Eastern Arabic Numeral counterpart. Note that,
both western and eastern arabic numerals should be read from left-to-right
(LTR), despite Arabic being read from right-to-left (RTL). Some terminals
don't follow that rule though, and might print the eastern numerals RTL,
as they would with other Arabic characters.
use ean;
fn main() {
let numeral = ean::from(120);
println!("{}", numeral);
}
2. Obtain the digits of an Eastern Arabic Numeral
In the following example, we see how the digits that make
up an Eastern Arabic Numeral can be accessed individually
through the "digits" field available on instances of the
ean::Numeral
struct.
use ean;
fn main() {
let numeral = ean::from(42);
let digits = numeral.digits.iter();
for (i, digit) in digits.enumerate() {
println!("Digit {} is {}", i, digit.to_char);
}
}
3. Compare eastern numerals with western numerals
In the following example, we see how an Eastern Arabic Numeral can be compared with a Western Arabic Numeral using the equality operator.
use ean;
fn main() {
let numeral = ean::from(42);
/* This expression evaluates to true */
if numeral == 42 {
println!("{} is equal to {}", numeral, 42);
}
}
This software is released under the MIT license, see ./LICENSE.txt for details.