Skip to content

Commit

Permalink
fix issue dominictarr#19 and allow using busybox egrep
Browse files Browse the repository at this point in the history
  • Loading branch information
stepk committed Mar 14, 2013
1 parent cfcfebc commit 624defc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions JSON.sh
Expand Up @@ -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 () {
Expand All @@ -41,6 +44,7 @@ parse_array () {
;;
esac
[ $BRIEF -ne 1 ] && value=`printf '[%s]' "$ary"` || value=
:
}

parse_object () {
Expand Down Expand Up @@ -75,6 +79,7 @@ parse_object () {
;;
esac
[ $BRIEF -ne 1 ] && value=`printf '{%s}' "$obj"` || value=
:
}

parse_value () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 624defc

Please sign in to comment.