From 7e82f682f7fb0a9ec928aa895f6049dcd90bc0d8 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 1 Jan 2023 19:37:49 +0100 Subject: [PATCH] add readme --- README.md | 10 ++++++++++ src/lib.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..96c2b04 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# readformat + +The inverse of format!(). +The format argument is the format string, and the s argument is the string to match the format +against. + +Examples: + - `readf1("Hello, {}!", "Hello, world!")` => `Some("world")` + - `readf("I hope {} are {}!", "I hope you are doing well!")` => `Some(vec!["you", "well"])` + - `readf1("Goodbye, {}!", "Hello, world!")` => `None` diff --git a/src/lib.rs b/src/lib.rs index 002bbe1..39a2baf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,9 @@ /// against. /// /// Examples: -/// `readf("Hello, {}!", "Hello, world!")` => `Some(vec!["world"])` -/// `readf("I hope {} are {}!", "I hope you are doing well!")` => `Some(vec!["you", "well"])` -/// `readf("Goodbye, {}!", "Hello, world!")` => `None` +/// - `readf("Hello, {}!", "Hello, world!")` => `Some(vec!["world"])` +/// - `readf("I hope {} are {}!", "I hope you are doing well!")` => `Some(vec!["you", "well"])` +/// - `readf("Goodbye, {}!", "Hello, world!")` => `None` pub fn readf(format: &str, mut s: &str) -> Option> { if !format.contains("{}") { return if format == s { Some(vec![]) } else { None }; @@ -61,9 +61,9 @@ pub fn readf(format: &str, mut s: &str) -> Option> { /// Convenience function for single-item format strings. Extra items are dropped. /// /// Examples: -/// `readf1("Hello, {}!", "Hello, world!")` => `Some("world")` -/// `readf1("I hope {} are doing well!", "I hope you are doing well!")` => `Some("you")` -/// `readf1("Goodbye, {}!", "Hello, world!")` => `None` +/// - `readf1("Hello, {}!", "Hello, world!")` => `Some("world")` +/// - `readf1("I hope {} are doing well!", "I hope you are doing well!")` => `Some("you")` +/// - `readf1("Goodbye, {}!", "Hello, world!")` => `None` pub fn readf1(format: &str, s: &str) -> Option { let r = readf(format, s); r.map(|x| if x.len() == 0 { "".into() } else { x[0].clone() })