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–185  ·  view source on GitHub ↗
(&mut self, literal_number: usize)

Source from the content-addressed store, hash-verified

154 }
155
156 fn parse_unicode_literal(&mut self, literal_number: usize) -> Result<char, LexicalError> {
157 let mut p: u32 = 0u32;
158 for i in 1..=literal_number {
159 let start = self.position();
160 match self.next_char() {
161 Some(c) => match c.to_digit(16) {
162 Some(d) => p += d << ((literal_number - i) * 4),
163 None => {
164 return Err(LexicalError::new(
165 LexicalErrorType::UnicodeError,
166 TextRange::at(start, TextSize::try_from(c.len_utf8()).unwrap()),
167 ));
168 }
169 },
170 None => {
171 return Err(LexicalError::new(
172 LexicalErrorType::UnicodeError,
173 TextRange::empty(self.position()),
174 ));
175 }
176 }
177 }
178 match p {
179 0xD800..=0xDFFF => Ok(std::char::REPLACEMENT_CHARACTER),
180 _ => std::char::from_u32(p).ok_or(LexicalError::new(
181 LexicalErrorType::UnicodeError,
182 TextRange::empty(self.position()),
183 )),
184 }
185 }
186
187 fn parse_octet(&mut self, o: u8) -> char {
188 let mut radix_bytes = [o, 0, 0];

Callers 1

parse_escaped_charMethod · 0.80

Calls 5

OkClass · 0.85
next_charMethod · 0.80
len_utf8Method · 0.80
emptyFunction · 0.50
positionMethod · 0.45

Tested by

no test coverage detected