This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/parse.sh

34 lines
684 B
Bash
Raw Normal View History

2023-10-30 03:49:10 +03:00
# parse data and output simplified format.
# usage: parse_simplify <STRING>
2023-12-05 23:56:04 +03:00
parse_simplify() {
2023-12-05 21:50:45 +03:00
echo "${*}" | \
sed -e "s/ /_/g" \
-e "s/[^[:alnum:]_-]//g" \
-e "s/_\+/_/g" -e "s/-\+/-/g" \
-e "s/_-/_/g" -e "s/-_/_/g" \
-e "s/_\+/_/g" \
-e "s/^_//" -e "s/_$//"
2023-10-30 03:49:10 +03:00
}
# Parse to CamelCase.
# Usage: parse_camel <STRING>
2023-12-05 23:56:04 +03:00
parse_camel() {
2023-12-05 21:50:45 +03:00
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
2023-11-30 04:53:57 +03:00
2023-12-05 21:50:45 +03:00
for part in "${parts[@]}"; do
local word="${part^}"
result="${result}${word}"
done
echo "${result}"
2023-11-30 04:53:57 +03:00
}
2023-10-30 03:49:10 +03:00
# parse data keeping only alphanumeric characters.
# usage: parse_alnum <STRING>
2023-12-05 23:56:04 +03:00
parse_alnum() {
2023-12-05 21:50:45 +03:00
echo "${*}" | \
sed -e "s/[^[:alnum:]]//g"
2023-10-30 03:49:10 +03:00
}