MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / parse_string

Function parse_string

cel/src/parser/parse.rs:177–186  ·  view source on GitHub ↗

Parse the provided quoted string. This function was adopted from [snailquote](https://docs.rs/snailquote/latest/snailquote/). # Details Parses a single or double quoted string and interprets escape sequences such as '\n', '\r', '\'', etc. Supports raw strings prefixed with `r` or `R` in which case all escape sequences are ignored./// The full set of supported escapes between quotes may be foun

(s: &str)

Source from the content-addressed store, hash-verified

175/// The returned result can display a human readable error if the string cannot be parsed as a
176/// valid quoted string.
177pub fn parse_string(s: &str) -> Result<String, ParseSequenceError> {
178 let mut chars = s.chars().enumerate();
179 let res = String::with_capacity(s.len());
180
181 match chars.next() {
182 Some((_, c)) if c == 'r' || c == 'R' => parse_raw_string(&mut chars, res),
183 Some((_, c)) if c == '\'' || c == '"' => parse_quoted_string(s, &mut chars, res, c),
184 _ => Err(ParseSequenceError::MissingOpeningQuote),
185 }
186}
187
188fn parse_raw_string(
189 chars: &mut Enumerate<Chars>,

Calls 3

parse_raw_stringFunction · 0.85
parse_quoted_stringFunction · 0.85
nextMethod · 0.45