mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
Eliminate common tails from branches
This commit is contained in:
parent
9232cafb66
commit
d43faa89f1
@ -256,17 +256,15 @@ pub fn trim<T: fmt::Display>(s: T) -> Result<String> {
|
|||||||
/// Limit string length, appends '...' if truncated
|
/// Limit string length, appends '...' if truncated
|
||||||
pub fn truncate<T: fmt::Display>(s: T, len: usize) -> Result<String> {
|
pub fn truncate<T: fmt::Display>(s: T, len: usize) -> Result<String> {
|
||||||
let mut s = s.to_string();
|
let mut s = s.to_string();
|
||||||
if s.len() <= len {
|
if s.len() > len {
|
||||||
Ok(s)
|
|
||||||
} else {
|
|
||||||
let mut real_len = len;
|
let mut real_len = len;
|
||||||
while !s.is_char_boundary(real_len) {
|
while !s.is_char_boundary(real_len) {
|
||||||
real_len += 1;
|
real_len += 1;
|
||||||
}
|
}
|
||||||
s.truncate(real_len);
|
s.truncate(real_len);
|
||||||
s.push_str("...");
|
s.push_str("...");
|
||||||
Ok(s)
|
|
||||||
}
|
}
|
||||||
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indent lines with `width` spaces
|
/// Indent lines with `width` spaces
|
||||||
|
@ -1453,12 +1453,10 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
|
|||||||
args: &[Expr],
|
args: &[Expr],
|
||||||
) -> Result<DisplayWrap, CompileError> {
|
) -> Result<DisplayWrap, CompileError> {
|
||||||
buf.write("(");
|
buf.write("(");
|
||||||
if self.locals.contains(&s) || s == "self" {
|
if !self.locals.contains(&s) && s != "self" {
|
||||||
buf.write(s);
|
|
||||||
} else {
|
|
||||||
buf.write("self.");
|
buf.write("self.");
|
||||||
buf.write(s);
|
|
||||||
}
|
}
|
||||||
|
buf.write(s);
|
||||||
buf.write(")(");
|
buf.write(")(");
|
||||||
self._visit_args(buf, args)?;
|
self._visit_args(buf, args)?;
|
||||||
buf.write(")");
|
buf.write(")");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user