Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Cleaner workaround for dominictarr/JSON.sh#50
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Dec 27, 2016
1 parent 3aaa87c commit 4c96ec0
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/shinc/JSON.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ parse_options() {
awk_egrep () {
local pattern_string=$1

gawk '{
awk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
Expand All @@ -73,22 +73,24 @@ tokenize () {
local ESCAPE
local CHAR

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

if echo "test string" | egrep -o "test" >/dev/null 2>&1
then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
# use awk for egrep because https://github.com/dominictarr/JSON.sh/issues/50

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

#if echo "test string" | egrep -o "test" >/dev/null 2>&1
#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
#fi

local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
Expand Down

0 comments on commit 4c96ec0

Please sign in to comment.