Fix bug in crop_text and make length argument optional (default is 512 chars).
This commit is contained in:
parent
1c4d6ff8bd
commit
89682cafa1
1 changed files with 10 additions and 5 deletions
|
|
@ -160,16 +160,21 @@ fn ll_add {
|
||||||
NEW_LINE='
|
NEW_LINE='
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# crop_text [max_lenght [ellipsis]]
|
||||||
|
# TODO: Option to crop only at word-delimiters.
|
||||||
fn crop_text {
|
fn crop_text {
|
||||||
ellipsis='...'
|
m=512
|
||||||
if(~ $#* 2)
|
e='...'
|
||||||
ellipsis=$2
|
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;
|
nc += 1 + length;
|
||||||
if(nc > max) {
|
if(nc > max) {
|
||||||
print substr($0, 1, nc - max) ellipsis
|
print substr($0, 1, nc - max) " " ellipsis
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
print
|
print
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue