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

Method parse_unicode_name

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

Source from the content-addressed store, hash-verified

204 }
205
206 fn parse_unicode_name(&mut self) -> Result<char, LexicalError> {
207 let start_pos = self.position();
208 let Some('{') = self.next_char() else {
209 return Err(LexicalError::new(
210 LexicalErrorType::MissingUnicodeLbrace,
211 TextRange::empty(start_pos),
212 ));
213 };
214
215 let start_pos = self.position();
216 let Some(close_idx) = self.source[self.cursor..].find('}') else {
217 return Err(LexicalError::new(
218 LexicalErrorType::MissingUnicodeRbrace,
219 TextRange::empty(self.compute_position(self.source.len())),
220 ));
221 };
222
223 let name_and_ending = self.skip_bytes(close_idx + 1);
224 let name = &name_and_ending[..name_and_ending.len() - 1];
225
226 unicode_names2::character(name).ok_or_else(|| {
227 LexicalError::new(
228 LexicalErrorType::UnicodeError,
229 // The cursor is right after the `}` character, so we subtract 1 to get the correct
230 // range of the unicode name.
231 TextRange::new(
232 start_pos,
233 self.compute_position(self.cursor - '}'.len_utf8()),
234 ),
235 )
236 })
237 }
238
239 /// Parse an escaped character, returning the new character.
240 fn parse_escaped_char(&mut self) -> Result<Option<EscapedChar>, LexicalError> {

Callers 1

parse_escaped_charMethod · 0.80

Calls 8

next_charMethod · 0.80
compute_positionMethod · 0.80
len_utf8Method · 0.80
emptyFunction · 0.50
positionMethod · 0.45
findMethod · 0.45
lenMethod · 0.45
skip_bytesMethod · 0.45

Tested by

no test coverage detected