Parse : Also split by uppercase letters.
This commit is contained in:
parent
6e471f3692
commit
c00fdc84b4
|
@ -14,7 +14,7 @@ function parse_simplify() {
|
|||
# Usage: parse_pascal <STRING>
|
||||
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 <STRING>
|
||||
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 <STRING>
|
||||
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 <STRING>
|
||||
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 <STRING>
|
||||
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 <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"
|
||||
}
|
||||
|
|
Reference in a new issue