From ca40690faf40a28d31777061d5055e55d7e8b0cd Mon Sep 17 00:00:00 2001 From: Michael Gebetsroither Date: Tue, 18 Apr 2006 14:19:17 +0200 Subject: [PATCH] added stringTrim function to trim off white-space characters --- sh-lib | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sh-lib b/sh-lib index 85d3c56..5d0ac5b 100644 --- a/sh-lib +++ b/sh-lib @@ -370,6 +370,26 @@ function relToAbs echo "$abspath_" } + +# Trim off white-space characters +# white-space in the "C" and "POSIX" locales are: +# space +# form-feed ('\f') +# newline ('\n') +# carriage return ('\r') +# horizontal tab ('\t') +# vertical tab ('\v') +function stringTrim +{ + local str_="$1" + local result_="" + + result_="`echo "$str_" | sed -e 's/^\s*//' -e 's/\s*$//'`" || \ + warn "stringTrim(): Problems stripping of blanks" || return 1 + dprint "stringTrim(): \"$str_\" => \"$result_\"" + echo "$result_" +} + # Simple shell grep function stringInFile { -- 2.1.4