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

Function parse_unicode_oct

cel/src/parser/parse.rs:378–398  ·  view source on GitHub ↗
(first_char: &char, chars: &mut I)

Source from the content-addressed store, hash-verified

376}
377
378fn parse_unicode_oct<I>(first_char: &char, chars: &mut I) -> Result<char, ParseUnicodeError>
379where
380 I: Iterator<Item = (usize, char)>,
381{
382 let mut unicode_seq: String = String::with_capacity(3);
383 unicode_seq.push(*first_char);
384 chars.take(2).for_each(|(_, c)| unicode_seq.push(c));
385
386 u32::from_str_radix(&unicode_seq, 8)
387 .map_err(|e| ParseUnicodeError::Oct {
388 source: e,
389 string: unicode_seq,
390 })
391 .and_then(|u| {
392 if u <= 255 {
393 char::from_u32(u).ok_or(ParseUnicodeError::Unicode { value: u })
394 } else {
395 Err(ParseUnicodeError::Unicode { value: u })
396 }
397 })
398}
399
400#[cfg(test)]
401mod tests {

Callers 1

parse_quoted_stringFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected