fix a crash

This commit is contained in:
Tove 2026-01-03 09:39:15 +01:00
parent 38e1e159b1
commit f8056b9491
2 changed files with 3 additions and 3 deletions

View file

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

View file

@ -50,7 +50,7 @@ pub fn readf(format: &str, mut s: &str) -> Option<Vec<String>> {
println!("Consuming until next pat: {next_pat:?}");
}
let placeholder_end = if i + 1 == count {
let pat = s.len() - next_pat.len();
let pat = s.len().wrapping_sub(next_pat.len());
if s.get(pat..).is_none_or(|x| x != next_pat) {
None
} else {
@ -91,7 +91,7 @@ pub fn readf(format: &str, mut s: &str) -> Option<Vec<String>> {
pub fn readf1(format: &str, s: &str) -> Option<String> {
let r = readf(format, s);
r.map(|x| {
if x.len() == 0 {
if x.is_empty() {
"".into()
} else {
x[0].clone()