cc82c47628
Changes to formatting system Create a formatting struct and then pass it to the to_text macro or the to_text_fmt function to format the strings accordingly Updated docs for the new version
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
//! Example program with default formatting
|
|
//!```rust
|
|
//!extern crate ntext;
|
|
//!use ntext::to_text;
|
|
//!fn main() {
|
|
//! assert_eq!(to_text!(7123),"Seven Thousand,One Hundred,Twenty-Three");
|
|
//! assert_eq!(to_text!(1000),"One Thousand");
|
|
//!}
|
|
//!```
|
|
//! Example program with custom formatting
|
|
//!
|
|
//!```rust
|
|
//!extern crate ntext;
|
|
//!use ntext::{Formatting,to_text};
|
|
//!fn main() {
|
|
//! assert_eq!(to_text!(1000, &Formatting::none().capitalize()),"OneThousand");
|
|
//! assert_eq!(to_text!(34123, &Formatting::with_seperator("#").capitalize()),"Thirty#Four#Thousand#One#Hundred#Twenty#Three");
|
|
//!}
|
|
//!```
|
|
//! This macro will also return an empty string on input zero
|
|
//! You can also create the Formatting struct manually
|
|
|
|
mod formatting;
|
|
mod numtext;
|
|
mod test;
|
|
|
|
pub use formatting::Formatting;
|
|
pub use numtext::{digit_to_text, to_text_fmt};
|
|
|
|
/// Macro which supports both seperator and without it
|
|
#[macro_export]
|
|
macro_rules! to_text {
|
|
($number:expr) => {
|
|
ntext::to_text_fmt($number, &ntext::Formatting::default());
|
|
};
|
|
($number:expr, $formatting:expr) => {
|
|
ntext::to_text_fmt($number, $formatting);
|
|
};
|
|
}
|