forked from mirrors/jj
templater: move split_email() to text_util module
It's not specific to templating.
This commit is contained in:
parent
63b3c0899a
commit
b380ca0cf7
2 changed files with 9 additions and 9 deletions
|
@ -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()
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue