]> git.stg.codes - stg.git/blob - functest/functions
Fix sgauth build (css embedding).
[stg.git] / functest / functions
1 trim()
2 {
3     printf "$1" | sed -e 's/^ *//' -e 's/ *$//'
4 }
5
6 getField()
7 {
8     NAME="$1"
9     DATA="$2"
10
11     printf "$DATA" | grep "$NAME" > /dev/null 2> /dev/null
12     if [ "$?" != "0" ]
13     then
14         return 1
15     fi
16
17     trim `printf "$DATA" | cut -d: -f2`
18 }
19
20 getFields()
21 {
22     NAME=$1
23     DATA=$2
24
25     IFS=`printf '\n+'`
26     for LINE in $DATA
27     do
28         VALUE=`getField $NAME $LINE` && printf "%s\n" "$VALUE"
29     done
30 }
31
32 count()
33 {
34     if [ "$1" == "" ]
35     then
36         printf "0"
37     else
38         RES=`printf "$1\n" | wc -l`
39         RES=`trim "$RES"`
40         printf "$RES"
41     fi
42 }
43
44 subst()
45 {
46     sed -i "s|$1|$2|g" "$3" 2> /dev/null || sed -i "" "s|$1|$2|g" "$3"
47 }