use crate::Issue;
pub fn xml_encode(input: impl AsRef<str>) -> String {
let input = input.as_ref();
let mut result = String::with_capacity(input.len());
for c in input.chars() {
let next = match c {
'&' => "&",
'<' => "<",
'>' => ">",
'"' => """,
'\'' => "'",
'\n' => " ",
'\r' => " ",
_ => {
result.push(c);
continue;
}
};
result.push_str(next);
}
result
}
pub fn long_message(issue: &Issue, include_annotations: bool) -> String {
let mut message = issue.message.clone();
if include_annotations {
for annotation in &issue.annotations {
if let Some(annotation_msg) = annotation.message.as_ref() {
message.push('\n');
message.push('>');
message.push_str(annotation_msg.as_str());
}
}
}
if !issue.notes.is_empty() {
message.push('\n');
for note in &issue.notes {
message.push('\n');
message.push_str(note.as_str());
}
}
if let Some(help) = issue.help.as_ref() {
message.push_str("\n\nHelp: ");
message.push_str(help.as_str());
}
if let Some(link) = issue.link.as_ref() {
message.push_str("\n\nMore information: ");
message.push_str(link.as_str());
}
message
}
pub fn osc8_hyperlink(template: &str, abs_path: &str, line: u32, column: u32, display_text: &str) -> String {
let url = template
.replace("%file%", abs_path)
.replace("%line%", &line.to_string())
.replace("%column%", &column.to_string());
format!("\x1b]8;;{url}\x1b\\{display_text}\x1b]8;;\x1b\\")
}