From 41940806db00e283fa34f92c421aa3e1b4e5bce7 Mon Sep 17 00:00:00 2001 From: uriel Date: Wed, 26 Nov 2008 04:50:03 +0100 Subject: [PATCH] New helper function: crop_text --- bin/cgilib.rc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/cgilib.rc b/bin/cgilib.rc index 1dc3ad3..1bc9cc3 100644 --- a/bin/cgilib.rc +++ b/bin/cgilib.rc @@ -94,6 +94,20 @@ BEGIN { ' } +fn crop_text { + max_chars = $0 + awk -v max'='^$max_chars^' ' ' + { + nc += 1 + length; + if(nc > max) { + print substr($0, 1, nc - max) "..." + exit + } + print + }' +} + + # Cookies fn set_cookie { # TODO: should check input values more carefully