Parse : Also split by uppercase letters.

This commit is contained in:
Dmitry Voronin 2023-12-26 07:58:37 +03:00
parent 6e471f3692
commit c00fdc84b4

View file

@ -14,7 +14,7 @@ function parse_simplify() {
# Usage: parse_pascal <STRING> # Usage: parse_pascal <STRING>
function parse_pascal() { function parse_pascal() {
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(_get_parts ${*}))
local result local result
# If already in Pascal. # If already in Pascal.
@ -36,7 +36,7 @@ function parse_pascal() {
# Usage: parse_snake <STRING> # Usage: parse_snake <STRING>
function parse_snake() { function parse_snake() {
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(_get_parts ${*}))
local result local result
for part in "${parts[@]}"; do for part in "${parts[@]}"; do
@ -51,7 +51,7 @@ function parse_snake() {
# Usage: parse_kebab <STRING> # Usage: parse_kebab <STRING>
function parse_kebab() { function parse_kebab() {
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(_get_parts ${*}))
local result local result
for part in "${parts[@]}"; do for part in "${parts[@]}"; do
@ -66,7 +66,7 @@ function parse_kebab() {
# Usage: parse_camel <STRING> # Usage: parse_camel <STRING>
function parse_camel() { function parse_camel() {
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(_get_parts ${*}))
local result local result
# If already in camel. # If already in camel.
@ -88,7 +88,7 @@ function parse_camel() {
# Usage: parse_snake_uppercase <STRING> # Usage: parse_snake_uppercase <STRING>
function parse_snake_uppercase() { function parse_snake_uppercase() {
local IFS=${IFS}_- local IFS=${IFS}_-
local parts=($(parse_simplify ${1})) local parts=($(_get_parts ${*}))
local result local result
for part in "${parts[@]}"; do for part in "${parts[@]}"; do
@ -105,3 +105,15 @@ function parse_alnum() {
echo "${*}" | \ echo "${*}" | \
sed -e "s/[^[:alnum:]]//g" 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"
}