done, kinda hacky solution but it works
This commit is contained in:
@@ -217,22 +217,38 @@ named!(
|
|||||||
|
|
||||||
pub struct ParserIterator<'a> {
|
pub struct ParserIterator<'a> {
|
||||||
dat: &'a[u8],
|
dat: &'a[u8],
|
||||||
|
done: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for ParserIterator<'a> {
|
impl<'a> Iterator for ParserIterator<'a> {
|
||||||
type Item = Output<'a>;
|
type Item = Output<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let parse = parse_output(self.dat.as_bytes())
|
if self.done {
|
||||||
.unwrap();
|
return None;
|
||||||
|
}
|
||||||
|
let parse = parse_output(self.dat);
|
||||||
|
|
||||||
self.dat = parse.0;
|
if parse.is_ok() {
|
||||||
Some(parse.1)
|
let parse = parse.unwrap();
|
||||||
|
|
||||||
|
self.dat = parse.0;
|
||||||
|
Some(parse.1)
|
||||||
|
}else{
|
||||||
|
if self.done {
|
||||||
|
None
|
||||||
|
}else{
|
||||||
|
self.done = true;
|
||||||
|
Some(Output::TextBlock(std::str::from_utf8(self.dat)
|
||||||
|
.unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterate_on<'a>(bytes: &'a[u8]) -> ParserIterator<'a> {
|
pub fn iterate_on<'a>(bytes: &'a str) -> ParserIterator<'a> {
|
||||||
ParserIterator {
|
ParserIterator {
|
||||||
dat: bytes
|
dat: bytes.as_bytes(),
|
||||||
|
done: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,8 +35,7 @@ fn test_reset_mode() {
|
|||||||
fn test_parser_iterator() {
|
fn test_parser_iterator() {
|
||||||
let parse_str = "Hello, world? How are \x27[=7lyou? I hope you're doing well.";
|
let parse_str = "Hello, world? How are \x27[=7lyou? I hope you're doing well.";
|
||||||
|
|
||||||
let strings: Vec<Output> = iterate_on(parse_str.as_bytes())
|
let strings: Vec<Output> = iterate_on(parse_str)
|
||||||
.take(2)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
println!("{:#?}", strings);
|
println!("{:#?}", strings);
|
||||||
|
Reference in New Issue
Block a user