|
|
|
@ -428,9 +428,10 @@ pub fn get_tree<'a>( |
|
|
|
|
lazy_static! { |
|
|
|
|
static ref APP_NAME_AND_VERSION_RX: regex::Regex = |
|
|
|
|
regex::Regex::new("(.+)(-[0-9.]+)").unwrap(); |
|
|
|
|
static ref PLACEHOLDER_RX: regex::Regex = |
|
|
|
|
regex::Regex::new(r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\}))?\}") |
|
|
|
|
.unwrap(); |
|
|
|
|
static ref PLACEHOLDER_RX: regex::Regex = regex::Regex::new( |
|
|
|
|
r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\})(?P<ellipsis>…)?)?\}" |
|
|
|
|
) |
|
|
|
|
.unwrap(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn maybe_html_escape(do_it: bool, text: String) -> String { |
|
|
|
@ -530,7 +531,12 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
|
_ => caps[0].to_string(), |
|
|
|
|
}; |
|
|
|
|
let fmt_str = caps.name("fmtstr").map_or("{}", |m| m.as_str()); |
|
|
|
|
maybe_html_escape(html_escape, rtfmt::format(fmt_str, &value)) |
|
|
|
|
let ellipsis = caps.name("ellipsis").is_some(); |
|
|
|
|
|
|
|
|
|
maybe_html_escape( |
|
|
|
|
html_escape, |
|
|
|
|
rtfmt::format(fmt_str, &value, ellipsis), |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
.into() |
|
|
|
|
} |
|
|
|
@ -561,3 +567,21 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_placeholder_rx() { |
|
|
|
|
let caps = PLACEHOLDER_RX.captures("Hello, {place}!").unwrap(); |
|
|
|
|
assert_eq!(caps.name("name").unwrap().as_str(), "place"); |
|
|
|
|
assert_eq!(caps.name("fmtstr"), None); |
|
|
|
|
assert_eq!(caps.name("ellipsis"), None); |
|
|
|
|
|
|
|
|
|
let caps = PLACEHOLDER_RX.captures("Hi, {place:{:>10.10}}!").unwrap(); |
|
|
|
|
assert_eq!(caps.name("name").unwrap().as_str(), "place"); |
|
|
|
|
assert_eq!(caps.name("fmtstr").unwrap().as_str(), "{:>10.10}"); |
|
|
|
|
assert_eq!(caps.name("ellipsis"), None); |
|
|
|
|
|
|
|
|
|
let caps = PLACEHOLDER_RX.captures("Hello, {place:{:.5}…}!").unwrap(); |
|
|
|
|
assert_eq!(caps.name("name").unwrap().as_str(), "place"); |
|
|
|
|
assert_eq!(caps.name("fmtstr").unwrap().as_str(), "{:.5}"); |
|
|
|
|
assert_eq!(caps.name("ellipsis").unwrap().as_str(), "…"); |
|
|
|
|
} |
|
|
|
|