summaryrefslogtreecommitdiff
path: root/bos-namespaces.sh
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-14 12:26:36 +0100
committerGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-14 12:26:36 +0100
commit8fa0f25dbc596431508a398291cb2a5e25b5660c (patch)
tree869cca6cc03aed9d7081d1cb403e2891792ad17b /bos-namespaces.sh
parentfix find-method-into (diff)
downloadbash-object-system-8fa0f25dbc596431508a398291cb2a5e25b5660c.tar.gz
bash-object-system-8fa0f25dbc596431508a398291cb2a5e25b5660c.tar.bz2
bash-object-system-8fa0f25dbc596431508a398291cb2a5e25b5660c.zip
much better encoding
Diffstat (limited to 'bos-namespaces.sh')
-rw-r--r--bos-namespaces.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/bos-namespaces.sh b/bos-namespaces.sh
index 9fbbb08..fd371c3 100644
--- a/bos-namespaces.sh
+++ b/bos-namespaces.sh
@@ -1,22 +1,38 @@
#!bash
## namespace handling
+function bos-namespaces/encode-into() {
+ local string="$1"
+ local -n result="$2"
+ local idx char tmp
+
+ result=''
+ for (( idx=0 ; idx < "${#string}" ; ++idx )); do
+ char="${string:$idx:1}"
+ case "$char" in
+ [0-9A-Za-z]) tmp="$char";;
+ *) printf -v tmp _%02x "'$char"
+ esac
+ result+="$tmp"
+ done
+}
+
function bos-namespaces/store-scalar-for-into() {
- local name="bos_namespaces__${2//[^[:word:]/__}__${1//[^[:word:]]/__}"
+ local name; bos-namespaces/encode-into "bos_${2}_${1}" name
local -n result="$3"
declare -g "$name"
result="$name"
}
function bos-namespaces/store-array-for-into() {
- local name="bos_namespaces__${2//[^[:word:]/__}__${1//[^[:word:]]/__}"
+ local name; bos-namespaces/encode-into "bos_${2}_${1}" name
local -n result="$3"
declare -ga "$name"
result="$name"
}
function bos-namespaces/store-dict-for-into() {
- local name="bos_namespaces__${2//[^[:word:]/__}__${1//[^[:word:]]/__}"
+ local name; bos-namespaces/encode-into "bos_${2}_${1}" name
local -n result="$3"
declare -gA "$name"
result="$name"