Find the next occurrence of this separator in the given bytes. Returns the index of the start of the separator, or None if not found.
(&self, haystack: &[u8])
| 110 | /// |
| 111 | /// Returns the index of the start of the separator, or None if not found. |
| 112 | fn find_in(&self, haystack: &[u8]) -> Option<usize> { |
| 113 | match self { |
| 114 | Separator::Newline => haystack.iter().position(|&b| b == b'\n'), |
| 115 | Separator::Byte(b) => haystack.iter().position(|&x| x == *b), |
| 116 | Separator::CrLf => { |
| 117 | // Find \r\n sequence |
| 118 | if haystack.len() < 2 { |
| 119 | return None; |
| 120 | } |
| 121 | haystack.windows(2).position(|window| window == b"\r\n") |
| 122 | } |
| 123 | Separator::Custom(needle) => { |
| 124 | if needle.is_empty() || needle.len() > haystack.len() { |
| 125 | return None; |
| 126 | } |
| 127 | // Simple substring search |
| 128 | haystack |
| 129 | .windows(needle.len()) |
| 130 | .position(|window| window == needle.as_slice()) |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /// An iterator that splits content into lines based on a separator. |