ref: 9628651f83bda70ced4e39880ae27a7a37856dc5
parent: e159c6478bb690e463c786dd993148ef4ade1741
author: sl <uriel@engel.se.cat-v.org>
date: Fri Feb 13 18:18:34 EST 2009
Fix bug in crop_text and make length argument optional (default is 512 chars).
--- a/bin/cgilib.rc
+++ b/bin/cgilib.rc
@@ -160,16 +160,21 @@
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
}