(text: &str)
| 55 | |
| 56 | #[cfg(feature = "cst")] |
| 57 | pub fn parse_string(text: &str) -> Result<Cow<'_, str>, ParseStringError> { |
| 58 | struct StringCharProvider<'a> { |
| 59 | text: &'a str, |
| 60 | byte_index: usize, |
| 61 | current_char: Option<char>, |
| 62 | chars: std::str::Chars<'a>, |
| 63 | } |
| 64 | |
| 65 | impl<'a> CharProvider<'a> for StringCharProvider<'a> { |
| 66 | fn current_char(&mut self) -> Option<char> { |
| 67 | self.current_char |
| 68 | } |
| 69 | |
| 70 | fn byte_index(&self) -> usize { |
| 71 | self.byte_index |
| 72 | } |
| 73 | |
| 74 | fn move_next_char(&mut self) -> Option<char> { |
| 75 | if let Some(current_char) = self.current_char { |
| 76 | self.byte_index += current_char.len_utf8(); |
| 77 | } |
| 78 | self.current_char = self.chars.next(); |
| 79 | self.current_char |
| 80 | } |
| 81 | |
| 82 | fn text(&self) -> &'a str { |
| 83 | self.text |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | let mut chars = text.chars(); |
| 88 | let mut provider = StringCharProvider { |
| 89 | text, |
| 90 | byte_index: 0, |
| 91 | current_char: chars.next(), |
| 92 | chars, |
| 93 | }; |
| 94 | |
| 95 | parse_string_with_char_provider(&mut provider) |
| 96 | } |
| 97 | |
| 98 | pub fn parse_string_with_char_provider<'a, T: CharProvider<'a>>( |
| 99 | chars: &mut T, |
no test coverage detected
searching dependent graphs…