-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.sh
54 lines (47 loc) · 721 Bytes
/
string.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
string_lower() {
tr '[:upper:]' '[:lower:]'
}
string_upper() {
tr '[:lower:]' '[:upper:]'
}
string_sub() {
local replace
local with
replace="$(echo "$1" | sed 's|/|\\/|g')"
with="$(echo "$2" | sed 's|/|\\/|g')"
sed 's/'"$replace"'/'"$with"'/'"${flags-}"
}
string_gsub() {
flags=g string_sub "$@"
}
# https://linuxize.com/post/how-to-check-if-string-contains-substring-in-bash/
string_includes() {
local r=1
case "$1" in
*"$2"*)
r=0
;;
esac
return "$r"
}
string_starts_with() {
local r=1
case "$1" in
"$2"*)
r=0
;;
esac
return "$r"
}
string_ends_with() {
local r=1
case "$1" in
*"$2")
r=0
;;
esac
return "$r"
}
string_strikethrough() {
sed "s/\(.\)/\1"$'\xcc\xb6'"/g"
}