summaryrefslogtreecommitdiffstats
path: root/core/includes/helper/string.inc
diff options
context:
space:
mode:
Diffstat (limited to 'core/includes/helper/string.inc')
-rw-r--r--core/includes/helper/string.inc31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/includes/helper/string.inc b/core/includes/helper/string.inc
new file mode 100644
index 00000000..077f1719
--- /dev/null
+++ b/core/includes/helper/string.inc
@@ -0,0 +1,31 @@
+
+# usage: VAR=$(trim " string ")
+trim() {
+ local var=$1
+ var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
+ var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
+ echo -n "$var"
+}
+
+# Inline version of trim, use when piping
+itrim () {
+ sed -r 's/^\s+//g;s/\s+$//g'
+}
+
+escape_search() {
+ sed -e 's/[]\/()$*.^|[]/\\&/g'
+
+}
+
+escape_replace() {
+ sed -e 's/[\/&]/\\&/g'
+}
+
+tolower () {
+ tr '[A-Z]' '[a-z]'
+}
+
+toupper () {
+ tr '[a-z]' '[A-Z]'
+}
+