Fix bug in crop_text, and allow to set the 'ellipsis' text ('...' by default)
This commit is contained in:
parent
f02b126611
commit
2a9dbdbfe9
1 changed files with 8 additions and 3 deletions
|
|
@ -95,12 +95,17 @@ BEGIN {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crop_text {
|
fn crop_text {
|
||||||
max_chars = $0
|
max_chars = $1
|
||||||
awk -v max'='^$max_chars^' ' '
|
|
||||||
|
ellipsis = '...'
|
||||||
|
if(~ $#* 2)
|
||||||
|
ellipsis = $2
|
||||||
|
|
||||||
|
awk -v max'='^$"max_chars^' ' -v 'ellipsis='$ellipsis '
|
||||||
{
|
{
|
||||||
nc += 1 + length;
|
nc += 1 + length;
|
||||||
if(nc > max) {
|
if(nc > max) {
|
||||||
print substr($0, 1, nc - max) "..."
|
print substr($0, 1, nc - max) ellipsis
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
print
|
print
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue