| 1 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 2 | pub struct CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#<'a> { |
| 3 | iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#iter.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::Charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Chars#<'a>>, |
| 4 | linerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#line.: usize, |
| 5 | colrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#col.: usize, |
| 6 | } |
| 7 | |
| 8 | impl<'a> CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#<'a> { |
| 9 | pub fn new_with_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new_with_pos().(src: &'a str, (line, col): (usize, usize)) -> Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`] { |
| 10 | CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream# { |
| 11 | iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#iter.: src.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(), |
| 12 | linerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#line., |
| 13 | colrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#col., |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | pub fn newrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new().(src: &'a str) -> Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`] { |
| 18 | Selfrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]::new_with_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new_with_pos().(src, (1, 1)) |
| 19 | } |
| 20 | |
| 21 | pub fn next_ifrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]next_if().(&mut self, f: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(char) -> bool) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> { |
| 22 | let item = self.iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#iter..next_ifrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]next_if().(|&c| f(c)); |
| 23 | match item { |
| 24 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\n') => { |
| 25 | self.linerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#line. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 26 | self.colrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#col. = 1; |
| 27 | } |
| 28 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => self.colrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#col. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1, |
| 29 | _ => {} |
| 30 | } |
| 31 | item |
| 32 | } |
| 33 | |
| 34 | pub fn eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().(&mut self, expect_char: char) -> bool { |
| 35 | self.next_ifrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]next_if().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().expect_char).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 36 | } |
| 37 | |
| 38 | pub fn skip_to_newlinerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]skip_to_newline().(&mut self) { |
| 39 | while self.next_ifrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]next_if().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'\n').is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {} |
| 40 | } |
| 41 | |
| 42 | pub fn peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> { |
| 43 | self.iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#iter..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() |
| 44 | } |
| 45 | |
| 46 | pub fn get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(&self) -> (usize, usize) { |
| 47 | (self.linerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#line., self.colrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#col.) |
| 48 | } |
| 49 | |
| 50 | pub fn advancerust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]advance().(&mut self, n: usize) { |
| 51 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n { |
| 52 | self.next_ifrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]next_if().(|_| true); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | #[cfg(test)] |
| 58 | mod testrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/test/ { |
| 59 | use superrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/::*; |
| 60 | |
| 61 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 62 | fn test_iterrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/test/test_iter().() { |
| 63 | let mut stream = CharStreamrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/CharStream#::newrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]new().("12\n3\n"); |
| 64 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('1')); |
| 65 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('1')); |
| 66 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('2')); |
| 67 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('2')); |
| 68 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('\n')); |
| 69 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stream.peekrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]peek().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('3')); |
| 70 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(stream.eat_charrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]eat_char().('3')); |
| 71 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stream.get_posrust-analyzer cargo sudo-rs 0.2.14 sudoers/char_stream/impl#[`CharStream<'a>`]get_pos().(), (2, 2)); |
| 72 | } |
| 73 | } |