fix a crash
This commit is contained in:
parent
e066f6ddfe
commit
24e2a0d441
2 changed files with 4 additions and 1 deletions
|
@ -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"
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue