ok/jj
1
0
Fork 0
forked from mirrors/jj

templater: move split_email() to text_util module

It's not specific to templating.
This commit is contained in:
Yuya Nishihara 2023-03-12 20:00:38 +09:00
parent 63b3c0899a
commit b380ca0cf7
2 changed files with 9 additions and 9 deletions

View file

@ -854,14 +854,6 @@ pub fn expect_arguments<'a, 'i, const N: usize, const M: usize>(
}
}
fn split_email(email: &str) -> (&str, Option<&str>) {
if let Some((username, rest)) = email.split_once('@') {
(username, Some(rest))
} else {
(email, None)
}
}
fn build_method_call<'a, L: TemplateLanguage<'a>>(
language: &L,
method: &MethodCallNode,
@ -982,7 +974,7 @@ fn build_signature_method<'a, L: TemplateLanguage<'a>>(
"username" => {
expect_no_arguments(function)?;
language.wrap_string(TemplateFunction::new(self_property, |signature| {
let (username, _) = split_email(&signature.email);
let (username, _) = text_util::split_email(&signature.email);
username.to_owned()
}))
}

View file

@ -24,6 +24,14 @@ pub fn complete_newline(s: impl Into<String>) -> String {
s
}
pub fn split_email(email: &str) -> (&str, Option<&str>) {
if let Some((username, rest)) = email.split_once('@') {
(username, Some(rest))
} else {
(email, None)
}
}
/// Indents each line by the given prefix preserving labels.
pub fn write_indented(
formatter: &mut dyn Formatter,