Skip to content

Commit

Permalink
Cleaning up keypath search.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvande committed Feb 25, 2012
1 parent a554da1 commit f5696bb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions jason
Expand Up @@ -11,7 +11,7 @@ needle=( this )
keypath=${1#this}
index=0
char=${keypath:0:1}
[[ ! "$char" =~ [\[\.:] ]] && char='.' && index=-1
[[ ! -z $keypath && ! "$char" =~ [\[\.:] ]] && char='.' && index=-1
until [[ -z "$char" ]]; do
case "${char}" in ('')
;; ( '[' | '.' | ':' )
Expand Down Expand Up @@ -80,12 +80,19 @@ until [[ -z "$char" ]]; do
esac

if [[ ! -z $value ]]; then
if [[ ${#needle[@]} == 1 || ${#key[@]} == ${#needle[@]} ]]; then
if [[ ${#needle[@]} == 1 ]]; then
success=1
elif [[ "${#needle[@]}" == "${#key[@]}" ]]; then
success=1
for i in "${!needle[@]}"; do
[[ "${needle[$i]}" == '*' || "${needle[$i]}" == "${key[$i]}" ]] || unset success
[[ "${needle[$i]}" != '*' && "${needle[$i]}" != "${key[$i]}" ]] && unset success && break
done
[[ ! -z $success ]] && echo "$(echo -n ${key[0]} && [ ${#key[*]} -gt 1 ] && printf "[%s]" "${key[@]:1}"): $value"
else
unset success
fi
if [[ ! -z $success ]]; then
echo "$(echo -n ${key[0]} && [ ${#key[*]} -gt 1 ] && printf "[%s]" "${key[@]:1}") $value"
unset sucess
fi
obj="${obj}${value}"
unset value
Expand Down

0 comments on commit f5696bb

Please sign in to comment.