Skip to content
Snippets Groups Projects
Commit 1e3c825b authored by Kevin Daudt's avatar Kevin Daudt :computer:
Browse files

functions: add helpers to convert case

Posix shell can do a lot of things, but there is no native way to change
the case of a string. Some packages require this functionality, and they
use `tr` in a subshell to achieve that.

In the global scope of APKBUILDs we want to avoid exec in the global
scope. By providing helper functions, we can avoid this.

The functions only handle the basic ascii letters, which should suffice
for the usecases that are needed in APKBUILD files.
parent 4e2c1902
No related branches found
No related tags found
1 merge request!333functions: add helpers to convert case
Pipeline #266280 passed
......@@ -273,6 +273,26 @@ error2() {
printf " %s\n" "$1" >&2
}
lowercase() {
str=$1
for pair in Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz; do
orig=${pair:0:1}
repl=${pair:1:1}
str=${str//"$orig"/"$repl"}
done
echo "$str"
}
uppercase() {
str=$1
for pair in aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ; do
orig=${pair:0:1}
repl=${pair:1:1}
str=${str//"$orig"/"$repl"}
done
echo "$str"
}
set_xterm_title() {
if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then
printf "\033]0;$1\007" >&2
......
......@@ -7,7 +7,9 @@ init_tests \
funcs_check_missing_apk \
funcs_check_missing_git \
funcs_check_env_set_but_empty \
funcs_check_defconfig
funcs_check_defconfig \
funcs_check_lowercase \
funcs_check_uppercase
FUNCS=$(atf_get_srcdir)/../functions.sh
......@@ -85,3 +87,15 @@ funcs_check_defconfig_body() {
-o match:"envcflags" \
sh -e -c " . $FUNCS; echo \"\$CFLAGS\""
}
funcs_check_lowercase_body() {
atf_check \
-o match:"aabcdefghijklkmnopqrstuvwxyz" \
sh -e -c " . $FUNCS; lowercase 'AABCDEFGHIJKLKMNOPQRSTUVWXYZ'"
}
funcs_check_uppercase_body() {
atf_check \
-o match:"AABCDEFGHIJKLKMNOPQRSTUVWXYZ" \
sh -e -c " . $FUNCS; uppercase 'aabcdefghijklkmnopqrstuvwxyz'"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment