Parse : Add parse_snake.

This commit is contained in:
Dmitry Voronin 2023-12-17 20:08:31 +03:00
parent ff07b915af
commit 0be0396232
2 changed files with 21 additions and 0 deletions

View file

@ -15,3 +15,9 @@ curl -s https://git.voronind.com/voronind/linux/raw/branch/master/.bootstrap.sh
# Load Gnome settings.
To load Gnome settings run `dconf_load`.
# Conventions.
Directory names are `snake_case` so you don't have to release the Shift key 10 times per second when tabing deep for directory.
File names are `CamelCase` to differ from directories, also it works nice with things like my archives where underscore and dash separate extra file data.

View file

@ -26,6 +26,21 @@ function parse_camel() {
echo "${result}"
}
# Parse to snake_case.
# Usage: parse_snake <STRING>
function parse_snake() {
local IFS=${IFS}_-
local parts=($(parse_simplify ${1}))
local result
for part in "${parts[@]}"; do
local word="${part,,}"
result="${result}_${word}"
done
echo "${result#_}"
}
# Parse data keeping only alphanumeric characters.
# Usage: parse_alnum <STRING>
function parse_alnum() {