ean

Crates.ioean
lib.rsean
version0.2.0
sourcesrc
created_at2022-05-14 12:55:20.71287
updated_at2022-05-14 15:36:01.73131
descriptionA Rust library that can convert Western Arabic Numerals to Eastern Arabic Numerals
homepagehttps://github.com/0x1eef/ean/blob/master/rust#readme
repositoryhttps://github.com/0x1eef/ean/blob/master/rust#readme
max_upload_size
id586661
size6,927
0x1eef (0x1eef)

documentation

README

ean.rs

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).

Examples

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);
  }
}

License

This software is released under the MIT license, see ./LICENSE.txt for details.

Commit count: 0

cargo fmt