summaryrefslogtreecommitdiff
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
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
-rw-r--r--bos-mop.sh5
-rw-r--r--bos-namespaces.sh22
-rw-r--r--test.sh8
3 files changed, 26 insertions, 9 deletions
diff --git a/bos-mop.sh b/bos-mop.sh
index 7cd28c7..3b06216 100644
--- a/bos-mop.sh
+++ b/bos-mop.sh
@@ -1,7 +1,8 @@
#!bash
-bos_namespaces__bos__mop__base__meta="bos-dipatch/invoke bos/mop/base 0"
-declare -a bos_namespaces__bos__mop__base__mro=( "bos/mop/base" )
+# this encoding must match bos-namespaces/encode-into
+bos_5fbos_2fmop_2fbase_5fmeta="bos-dipatch/invoke bos/mop/base 0"
+declare -a bos_5fbos_2fmop_2fbase_5fmro=( "bos/mop/base" )
# these are instance methods of the base metaclass
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"
diff --git a/test.sh b/test.sh
index 6e7e49c..1a4ed6d 100644
--- a/test.sh
+++ b/test.sh
@@ -5,15 +5,15 @@
. bos-mop.sh
. bos-dispatch.sh
-bos_namespaces__A__meta="bos-dispatch/invoke bos/mop/base 0"
-bos_namespaces__A__mro=( "A" )
+bos_5fA_5fmeta="bos-dispatch/invoke bos/mop/base 0"
+bos_5fA_5fmro=( "A" )
function A/thing() {
echo "<$self> A/thing ($*)"
}
-bos_namespaces__B__meta="bos-dispatch/invoke bos/mop/base 0"
-bos_namespaces__B__mro=( "B" "A" )
+bos_5fB_5fmeta="bos-dispatch/invoke bos/mop/base 0"
+bos_5fB_5fmro=( "B" "A" )
function B/other() {
echo "<$self> B/other ($*)"