Recognizes a [`Value::Single`] in a string slice. Calls [`Value::variable_character`] to handle escaped characters in `input`. # Examples ```text "This is a string value\" with escaped \\ characters" ``` # Errors Returns an error if no [`Value::Single`] is found in `input`.
(input: &mut &str)
| 186 | /// |
| 187 | /// Returns an error if no [`Value::Single`] is found in `input`. |
| 188 | pub fn parse_next_value(input: &mut &str) -> ModalResult<String> { |
| 189 | // We expect a value surrounded with double quotes (") that may contain escaped characters. |
| 190 | // As we resolve the escaping, we cannot just `.take()`. Instead we have to accumulate in |
| 191 | // a `String`. |
| 192 | let string_value = trace( |
| 193 | "variable", |
| 194 | preceded( |
| 195 | '"', |
| 196 | cut_err( |
| 197 | terminated( |
| 198 | repeat(0.., Self::variable_character).fold(String::new, |mut string, c| { |
| 199 | string.push(c); |
| 200 | string |
| 201 | }), |
| 202 | '"', |
| 203 | ) |
| 204 | .context(StrContext::Label("variable")) |
| 205 | .context(StrContext::Expected( |
| 206 | StrContextValue::Description("A string surrounded by double quotes"), |
| 207 | )), |
| 208 | ), |
| 209 | ), |
| 210 | ) |
| 211 | .parse_next(input)?; |
| 212 | |
| 213 | Ok(string_value) |
| 214 | } |
| 215 | |
| 216 | /// Recognizes a single [`char`] in a string slice. |
| 217 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected