MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_spec

Method parse_spec

crates/common/src/format.rs:1293–1332  ·  view source on GitHub ↗
(text: &Wtf8)

Source from the content-addressed store, hash-verified

1291 }
1292
1293 fn parse_spec(text: &Wtf8) -> Result<(FormatPart, &Wtf8), FormatParseError> {
1294 let mut nested = false;
1295 let mut end_bracket_pos = None;
1296 let mut left = Wtf8Buf::new();
1297
1298 // There may be one layer nesting brackets in spec
1299 for (idx, c) in text.code_point_indices() {
1300 if idx == 0 {
1301 if c != '{' {
1302 return Err(FormatParseError::MissingStartBracket);
1303 }
1304 } else if c == '{' {
1305 if nested {
1306 return Err(FormatParseError::InvalidFormatSpecifier);
1307 } else {
1308 nested = true;
1309 left.push(c);
1310 continue;
1311 }
1312 } else if c == '}' {
1313 if nested {
1314 nested = false;
1315 left.push(c);
1316 continue;
1317 } else {
1318 end_bracket_pos = Some(idx);
1319 break;
1320 }
1321 } else {
1322 left.push(c);
1323 }
1324 }
1325 if let Some(pos) = end_bracket_pos {
1326 let right = &text[pos..];
1327 let format_part = Self::parse_part_in_brackets(&left)?;
1328 Ok((format_part, &right[1..]))
1329 } else {
1330 Err(FormatParseError::UnmatchedBracket)
1331 }
1332 }
1333}
1334
1335pub trait FromTemplate<'a>: Sized {

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
code_point_indicesMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
pushMethod · 0.45

Tested by

no test coverage detected