fix a crash

This commit is contained in:
Daniella / Tove 2023-01-01 20:01:55 +01:00
parent e066f6ddfe
commit 24e2a0d441
2 changed files with 4 additions and 1 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "readformat" name = "readformat"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
repository = "https://github.com/tudbut/readformat" repository = "https://github.com/tudbut/readformat"
license = "MIT" license = "MIT"

View file

@ -26,6 +26,9 @@ pub fn readf(format: &str, mut s: &str) -> Option<Vec<String>> {
for n in 0..=occurences { for n in 0..=occurences {
// shave off space until next {} // shave off space until next {}
let i = if let Some(x) = f.find("{}") { x } else { f.len() }; let i = if let Some(x) = f.find("{}") { x } else { f.len() };
if f.len() <= i || s.len() <= i {
return None;
}
if &f[0..i] != &s[0..i] { if &f[0..i] != &s[0..i] {
return None; return None;
} }