From d381768c8f08b5d2a3a1f00b84cb8f738fec6657 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