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

Method parse_unicode_name

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

Source from the content-addressed store, hash-verified

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

Callers 1

parse_escaped_charMethod · 0.80

Calls 9

characterFunction · 0.85
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