Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2012-05-29 04:06:39 +0400
committerJo-Philipp Wich <jow@openwrt.org>2012-05-29 04:12:35 +0400
commit67bc554465d9a364a5a0e5d418b42ad4d117911d (patch)
tree6a99cbbfb4a480f64a1f279332e7a339db387069 /sh
parent652162cf86cb0a2ebb82965dac806bbb441e1be9 (diff)
sh/jshn.sh: replace "tr" calls with inline substitution, signalize success with return values
Diffstat (limited to 'sh')
-rw-r--r--sh/jshn.sh15
1 files changed, 8 insertions, 7 deletions
diff --git a/sh/jshn.sh b/sh/jshn.sh
index 7f922c4..a15cb00 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -24,7 +24,7 @@ json_add_generic() {
var=$(( ${aseq:-0} + 1 ))
export -- "SEQ_$cur=$var"
else
- local name="$(echo -n "$var" | tr -C '[a-zA-Z0-9_]' _)"
+ local name="${var//[^a-zA-Z0-9_]/_}"
[[ "$name" == "$var" ]] || export -- "NAME_${cur}_${name}=$var"
var="$name"
fi
@@ -94,14 +94,14 @@ json_dump() {
json_get_type() {
local dest="$1"
- local var="$2"
- eval "export -- \"$dest=\${TYPE_${JSON_CUR}_$var}\""
+ local var="TYPE_${JSON_CUR}_$2"
+ eval "[ -n \"\${$var+x}\" ] && export -- \"$dest=\${$var}\""
}
json_get_var() {
local dest="$1"
- local var="$(echo -n "$2" | tr -C '[a-zA-Z0-9_]' _)"
- eval "export -- \"$dest=\${${JSON_CUR}_$var}\""
+ local var="${JSON_CUR}_${2//[^a-zA-Z0-9_]/_}"
+ eval "[ -n \"\${$var+x}\" ] && export -- \"$dest=\${$var}\""
}
json_get_vars() {
@@ -117,11 +117,11 @@ json_select() {
[ -z "$1" ] && {
JSON_CUR="JSON_VAR"
- return
+ return 0
}
[[ "$1" == ".." ]] && {
eval "JSON_CUR=\"\${UP_$JSON_CUR}\""
- return;
+ return 0
}
json_get_type type "$target"
case "$type" in
@@ -130,6 +130,7 @@ json_select() {
;;
*)
echo "WARNING: Variable '$target' does not exist or is not an array/object"
+ return 1
;;
esac
}