Parse : Fix parse splitting.
This commit is contained in:
parent
32f6ae74d4
commit
0587a9404a
|
@ -88,8 +88,7 @@ function parse_snake_uppercase() {
|
||||||
# Parse data keeping only alphanumeric characters.
|
# Parse data keeping only alphanumeric characters.
|
||||||
# Usage: parse_alnum <STRING>
|
# Usage: parse_alnum <STRING>
|
||||||
function parse_alnum() {
|
function parse_alnum() {
|
||||||
echo "${*}" | \
|
echo "${*}" | sed -e "s/[^[:alnum:]]//g"
|
||||||
sed -e "s/[^[:alnum:]]//g"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse integers from mixed string.
|
# Parse integers from mixed string.
|
||||||
|
@ -114,8 +113,8 @@ function parse_uppercase() {
|
||||||
# Usage: parse_titlecase <STRING>
|
# Usage: parse_titlecase <STRING>
|
||||||
function parse_titlecase() {
|
function parse_titlecase() {
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local parts=$(_get_parts ${*})
|
local parts=$(_parse_split ${*})
|
||||||
local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does" "")
|
local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does")
|
||||||
local is_first=true
|
local is_first=true
|
||||||
|
|
||||||
for part in ${parts[@]}; do
|
for part in ${parts[@]}; do
|
||||||
|
@ -125,7 +124,7 @@ function parse_titlecase() {
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${minors[@]}" =~ "${part,,}" ]]; then
|
if [[ "${minors[@]}" =~ $(echo ${part} | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g") ]]; then
|
||||||
echo -n "${part}"
|
echo -n "${part}"
|
||||||
else
|
else
|
||||||
echo -n "${part^}"
|
echo -n "${part^}"
|
||||||
|
@ -146,7 +145,7 @@ function parse_sentencecase() {
|
||||||
# Usage: parse_startcase <STRING>
|
# Usage: parse_startcase <STRING>
|
||||||
function parse_startcase() {
|
function parse_startcase() {
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
local parts=$(_get_parts ${*})
|
local parts=$(_parse_split ${*})
|
||||||
|
|
||||||
for part in ${parts[@]}; do
|
for part in ${parts[@]}; do
|
||||||
echo -n "${part^}"
|
echo -n "${part^}"
|
||||||
|
@ -159,8 +158,14 @@ function parse_json() {
|
||||||
echo "${*}" | jq
|
echo "${*}" | jq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Split string by separators.
|
||||||
|
# Usage: _parse_split <STRING>
|
||||||
|
function _parse_split() {
|
||||||
|
echo "${*}" | sed -e "s/[A-Z]/\n&/g" -e "s/[0-9]\+/\n&\n/g" -e "s/[${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d"
|
||||||
|
}
|
||||||
|
|
||||||
# Get name parts.
|
# Get name parts.
|
||||||
# Usage: _get_parts <STRING>
|
# Usage: _get_parts <STRING>
|
||||||
function _get_parts() {
|
function _get_parts() {
|
||||||
echo "${*}" | sed -e "s/[A-Z]/\n&/g" -e "s/[0-9]\+/\n&/g" -e "s/[${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d"
|
_parse_split "${*}" | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g" | sed -e "/^$/d"
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue