Skip to content

Commit

Permalink
feat(macro): add uppercase/lowercase/sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
tueda committed Jan 7, 2024
1 parent 15d140d commit 8592b24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ assert_true = \
assert_false = \
$(if $(strip $1),false,:)

assert_eq = \
$(if $(and $(findstring $1,$2),$(findstring $2,$1)),echo '$1==$2';:,echo '$1!=$2';false)

assert_success = \
$(strip $1)

Expand Down Expand Up @@ -448,6 +451,18 @@ has_gnu_grep_impl = $(strip \
rule_exists = \
$(shell $(MAKE) -n $1 >/dev/null 2>&1 && echo 1)

# $(call uppercase,STR) converts STR to uppercase.
uppercase = \
$(shell echo '$1' | tr a-z A-Z)

# $(call lowercase,STR) converts STR to lowercase.
lowercase = \
$(shell echo '$1' | tr A-Z a-z)

# $(call sanitize,STR) replaces special characters in STR with underscores.
sanitize = \
$(shell echo '$1' | sed 's/[^a-zA-Z0-9]/_/g')

# $(init_toolchain) initializes the toolchain.
init_toolchain = $(call cache,init_toolchain_impl)

Expand Down
9 changes: 9 additions & 0 deletions tests/macro/latex.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ test_mv_target:
$(call assert_success,$(call mv_target,1.tmp))
$(call assert_fail, $(call mv_target,2.tmp))
$(call assert_success,$(call mv_target,3.tmp,false))

test_uppercase:
$(call assert_eq,$(call uppercase,abcxyzABCXYZ0189 !"#%&*+-./x:;<=>?@x[]^_`x{|}~x y),ABCXYZABCXYZ0189 !"#%&*+-./X:;<=>?@X[]^_`X{|}~X Y)

test_lowercase:
$(call assert_eq,$(call lowercase,abcxyzABCXYZ0189 !"#%&*+-./X:;<=>?@X[]^_`X{|}~X Y),abcxyzabcxyz0189 !"#%&*+-./x:;<=>?@x[]^_`x{|}~x y)

test_sanitize:
$(call assert_eq,$(call sanitize,abcxyzABCXYZ0189 !"#%&*+-./x:;<=>?@x[]^_`x{|}~x y),abcxyzABCXYZ0189____________x_______x_____x____x__y)

0 comments on commit 8592b24

Please sign in to comment.