1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
//! `titlefmt` is a title formatting expression library. It enables automatic formatting of media metadata. //! //! # Example //! ``` //! extern crate titlefmt; //! //! use std::collections::HashMap; //! use titlefmt::{ metadata, Formatter }; //! //! pub struct MetadataProvider<'a> { //! metadata_dict: HashMap<&'a str, &'a str>, //! } //! //! impl<'a> metadata::Provider for MetadataProvider<'a> { //! fn tag_value(&self, key: &str) -> Option<String> { //! let entry = self.metadata_dict.get(key); //! if let Some(value) = entry { //! let s = value.to_string(); //! Some(s) //! } //! else { //! None //! } //! } //! } //! //! impl<'a> MetadataProvider<'a> { //! pub fn new(metadata_dict: HashMap<&'a str, &'a str>) -> MetadataProvider<'a> { //! MetadataProvider { //! metadata_dict, //! } //! } //! } //! //! fn main() { //! let formatter = Formatter::new(); //! // tests with optional expressions //! { //! let expression = formatter.parser().parse("%tracknumber%.[ %artist% -] %title%").unwrap(); //! { //! let test_metadata = { //! let mut dict = HashMap::new(); //! dict.insert("tracknumber", "1"); //! dict.insert("title", "9th Symphony, 1. Allegro ma non troppo, un poco maestoso"); //! dict.insert("composer", "Ludwig van Beethoven"); //! MetadataProvider::new(dict) //! }; //! let s = expression.apply(&test_metadata); //! assert_eq!("01. 9th Symphony, 1. Allegro ma non troppo, un poco maestoso", s.to_string().as_str()); //! } //! { //! let test_metadata = { //! let mut dict = HashMap::new(); //! dict.insert("tracknumber", "5"); //! dict.insert("title", "Always Crashing In The Same Car"); //! dict.insert("artist", "David Bowie"); //! MetadataProvider::new(dict) //! }; //! let s = expression.apply(&test_metadata); //! assert_eq!("05. David Bowie - Always Crashing In The Same Car", s.to_string().as_str()); //! } //! } //! } //! ``` #[macro_use] extern crate nom; /// Metadata provider trait module. pub mod metadata; /// Expression module. pub mod expression; /// Functions module. #[macro_use] pub mod function; /// Parser module mod parser; /// Tests module. #[cfg(test)] mod test; /// Formatter module. mod formatter; pub use formatter::Formatter; /// FormatParser module. mod format_parser; pub use format_parser::FormatParser;