diff --git a/.config/bash/module/Parse.sh b/.config/bash/module/Parse.sh index d0d63a1..4fd7c23 100644 --- a/.config/bash/module/Parse.sh +++ b/.config/bash/module/Parse.sh @@ -14,7 +14,7 @@ function parse_simplify() { # Usage: parse_pascal function parse_pascal() { local IFS=${IFS}_- - local parts=($(parse_simplify ${1})) + local parts=($(_get_parts ${*})) local result # If already in Pascal. @@ -36,7 +36,7 @@ function parse_pascal() { # Usage: parse_snake function parse_snake() { local IFS=${IFS}_- - local parts=($(parse_simplify ${1})) + local parts=($(_get_parts ${*})) local result for part in "${parts[@]}"; do @@ -51,7 +51,7 @@ function parse_snake() { # Usage: parse_kebab function parse_kebab() { local IFS=${IFS}_- - local parts=($(parse_simplify ${1})) + local parts=($(_get_parts ${*})) local result for part in "${parts[@]}"; do @@ -66,7 +66,7 @@ function parse_kebab() { # Usage: parse_camel function parse_camel() { local IFS=${IFS}_- - local parts=($(parse_simplify ${1})) + local parts=($(_get_parts ${*})) local result # If already in camel. @@ -88,7 +88,7 @@ function parse_camel() { # Usage: parse_snake_uppercase function parse_snake_uppercase() { local IFS=${IFS}_- - local parts=($(parse_simplify ${1})) + local parts=($(_get_parts ${*})) local result for part in "${parts[@]}"; do @@ -105,3 +105,15 @@ function parse_alnum() { echo "${*}" | \ sed -e "s/[^[:alnum:]]//g" } + +# Get name parts. +# Usage: _get_parts +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" +}