Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 10, 2024
1 parent 71dc5af commit 4bc3cab
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ nvm_json_awk_egrep() {
local pattern_string
pattern_string=$1

gawk '{
awk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
Expand All @@ -128,15 +128,13 @@ nvm_json_tokenize() {
local ESCAPE
local CHAR

if echo 'test string' | grep -Eao --color=never 'test' &>/dev/null
then
if echo 'test string' | grep -Eao --color=never 'test' > /dev/null 2>&1; then
GREP='grep -Eao --color=never'
else
GREP='grep -Eao'
fi

if echo "test string" | grep -Eo "test" &>/dev/null
then
if echo "test string" | grep -Eo "test" > /dev/null 2>&1; then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
Expand All @@ -158,19 +156,16 @@ nvm_json_tokenize() {
}

_json_parse_array() {
local index
index=0
local ary
ary=''
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :
do
while :; do
_json_parse_value "${1}" "${index}"
index=$((index+1))
ary="${ary}""${value}"
ary="${ary}${value}"
read -r token
case "${token}" in
']') break ;;
Expand All @@ -186,14 +181,12 @@ _json_parse_array() {

_json_parse_object() {
local key
local obj
obj=''
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :
do
while :; do
case "${token}" in
'"'*'"') key="${token}" ;;
*) nvm_json_throw "EXPECTED string GOT ${token:-EOF}" ;;
Expand All @@ -220,14 +213,10 @@ _json_parse_object() {
}

_json_parse_value() {
local jpath
jpath="${1:+$1,}$2"
local isleaf
isleaf=0
local isempty
isempty=0
local print
print=0
local jpath="${1:+$1,}$2"
local isleaf=0
local isempty=0
local print=0

case "$token" in
'{') _json_parse_object "${jpath}" ;;
Expand Down Expand Up @@ -257,9 +246,6 @@ _json_parse() {
esac
}


nvm_json_extract() {
local parsed
parsed=$(nvm_json_tokenize | _json_parse)
echo "${parsed}" | grep -e "${1}" | awk '{print $2 $3}'
nvm_json_tokenize | _json_parse | grep -e "${1}" | awk '{print $2 $3}'
}

0 comments on commit 4bc3cab

Please sign in to comment.