Compare commits

..

2 commits

3 changed files with 26 additions and 15 deletions

View file

@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
### 🐛 Bug Fixes
- PR comment emoji prefix detection - ([ed0fbc3](https://codeberg.org/ThetaDev/artifactview/commit/ed0fbc38b2a1e76f070697f766812a20c84149ee))
- PR comment emoji prefix detection - ([1e36edf](https://codeberg.org/ThetaDev/artifactview/commit/1e36edf49978e8ba24a85d4663ff3ebaf9642a29))
## [v0.4.1](https://codeberg.org/ThetaDev/artifactview/compare/v0.4.0..v0.4.1) - 2024-06-22

View file

@ -1,5 +1,4 @@
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
fmt::Write,
net::{IpAddr, SocketAddr},
@ -866,19 +865,7 @@ fn pr_comment_text(p: PrCommentTextParams) -> String {
};
let write_link_icon = |s: &mut String, title: &str, href: &str| {
// Move leading emoji into a prefix variable since including them in the link does not look good
let mut title_pfx = String::new();
let mut title = Cow::Borrowed(title);
if let Some((i, c)) = title
.char_indices()
.find(|(_, c)| c.is_ascii() || c.is_alphanumeric())
{
if i > 0 && c == ' ' {
title[..i + 1].clone_into(&mut title_pfx);
title = title[i + 1..].to_owned().into();
}
}
let (title_pfx, title) = util::split_icon_prefix(title);
_ = write!(
s,
r#"{title_pfx}<a href="{href}" target="_blank" rel="noopener noreferrer">{title}</a>"#,

View file

@ -302,6 +302,18 @@ pub fn extract_delim<'a>(s: &'a str, start: &str, end: &str) -> Option<&'a str>
None
}
pub fn split_icon_prefix(s: &str) -> (&str, &str) {
if let Some((i, c)) = s
.char_indices()
.find(|(_, c)| c.is_ascii() || c.is_alphanumeric())
{
if i > 0 && c == ' ' && s.get(i + 1..).is_some() {
return (&s[..i + 1], &s[i + 1..]);
}
}
("", s)
}
#[cfg(test)]
pub(crate) mod tests {
use std::path::{Path, PathBuf};
@ -390,4 +402,16 @@ pub(crate) mod tests {
let res = super::filename_ext(filename);
assert_eq!(res, expect);
}
#[rstest]
#[case("🧪 Test", ("🧪 ", "Test"))]
#[case("🧪👨‍👩‍👦 Test", ("🧪👨‍👩‍👦 ", "Test"))]
#[case("🧪 👨‍👩‍👦 Test", ("🧪 ", "👨‍👩‍👦 Test"))]
#[case("", ("", ""))]
#[case("Test", ("", "Test"))]
#[case("運命 Test", ("", "運命 Test"))]
fn split_icon_prefix(#[case] s: &str, #[case] expect: (&str, &str)) {
let res = super::split_icon_prefix(s);
assert_eq!(res, expect);
}
}