improve read_rle
This commit is contained in:
parent
40795de5c3
commit
b9949eff67
22
src/lib.rs
22
src/lib.rs
|
@ -168,20 +168,20 @@ impl Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_rle(map: &str) -> std::result::Result<Self, ReadError> {
|
fn read_rle(map: &str) -> std::result::Result<Self, ReadError> {
|
||||||
let mut n: usize = 1;
|
|
||||||
|
|
||||||
Self::read(
|
Self::read(
|
||||||
map.chars()
|
map.chars()
|
||||||
.filter_map(|c| match c {
|
.scan(1, |n, c| {
|
||||||
'0'..='9' => {
|
Some(match c {
|
||||||
n = c.to_digit(10).unwrap() as usize;
|
'0'..='9' => {
|
||||||
None
|
*n = c.to_digit(10).unwrap() as usize;
|
||||||
}
|
None
|
||||||
'|' => Some("\n".into()),
|
}
|
||||||
_ => Some(c.to_string().repeat(n)),
|
'|' => Some("\n".to_string()),
|
||||||
|
_ => Some(c.to_string().repeat(*n)),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.flatten()
|
||||||
.join("")
|
.collect::<String>()
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue