Skip to content

Commit

Permalink
- add egrep -v "^$SPACE$" to eat up whitespace to fix the test failur…
Browse files Browse the repository at this point in the history
…e issue

- adjust GREP selection by using if...then...else style
  • Loading branch information
golwatt committed Apr 29, 2013
1 parent c546892 commit fb3709c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions JSON.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,33 @@ awk_egrep () {
}

tokenize () {
local GREP='egrep -ao --color=never'
local ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
local CHAR='[^[:cntrl:]"\\]'

echo "test string" | $GREP "test" &>/dev/null ||
GREP='egrep -ao'

echo "test string" | egrep -o "test" &>/dev/null ||
{
local GREP
local ESCAPE
local CHAR

if echo "test string" | egrep -ao --color=never "test" &>/dev/null
then
GREP='egrep -ao --color=never'
else
GREP='egrep -ao'
fi

if echo "test string" | egrep -o "test" &>/dev/null
then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
GREP=awk_egrep
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\\\]'
}
fi

local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'
$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|."

$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|." | egrep -v "^$SPACE$"
}

parse_array () {
Expand Down

0 comments on commit fb3709c

Please sign in to comment.