Recognizes a [`Name`] in a string slice. Consumes all of its input. # Errors Returns an error if `input` contains an invalid _alpm-package-name_.
(input: &mut &str)
| 151 | } |
| 152 | } |
| 153 | |
| 154 | impl Name { |
| 155 | /// Recognizes a [`Name`] as part of an [`InstalledPackage`](`crate::InstalledPackage`). |
| 156 | /// |
| 157 | /// # Warning |
| 158 | /// |
| 159 | /// This parser is designed **specifically** for the internal |
| 160 | /// [`InstalledPackage`](`crate::InstalledPackage`) parser. |
| 161 | /// |
| 162 | /// [`InstalledPackage`](`crate::InstalledPackage`) is a very special use-case, as it uses |
| 163 | /// dashes (`-`) as delimiter. However, dashes are also valid characters in a [`Name`]. |
| 164 | /// As such, the [`Name`] parser must be aware of how many dashes are expected to be inside the |
| 165 | /// input string to parse. |
| 166 | /// |
| 167 | /// This is a necessary, albeit cursed hack due to |
| 168 | /// [`InstalledPackage`](`crate::InstalledPackage`)'s dash-based delimiter design. |
| 169 | /// |
| 170 | /// In contrast to [`Name::parser`], this function expects the final character to be a `-`, |
| 171 | /// which it **does not consume**. |
| 172 | /// |
| 173 | /// # Errors |
| 174 | /// |
| 175 | /// Returns an error if `input` does not begin with a valid [alpm-package-name]. |
| 176 | /// |
| 177 | /// [alpm-package-name]: https://alpm.archlinux.page/specifications/alpm-package-name.7.html |
| 178 | pub(crate) fn parse_name_followed_by_version<'a>( |
| 179 | delimiter_count: usize, |
| 180 | ) -> impl Parser<&'a str, Self, ErrMode<ContextError>> { |
| 181 | let never_first_char_list = ['_', '@', '+', '.']; |
| 182 | |
| 183 | let alphanum = |c: char| c.is_ascii_alphanumeric(); |
| 184 | let first_char = one_of((alphanum, Self::SPECIAL_FIRST_CHARS)) |
| 185 | .context(StrContext::Label("first character of package name")) |
| 186 | .context(StrContext::Expected(StrContextValue::Description( |
| 187 | "ASCII alphanumeric character", |
| 188 | ))) |
nothing calls this directly
no test coverage detected