MCPcopy Create free account
hub / github.com/davidblewett/rure-python / parse_octal

Method parse_octal

regex/regex-syntax/src/ast/parse.rs:1539–1566  ·  view source on GitHub ↗

Parse an octal representation of a Unicode codepoint up to 3 digits long. This expects the parser to be positioned at the first octal digit and advances the parser to the first character immediately following the octal number. This also assumes that parsing octal escapes is enabled. Assuming the preconditions are met, this routine can never fail.

(&self)

Source from the content-addressed store, hash-verified

1537 ///
1538 /// Assuming the preconditions are met, this routine can never fail.
1539 fn parse_octal(&self) -> ast::Literal {
1540 use std::char;
1541 use std::u32;
1542
1543 assert!(self.parser().octal);
1544 assert!('0' <= self.char() && self.char() <= '7');
1545 let start = self.pos();
1546 // Parse up to two more digits.
1547 while
1548 self.bump() &&
1549 '0' <= self.char() && self.char() <= '7' &&
1550 self.pos().offset - start.offset <= 2
1551 {}
1552 let end = self.pos();
1553 let octal = &self.pattern()[start.offset..end.offset];
1554 // Parsing the octal should never fail since the above guarantees a
1555 // valid number.
1556 let codepoint =
1557 u32::from_str_radix(octal, 8).expect("valid octal number");
1558 // The max value for 3 digit octal is 0777 = 511 and [0, 511] has no
1559 // invalid Unicode scalar values.
1560 let c = char::from_u32(codepoint).expect("Unicode scalar value");
1561 ast::Literal {
1562 span: Span::new(start, end),
1563 kind: ast::LiteralKind::Octal,
1564 c: c,
1565 }
1566 }
1567
1568 /// Parse a hex representation of a Unicode codepoint. This handles both
1569 /// hex notations, i.e., `\xFF` and `\x{FFFF}`. This expects the parser to

Callers 1

parse_escapeMethod · 0.80

Calls 4

bumpMethod · 0.80
posMethod · 0.45
charMethod · 0.45
patternMethod · 0.45

Tested by

no test coverage detected