summaryrefslogtreecommitdiffstats
path: root/json
diff options
context:
space:
mode:
authortv <tv@xso>2011-09-09 16:38:12 +0200
committertv <tv@xso>2011-09-09 16:38:12 +0200
commitb938d6ad54f1e78219559d74e3be6cbb3d949cf8 (patch)
tree9f37309bcd1e42e8b1f5e6c23f959d6d3dc18e98 /json
parenta56b814d35262560a81c8cca648f558261788a38 (diff)
//json/sh/json.sh: use BRE @sed
Diffstat (limited to 'json')
-rwxr-xr-xjson/sh/json.sh14
1 files changed, 7 insertions, 7 deletions
diff --git a/json/sh/json.sh b/json/sh/json.sh
index 2a64d371..79f8529a 100755
--- a/json/sh/json.sh
+++ b/json/sh/json.sh
@@ -6,23 +6,23 @@ set -euf
# XXX json_key is something like PWD^^
normalize_json() {
- sed -rn '
+ sed -n '
1s/^/cat<<EOF\n/
# TODO handle escaped double quotes
- s/"[^"]+"/"$(echo -n & | base64)"/g
+ s/"[^"]\+"/"$(echo -n & | base64)"/g
$s/$/\nEOF/
p
' | sh | tr -d '[:space:]'
}
json_to_sh() {
- sed -rn '
+ sed -n '
s/,/;/g
s/\[/begin_json_array;/g; s/\]/end_json_array;/g
s/\{/begin_json_object;/g; s/\}/end_json_object;/g
- s/("[^"]+"):/json_set_key \1;/g
- s/;("[^"]+")/;json_set string \1;/g
- s/;([0-9.]+)/;json_set number `echo -n \1 | base64`;/g
+ s/\("[^"]\+"\):/json_set_key \1;/g
+ s/;\("[^"]\+"\)/;json_set string \1;/g
+ s/;\([0-9.]\+\)/;json_set number `echo -n \1 | base64`;/g
s/;;/;/g
s/;/\n/g
p
@@ -37,7 +37,7 @@ end_json_object() {
pop_key # TODO check if is %%%MAKEJSONOBJ%%%
#echo obj: $1 `set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"` >&2
#json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)_VALUE=(.*)/\1/p"`"
- json_set object "`set | sed -rn "s/^(${json_key}_[a-zA-Z]+)=(.*)/\1/p"`"
+ json_set object "`set | sed -n "s/^\(${json_key}_[a-zA-Z]\+\)=\(.*\)/\1/p"`"
}
begin_json_array() { :; }
end_json_array() { :; }