added stringTrim function to trim off white-space characters grml0.9
authorMichael Gebetsroither <michael.geb@gmx.at>
Tue, 18 Apr 2006 12:19:17 +0000 (14:19 +0200)
committerMichael Gebetsroither <michael.geb@gmx.at>
Tue, 18 Apr 2006 12:19:17 +0000 (14:19 +0200)
sh-lib

diff --git a/sh-lib b/sh-lib
index 85d3c56..5d0ac5b 100644 (file)
--- 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
 {