MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_octet

Method parse_octet

crates/ruff_python_parser/src/string.rs:187–204  ·  view source on GitHub ↗
(&mut self, o: u8)

Source from the content-addressed store, hash-verified

185 }
186
187 fn parse_octet(&mut self, o: u8) -> char {
188 let mut radix_bytes = [o, 0, 0];
189 let mut len = 1;
190
191 while len < 3 {
192 let Some(b'0'..=b'7') = self.peek_byte() else {
193 break;
194 };
195
196 radix_bytes[len] = self.next_byte().unwrap();
197 len += 1;
198 }
199
200 // OK because radix_bytes is always going to be in the ASCII range.
201 let radix_str = std::str::from_utf8(&radix_bytes[..len]).expect("ASCII bytes");
202 let value = u32::from_str_radix(radix_str, 8).unwrap();
203 char::from_u32(value).unwrap()
204 }
205
206 fn parse_unicode_name(&mut self) -> Result<char, LexicalError> {
207 let start_pos = self.position();

Callers 1

parse_escaped_charMethod · 0.80

Calls 3

peek_byteMethod · 0.80
next_byteMethod · 0.80
expectMethod · 0.80

Tested by

no test coverage detected