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

Method parse_unicode_literal

crates/ruff_python_parser/src/string.rs:156–180  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

154 }
155
156 fn parse_unicode_literal<const N: usize>(&mut self) -> Result<char, LexicalError> {
157 let mut value = 0;
158 for _ in 0..N {
159 let Some(digit) = self
160 .peek_byte()
161 .and_then(|byte| char::from(byte).to_digit(16))
162 else {
163 let start = self.position();
164 self.next_char();
165 return Err(LexicalError::new(
166 LexicalErrorType::UnicodeError,
167 TextRange::new(start, self.position()),
168 ));
169 };
170 self.cursor += 1;
171 value = (value << 4) | digit;
172 }
173 match value {
174 0xD800..=0xDFFF => Ok(std::char::REPLACEMENT_CHARACTER),
175 _ => std::char::from_u32(value).ok_or(LexicalError::new(
176 LexicalErrorType::UnicodeError,
177 TextRange::empty(self.position()),
178 )),
179 }
180 }
181
182 fn parse_octet(&mut self, o: u8) -> char {
183 let mut radix_bytes = [o, 0, 0];

Callers

nothing calls this directly

Calls 6

OkClass · 0.85
peek_byteMethod · 0.80
next_charMethod · 0.80
emptyFunction · 0.50
and_thenMethod · 0.45
positionMethod · 0.45

Tested by

no test coverage detected