Fix bug in crop_text, and allow to set the 'ellipsis' text ('...' by default)

This commit is contained in:
uriel 2008-12-12 02:25:10 +01:00
parent f1df14a011
commit 86c55df5ec

View File

@ -95,12 +95,17 @@ BEGIN {
}
fn crop_text {
max_chars = $0
awk -v max'='^$max_chars^' ' '
max_chars = $1
ellipsis = '...'
if(~ $#* 2)
ellipsis = $2
awk -v max'='^$"max_chars^' ' -v 'ellipsis='$ellipsis '
{
nc += 1 + length;
if(nc > max) {
print substr($0, 1, nc - max) "..."
print substr($0, 1, nc - max) ellipsis
exit
}
print