Skip to content
Browse files

Merge pull request #21 from step-/master

squash issue #19 and allow using busybox egrep
  • Loading branch information...
2 parents cfcfebc + 624defc commit 754ee25419ce67f9b8283734f68cfdaafac2e6b9 @dominictarr committed Mar 14, 2013
Showing with 9 additions and 3 deletions.
  1. +9 −3 JSON.sh
View
12 JSON.sh
@@ -14,8 +14,11 @@ tokenize () {
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'
- egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never |
- egrep -v "^$SPACE$" # eat whitespace
+ {
+ egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." --color=never 2>/dev/null ||
+ egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." # busybox egrep
+ } |
+ egrep -v "^$SPACE$" # eat whitespace
}
parse_array () {
@@ -41,6 +44,7 @@ parse_array () {
;;
esac
[ $BRIEF -ne 1 ] && value=`printf '[%s]' "$ary"` || value=
+ :
}
parse_object () {
@@ -75,6 +79,7 @@ parse_object () {
;;
esac
[ $BRIEF -ne 1 ] && value=`printf '{%s}' "$obj"` || value=
+ :
}
parse_value () {
@@ -86,8 +91,9 @@ parse_value () {
''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token ;;
esac
- ! ([ $BRIEF -eq 1 ] && ([ -z $jpath ] || [ "$value" = '' ])) \
+ ! ([ $BRIEF -eq 1 ] && ([ -z "$jpath" ] || [ "$value" = '' ])) \
&& printf "[%s]\t%s\n" "$jpath" "$value"
+ :
}
parse () {

0 comments on commit 754ee25

Please sign in to comment.
Something went wrong with that request. Please try again.