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

Method parse_part

crates/common/src/format.rs:1096–1132  ·  view source on GitHub ↗
(
        chars: &mut impl PeekingNext<Item = CodePoint>,
    )

Source from the content-addressed store, hash-verified

1094
1095impl FieldNamePart {
1096 fn parse_part(
1097 chars: &mut impl PeekingNext<Item = CodePoint>,
1098 ) -> Result<Option<Self>, FormatParseError> {
1099 chars
1100 .next()
1101 .map(|ch| match ch.to_char_lossy() {
1102 '.' => {
1103 let mut attribute = Wtf8Buf::new();
1104 for ch in chars.peeking_take_while(|ch| *ch != '.' && *ch != '[') {
1105 attribute.push(ch);
1106 }
1107 if attribute.is_empty() {
1108 Err(FormatParseError::EmptyAttribute)
1109 } else {
1110 Ok(Self::Attribute(attribute))
1111 }
1112 }
1113 '[' => {
1114 let mut index = Wtf8Buf::new();
1115 for ch in chars {
1116 if ch == ']' {
1117 return if index.is_empty() {
1118 Err(FormatParseError::EmptyAttribute)
1119 } else if let Some(index) = parse_usize(&index) {
1120 Ok(Self::Index(index))
1121 } else {
1122 Ok(Self::StringIndex(index))
1123 };
1124 }
1125 index.push(ch);
1126 }
1127 Err(FormatParseError::MissingRightBracket)
1128 }
1129 _ => Err(FormatParseError::InvalidCharacterAfterRightBracket),
1130 })
1131 .transpose()
1132 }
1133}
1134
1135#[derive(Debug, PartialEq)]

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
AttributeClass · 0.85
parse_usizeFunction · 0.85
ErrClass · 0.50
IndexClass · 0.50
mapMethod · 0.45
nextMethod · 0.45
to_char_lossyMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected