Fix bug in crop_text and make length argument optional (default is 512 chars).

This commit is contained in:
Uriel 2009-02-13 23:18:34 +00:00
parent 1c4d6ff8bd
commit 89682cafa1

View file

@ -160,16 +160,21 @@ fn ll_add {
NEW_LINE='
'
# crop_text [max_lenght [ellipsis]]
# TODO: Option to crop only at word-delimiters.
fn crop_text {
ellipsis='...'
if(~ $#* 2)
ellipsis=$2
m=512
e='...'
if(! ~ $#1 0)
m=$1
if(! ~ $#2 0)
e=$2
awk -v max'='^$"1^' ' -v 'ellipsis='$ellipsis '
awk -v 'max='^$"m -v 'ellipsis='$e '
{
nc += 1 + length;
if(nc > max) {
print substr($0, 1, nc - max) ellipsis
print substr($0, 1, nc - max) " " ellipsis
exit
}
print