anchor.diff:  %% rewriting dynamically the quey list given as query member in
   %% rewrites. Each value is replaced by one binding or an argument
   %% passed in url.
  -make_query_list([], _Bindings, Acc) ->
  +make_query_list([], _Bindings, _Formats, Acc) ->
       Acc;
  -make_query_list([{Key, {Value}}|Rest], Bindings, Acc) ->
  +make_query_list([{Key, {Value}}|Rest], Bindings, Formats, Acc) ->
       Value1 = {Value},
  -    make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  -make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_binary(Value) ->
  -    Value1 = replace_var(Value, Bindings),
  -    make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  -make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_list(Value) ->
  -    Value1 = replace_var(Value, Bindings),
  -    make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  -make_query_list([{Key, Value}|Rest], Bindings, Acc) ->
  -    make_query_list(Rest, Bindings, [{to_binding(Key), Value}|Acc]).
  -
  -replace_var(<<"*">>=Value, Bindings) ->
  -    get_var(Value, Bindings, Value);
  -replace_var(<<":", Var/binary>> = Value, Bindings) ->
  -    get_var(Var, Bindings, Value);
  -replace_var(Value, _Bindings) when is_binary(Value) ->
  +    make_query_list(Rest, Bindings, Formats, [{to_binding(Key), Value1}|Acc]);
  +make_query_list([{Key, Value}|Rest], Bindings, Formats, Acc) when is_binary(Value) ->
  +    Value1 = replace_var(Value, Bindings, Formats),
  +    make_query_list(Rest, Bindings, Formats, [{to_binding(Key), Value1}|Acc]);
  +make_query_list([{Key, Value}|Rest], Bindings, Formats, Acc) when is_list(Value) ->
  +    Value1 = replace_var(Value, Bindings, Formats),
  +    make_query_list(Rest, Bindings, Formats, [{to_binding(Key), Value1}|Acc]);
  +make_query_list([{Key, Value}|Rest], Bindings, Formats, Acc) ->
  +    make_query_list(Rest, Bindings, Formats, [{to_binding(Key), Value}|Acc]).
  +
  +replace_var(<<"*">>=Value, Bindings, Formats) ->
  +    get_var(Value, Bindings, Value, Formats);
  +replace_var(<<":", Var/binary>> = Value, Bindings, Formats) ->
  +    get_var(Var, Bindings, Value, Formats);
  +replace_var(Value, _Bindings, _Formats) when is_binary(Value) ->
       Value;
  -replace_var(Value, Bindings) when is_list(Value) ->
  +replace_var(Value, Bindings, Formats) when is_list(Value) ->
       lists:reverse(lists:foldl(fun
                   (<<":", Var/binary>>=Value1, Acc) ->
  -                    [get_var(Var, Bindings, Value1)|Acc];
  +                    [get_var(Var, Bindings, Value1, Formats)|Acc];
                   (Value1, Acc) ->
                       [Value1|Acc]
               end, [], Value));
  -replace_var(Value, _Bindings) ->
  +replace_var(Value, _Bindings, _Formats) ->
       Value.
                       
   maybe_json(Key, Value) ->
  
positive.code:     [];
  maybe_encode_bindings(Props) -> 
      lists:foldl(fun 
              ({{bind, <<"*">>}, V}, Acc) ->
                  Acc;
              ({{bind, K}, V}, Acc) ->
                  V1 = iolist_to_binary(maybe_json(K, V)),
  
negative.code:         To ->
              parse_path(To)
          end,
      Formats = case couch_util:get_value(<<"formats">>, Rule) of
          undefined -> [];
          {Fmts} -> Fmts
      end,
      [{FromParts, Method}, ToParts, QueryArgs, Formats].
  
  parse_path(Path) ->
      {ok, SlashRE} = re:compile(<<"\\/">>),
  