pub fn clean_gaussian_keywords(keywords: &str) -> StringExpand description
Cleans Gaussian keywords by removing comments and extra whitespace.
This function processes multi-line keyword strings to remove:
- Lines starting with ‘#’ (full-line comments)
- Inline comments (text after ‘#’ on the same line as valid keywords)
- Empty lines
- Leading and trailing whitespace from each line
The remaining valid keywords are joined with single spaces to create a clean string suitable for Gaussian route sections. If all content is filtered out (e.g., only comments), an empty string is returned, which is handled gracefully by the Gaussian header generation.
§Arguments
keywords- The raw keyword string that may contain comments and extra whitespace
§Returns
Returns a String containing cleaned keywords joined with single spaces.
Returns an empty string if no valid keywords remain after filtering.
§Examples
use omecp::io;
let raw_keywords = "# This is a comment\nTD(NStates=5)\n# Another comment\nRoot=1\n\n";
let cleaned = io::clean_gaussian_keywords(raw_keywords);
assert_eq!(cleaned, "TD(NStates=5) Root=1");
// Empty result when only comments are present
let only_comments = "# Only comments\n# More comments";
let empty_result = io::clean_gaussian_keywords(only_comments);
assert_eq!(empty_result, "");
// Inline comments are removed
let inline_comments = "TD(NStates=5) # This is an inline comment\nRoot=1 # Another inline comment";
let cleaned_inline = io::clean_gaussian_keywords(inline_comments);
assert_eq!(cleaned_inline, "TD(NStates=5) Root=1");