Function clean_alt_text

Source
fn clean_alt_text(alt: &str) -> String
Expand description

⚙️ Function: Cleans the alt text for an item or rune and applies special formatting.

This function processes the alt attribute text extracted from HTML elements, removes unwanted characters, and applies special rules. If the alt text contains certain characters (parentheses, hyphens, and plus signs), it returns “HealthScale”. Otherwise, it cleans the text by removing parentheses, numbers, and specific symbols.

§Parameters:

  • alt: A string slice representing the alt text from an HTML img tag that needs to be cleaned.

§Returns:

  • String: Returns a cleaned version of the alt text. If the alt text matches specific patterns (parentheses, hyphen, and plus signs), it returns “HealthScale”. Otherwise, it returns the cleaned text with unwanted characters removed.

§Example:

This function is typically called to clean the text from the alt attributes of item or rune images:

let clean_text = clean_alt_text("Health (100) + 10% - 5%");
println!("{}", clean_text); // Output: "HealthScale"

let clean_text = clean_alt_text("Sunfire Aegis");
println!("{}", clean_text); // Output: "SunfireAegis"

§Notes:

  • If the alt text contains parentheses (), a hyphen -, and a plus sign +, the function returns “HealthScale”.
  • It uses regular expressions to remove unwanted characters such as parentheses, numbers, percentage symbols, commas, and others.
  • Spaces are also removed in the final output.