|
6 | 6 | /// After successful search the parser will return [`Some`] with position where |
7 | 7 | /// processing instruction is ended (the position after `?>`). If search was |
8 | 8 | /// unsuccessful, a [`None`] will be returned. You typically would expect positive |
9 | | -/// result of search, so that you should feed new data until yo'll get it. |
| 9 | +/// result of search, so that you should feed new data until you get it. |
10 | 10 | /// |
11 | 11 | /// NOTE: after successful match the parser does not returned to the initial |
12 | 12 | /// state and should not be used anymore. Create a new parser if you want to perform |
|
25 | 25 | /// // ...get new chunk of data |
26 | 26 | /// assert_eq!(parser.feed(b" with = 'some > and ?"), None); |
27 | 27 | /// // ...get another chunk of data |
28 | | -/// assert_eq!(parser.feed(b"' inside?>and the text follow..."), Some(10)); |
29 | | -/// // ^ ^ |
30 | | -/// // 0 10 |
| 28 | +/// assert_eq!(parser.feed(b"' inside?>and the text follow..."), Some(9)); |
| 29 | +/// // ^ ^ |
| 30 | +/// // 0 9 |
31 | 31 | /// ``` |
32 | 32 | /// |
33 | 33 | /// [`feed`]: Self::feed() |
@@ -56,11 +56,9 @@ impl PiParser { |
56 | 56 | pub fn feed(&mut self, bytes: &[u8]) -> Option<usize> { |
57 | 57 | for i in memchr::memchr_iter(b'>', bytes) { |
58 | 58 | match i { |
59 | | - // +1 for `>` which should be included in event |
60 | | - 0 if self.0 => return Some(1), |
| 59 | + 0 if self.0 => return Some(0), |
61 | 60 | // If the previous byte is `?`, then we found `?>` |
62 | | - // +1 for `>` which should be included in event |
63 | | - i if i > 0 && bytes[i - 1] == b'?' => return Some(i + 1), |
| 61 | + i if i > 0 && bytes[i - 1] == b'?' => return Some(i), |
64 | 62 | _ => {} |
65 | 63 | } |
66 | 64 | } |
@@ -95,11 +93,11 @@ fn pi() { |
95 | 93 | assert_eq!(parse_pi(b"?", true), Err(true)); // ?|? |
96 | 94 |
|
97 | 95 | assert_eq!(parse_pi(b">", false), Err(false)); // x|> |
98 | | - assert_eq!(parse_pi(b">", true), Ok(1)); // ?|> |
| 96 | + assert_eq!(parse_pi(b">", true), Ok(0)); // ?|> |
99 | 97 |
|
100 | | - assert_eq!(parse_pi(b"?>", false), Ok(2)); // x|?> |
101 | | - assert_eq!(parse_pi(b"?>", true), Ok(2)); // ?|?> |
| 98 | + assert_eq!(parse_pi(b"?>", false), Ok(1)); // x|?> |
| 99 | + assert_eq!(parse_pi(b"?>", true), Ok(1)); // ?|?> |
102 | 100 |
|
103 | | - assert_eq!(parse_pi(b">?>", false), Ok(3)); // x|>?> |
104 | | - assert_eq!(parse_pi(b">?>", true), Ok(1)); // ?|>?> |
| 101 | + assert_eq!(parse_pi(b">?>", false), Ok(2)); // x|>?> |
| 102 | + assert_eq!(parse_pi(b">?>", true), Ok(0)); // ?|>?> |
105 | 103 | } |
0 commit comments