35 lines
669 B
Bash
35 lines
669 B
Bash
# parse data and output simplified format.
|
|
# usage: parse_simplify <STRING>
|
|
parse_simplify()
|
|
{
|
|
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/_$//"
|
|
}
|
|
|
|
parse_camel()
|
|
{
|
|
local IFS=${IFS}_-
|
|
local parts=($(parse_simplify ${1}))
|
|
local result
|
|
|
|
for part in "${parts[@]}"; do
|
|
local word="${part^}"
|
|
result="${result}${word}"
|
|
done
|
|
|
|
echo "${result}"
|
|
}
|
|
|
|
# parse data keeping only alphanumeric characters.
|
|
# usage: parse_alnum <STRING>
|
|
parse_alnum()
|
|
{
|
|
echo "${*}" | \
|
|
sed -e "s/[^[:alnum:]]//g"
|
|
}
|