(
chars: &mut impl PeekingNext<Item = CodePoint>,
)
| 1094 | |
| 1095 | impl 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)] |
nothing calls this directly
no test coverage detected