From 9599f7cd77ef8a6feacec3c8ead9432af02a57d3 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Mon, 12 Jul 2010 17:24:00 +0000 Subject: Reverting revision 963042 - lists:keystore/4 only replaces the first occurrence in the list. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@963367 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_util.erl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/couchdb/couch_util.erl') diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 80c92271..2aa69af8 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -144,11 +144,18 @@ get_nested_json_value(Value, []) -> get_nested_json_value(_NotJSONObj, _) -> throw({not_found, json_mismatch}). -proplist_apply_field({K, _V} = KV, L) -> - lists:keystore(K, 1, L, KV). - -json_apply_field({K, _V} = KV, {L}) -> - {lists:keystore(K, 1, L, KV)}. +proplist_apply_field(H, L) -> + {R} = json_apply_field(H, {L}), + R. + +json_apply_field(H, {L}) -> + json_apply_field(H, L, []). +json_apply_field({Key, NewValue}, [{Key, _OldVal} | Headers], Acc) -> + json_apply_field({Key, NewValue}, Headers, Acc); +json_apply_field({Key, NewValue}, [{OtherKey, OtherVal} | Headers], Acc) -> + json_apply_field({Key, NewValue}, Headers, [{OtherKey, OtherVal} | Acc]); +json_apply_field({Key, NewValue}, [], Acc) -> + {[{Key, NewValue}|Acc]}. json_user_ctx(#db{name=DbName, user_ctx=Ctx}) -> {[{<<"db">>, DbName}, -- cgit v1.2.3