|
|
@ -428,9 +428,10 @@ pub fn get_tree<'a>( |
|
|
|
lazy_static! { |
|
|
|
lazy_static! { |
|
|
|
static ref APP_NAME_AND_VERSION_RX: regex::Regex = |
|
|
|
static ref APP_NAME_AND_VERSION_RX: regex::Regex = |
|
|
|
regex::Regex::new("(.+)(-[0-9.]+)").unwrap(); |
|
|
|
regex::Regex::new("(.+)(-[0-9.]+)").unwrap(); |
|
|
|
static ref PLACEHOLDER_RX: regex::Regex = |
|
|
|
static ref PLACEHOLDER_RX: regex::Regex = regex::Regex::new( |
|
|
|
regex::Regex::new(r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\}))?\}") |
|
|
|
r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\})(?P<ellipsis>…)?)?\}" |
|
|
|
.unwrap(); |
|
|
|
) |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn maybe_html_escape(do_it: bool, text: String) -> String { |
|
|
|
fn maybe_html_escape(do_it: bool, text: String) -> String { |
|
|
@ -530,7 +531,12 @@ impl DisplayFormat for DisplayNode<'_> { |
|
|
|
_ => caps[0].to_string(), |
|
|
|
_ => caps[0].to_string(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
let fmt_str = caps.name("fmtstr").map_or("{}", |m| m.as_str()); |
|
|
|
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() |
|
|
|
.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(), "…"); |
|
|
|
|
|
|
|
} |
|
|
|