| New helper function: crop_text - swerc - anselm's simpler werc fork | |
| git clone git://git.suckless.org/swerc | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit bbc643c2cdc09a812c468c812355d95f8cdca4ae | |
| parent f246e544b722f233beed28730cb5b346124e1847 | |
| Author: [email protected] <unknown> | |
| Date: Wed, 26 Nov 2008 04:50:03 +0100 | |
| New helper function: crop_text | |
| Diffstat: | |
| M bin/cgilib.rc | 14 ++++++++++++++ | |
| 1 file changed, 14 insertions(+), 0 deletions(-) | |
| --- | |
| diff --git 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 | |
| + } | |
| + }' | |
| +} | |
| + | |
| + | |
| # Cookies | |
| fn set_cookie { | |
| # TODO: should check input values more carefully |