diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2010-05-04 02:01:00 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2010-05-04 02:01:00 +0000 |
commit | 33b3524268195a0798993690b54cead286da28fb (patch) | |
tree | 3522835f347d8671d44a9e9f966bd3fc4604699e /src/couchdb/couch_util.erl | |
parent | c2ddcc5d1c5fcbe712031df19ecc12c781d8b613 (diff) |
use keysearch BIF to search ejson props. Closes COUCHDB-747
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@940708 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r-- | src/couchdb/couch_util.erl | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 3b999560..e685332d 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -23,6 +23,7 @@ -export([json_encode/1, json_decode/1]). -export([verify/2,simple_call/2,shutdown_sync/1]). -export([compressible_att_type/1]). +-export([get_value/2, get_value/3]). -include("couch_db.hrl"). -include_lib("kernel/include/file.hrl"). @@ -119,9 +120,19 @@ parse_term(List) -> {ok, Tokens, _} = erl_scan:string(List ++ "."), erl_parse:parse_term(Tokens). +get_value(Key, List) -> + get_value(Key, List, undefined). + +get_value(Key, List, Default) -> + case lists:keysearch(Key, 1, List) of + {value, {Key,Value}} -> + Value; + false -> + Default + end. get_nested_json_value({Props}, [Key|Keys]) -> - case proplists:get_value(Key, Props, nil) of + case couch_util:get_value(Key, Props, nil) of nil -> throw({not_found, <<"missing json key: ", Key/binary>>}); Value -> get_nested_json_value(Value, Keys) end; |