summaryrefslogtreecommitdiffstats
path: root/helper/string.inc
blob: 077f1719e85cd9f91029210efc668c547efbbb32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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]'
}