Skip to main content

split_name_email

Function split_name_email 

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

Parses “Name email@domain.com” format into separate components.

This utility handles common author/maintainer strings found in package manifests where the format combines a human-readable name with an email address in angle brackets.

§Arguments

  • s - A string potentially containing name and email in “Name <email>” format

§Returns

A tuple of (Option<String>, Option<String>) representing (name, email):

  • If \<email\> pattern found: name (trimmed, or None if empty) and email
  • If no pattern: trimmed input as name, None for email

§Examples

use provenant::parsers::utils::split_name_email;

// Full format
let (name, email) = split_name_email("John Doe <john@example.com>");
assert_eq!(name, Some("John Doe".to_string()));
assert_eq!(email, Some("john@example.com".to_string()));

// Email only in angle brackets
let (name, email) = split_name_email("<john@example.com>");
assert_eq!(name, None);
assert_eq!(email, Some("john@example.com".to_string()));

// Name only (no angle brackets)
let (name, email) = split_name_email("John Doe");
assert_eq!(name, Some("John Doe".to_string()));
assert_eq!(email, None);