Parse : Simplify.
This commit is contained in:
parent
04ffbfe55a
commit
908c157eff
|
@ -61,7 +61,7 @@ function name_simple() {
|
|||
[[ "${ext#.}" = "${name}" ]] && ext=""
|
||||
|
||||
# Get new name.
|
||||
local new_name=$(parse_simplify "${name}")${ext,,}
|
||||
local new_name=$(echo "${name}" | parse_simplify)${ext,,}
|
||||
|
||||
# check if same name.
|
||||
[[ "${target}" = "${new_name}" ]] && return 0
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
_PARSE_ALLOWED_CHARS="_-"
|
||||
_PARSE_SPLIT_CHARS="\.\ _-"
|
||||
|
||||
# Parse data and output simplified format.
|
||||
# Usage: parse_simplify <STRING>
|
||||
function parse_simplify() {
|
||||
echo "${*}" | \
|
||||
sed -e "s/ /_/g" -e "s/\./_/g" \
|
||||
-e "s/[^[:alnum:]_-]//g" \
|
||||
echo "${*}" | sed \
|
||||
-e "s/[${_PARSE_SPLIT_CHARS}]/_/g" \
|
||||
-e "s/[^[:alnum:]${_PARSE_ALLOWED_CHARS}]//g" \
|
||||
-e "s/_\+/_/g" -e "s/-\+/-/g" \
|
||||
-e "s/_-/_/g" -e "s/-_/_/g" \
|
||||
-e "s/_\+/_/g" \
|
||||
|
@ -13,7 +16,6 @@ function parse_simplify() {
|
|||
# Parse to PascalCase.
|
||||
# Usage: parse_pascal <STRING>
|
||||
function parse_pascal() {
|
||||
local IFS=${IFS}_-
|
||||
local parts=($(_get_parts ${*}))
|
||||
local result
|
||||
|
||||
|
@ -29,7 +31,6 @@ function parse_pascal() {
|
|||
# Parse to snake_case.
|
||||
# Usage: parse_snake <STRING>
|
||||
function parse_snake() {
|
||||
local IFS=${IFS}_-
|
||||
local parts=($(_get_parts ${*}))
|
||||
local result
|
||||
|
||||
|
@ -44,7 +45,6 @@ function parse_snake() {
|
|||
# Parse to kebab-case.
|
||||
# Usage: parse_kebab <STRING>
|
||||
function parse_kebab() {
|
||||
local IFS=${IFS}_-
|
||||
local parts=($(_get_parts ${*}))
|
||||
local result
|
||||
|
||||
|
@ -59,7 +59,6 @@ function parse_kebab() {
|
|||
# Parse to camelCase.
|
||||
# Usage: parse_camel <STRING>
|
||||
function parse_camel() {
|
||||
local IFS=${IFS}_-
|
||||
local parts=($(_get_parts ${*}))
|
||||
local result
|
||||
|
||||
|
@ -75,7 +74,6 @@ function parse_camel() {
|
|||
# Parse to SNAKE_CASE_UPPERCASE.
|
||||
# Usage: parse_snake_uppercase <STRING>
|
||||
function parse_snake_uppercase() {
|
||||
local IFS=${IFS}_-
|
||||
local parts=($(_get_parts ${*}))
|
||||
local result
|
||||
|
||||
|
@ -97,11 +95,5 @@ function parse_alnum() {
|
|||
# Get name parts.
|
||||
# Usage: _get_parts <STRING>
|
||||
function _get_parts() {
|
||||
parse_simplify "${*}" | _split_uppercase
|
||||
}
|
||||
|
||||
# Split string by uppercase letters.
|
||||
# Usage: echo | _split_uppercase
|
||||
function _split_uppercase() {
|
||||
sed -e "s/[A-Z]/\n&/g"
|
||||
parse_simplify "${*}" | sed -e "s/[A-Z]/\n&/g" -e "s/[${_PARSE_SPLIT_CHARS}]/\n/g" | sed -e "1d" -e "/^$/d"
|
||||
}
|
||||
|
|
Reference in a new issue