parse_update_entry

Function parse_update_entry 

Source
pub fn parse_update_entry(line: &str) -> Option<(String, String, String)>
Expand description

What: Parse a single update entry line in the format “name - old_version -> name - new_version”.

Inputs:

  • line: A trimmed line from the updates file

Output:

  • Some((name, old_version, new_version)) if parsing succeeds, None otherwise

Details:

  • Parses format: “name - old_version -> name - new_version
  • Returns None for empty lines or invalid formats
  • Uses rfind to find the last occurrence of “ - “ to handle package names that may contain dashes

§Examples

use pacsea::util::parse_update_entry;

// Parsing a standard package update line from `pacman -Spu` or similar output
let update_line = "linux - 6.10.1.arch1-1 -> linux - 6.10.2.arch1-1";
let parsed = parse_update_entry(update_line);
assert_eq!(parsed, Some(("linux".to_string(), "6.10.1.arch1-1".to_string(), "6.10.2.arch1-1".to_string())));

// Parsing an update for a package with a hyphen in its name (common in AUR)
let aur_update_line = "python-requests - 2.31.0-1 -> python-requests - 2.32.0-1";
let aur_parsed = parse_update_entry(aur_update_line);
assert_eq!(aur_parsed, Some(("python-requests".to_string(), "2.31.0-1".to_string(), "2.32.0-1".to_string())));

// Handling a malformed or empty line (returns None)
assert_eq!(parse_update_entry(""), None);
assert_eq!(parse_update_entry("invalid line"), None);