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

Function parse_quoted_string

cel/src/parser/parse.rs:250–362  ·  view source on GitHub ↗
(
    s: &str,
    mut chars: &mut Enumerate<Chars>,
    mut res: String,
    quote: char,
)

Source from the content-addressed store, hash-verified

248}
249
250fn parse_quoted_string(
251 s: &str,
252 mut chars: &mut Enumerate<Chars>,
253 mut res: String,
254 quote: char,
255) -> Result<String, ParseSequenceError> {
256 let mut in_single_quotes = quote == '\'';
257 let mut in_double_quotes = quote == '"';
258
259 while let Some((idx, c)) = chars.next() {
260 let in_quotes = in_single_quotes || in_double_quotes;
261
262 if c == '\\' && in_quotes {
263 match chars.next() {
264 None => {
265 return Err(ParseSequenceError::InvalidEscape {
266 escape: format!("{c}"),
267 index: idx,
268 string: String::from(s),
269 });
270 }
271 Some((idx, c2)) => {
272 let mut push_escape_character = false;
273
274 let value = match c2 {
275 'a' => '\u{07}',
276 'b' => '\u{08}',
277 'v' => '\u{0B}',
278 'f' => '\u{0C}',
279 'n' => '\n',
280 'r' => '\r',
281 't' => '\t',
282 '\\' => c2,
283 '?' => c2,
284 '\'' => {
285 push_escape_character = in_double_quotes;
286 c2
287 }
288 '"' => {
289 push_escape_character = in_single_quotes;
290 c2
291 }
292 '`' => c2,
293 'x' | 'u' | 'U' => {
294 let length = match c2 {
295 'x' => 2,
296 'u' => 4,
297 'U' => 8,
298 _ => unreachable!(),
299 };
300
301 parse_unicode_hex(length, &mut chars).map_err(|x| {
302 ParseSequenceError::InvalidUnicode {
303 source: x.clone(),
304 index: idx,
305 string: String::from(s),
306 }
307 })?

Callers 1

parse_stringFunction · 0.85

Calls 6

parse_unicode_hexFunction · 0.85
parse_unicode_octFunction · 0.85
cloneMethod · 0.80
pushMethod · 0.80
nextMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected