You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/05 15:51:00 UTC

[38/49] couchdb commit: updated refs/heads/1843-feature-bigcouch to 3069c01

Remove src/mochiweb


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/acf8eaff
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/acf8eaff
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/acf8eaff

Branch: refs/heads/1843-feature-bigcouch
Commit: acf8eaff91cfe1b1558570df199aa802041bf103
Parents: 4cac46a
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Feb 4 17:41:55 2014 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Feb 4 17:41:55 2014 -0600

----------------------------------------------------------------------
 src/mochiweb/src/internal.hrl               |    3 -
 src/mochiweb/src/mochifmt.erl               |  425 --------
 src/mochiweb/src/mochifmt_records.erl       |   38 -
 src/mochiweb/src/mochifmt_std.erl           |   30 -
 src/mochiweb/src/mochiglobal.erl            |  107 --
 src/mochiweb/src/mochihex.erl               |   91 --
 src/mochiweb/src/mochijson.erl              |  531 ---------
 src/mochiweb/src/mochijson2.erl             |  849 ---------------
 src/mochiweb/src/mochilists.erl             |  104 --
 src/mochiweb/src/mochilogfile2.erl          |  140 ---
 src/mochiweb/src/mochinum.erl               |  354 ------
 src/mochiweb/src/mochitemp.erl              |  310 ------
 src/mochiweb/src/mochiutf8.erl              |  316 ------
 src/mochiweb/src/mochiweb.app.src           |    8 -
 src/mochiweb/src/mochiweb.erl               |  289 -----
 src/mochiweb/src/mochiweb_acceptor.erl      |   49 -
 src/mochiweb/src/mochiweb_app.erl           |   27 -
 src/mochiweb/src/mochiweb_charref.erl       |  308 ------
 src/mochiweb/src/mochiweb_cookies.erl       |  309 ------
 src/mochiweb/src/mochiweb_cover.erl         |   75 --
 src/mochiweb/src/mochiweb_echo.erl          |   38 -
 src/mochiweb/src/mochiweb_headers.erl       |  299 -----
 src/mochiweb/src/mochiweb_html.erl          | 1264 ----------------------
 src/mochiweb/src/mochiweb_http.erl          |  290 -----
 src/mochiweb/src/mochiweb_io.erl            |   46 -
 src/mochiweb/src/mochiweb_mime.erl          |   94 --
 src/mochiweb/src/mochiweb_multipart.erl     |  824 --------------
 src/mochiweb/src/mochiweb_request.erl       |  788 --------------
 src/mochiweb/src/mochiweb_request_tests.erl |   63 --
 src/mochiweb/src/mochiweb_response.erl      |   64 --
 src/mochiweb/src/mochiweb_skel.erl          |   86 --
 src/mochiweb/src/mochiweb_socket.erl        |   83 --
 src/mochiweb/src/mochiweb_socket_server.erl |  364 -------
 src/mochiweb/src/mochiweb_sup.erl           |   41 -
 src/mochiweb/src/mochiweb_util.erl          |  980 -----------------
 src/mochiweb/src/reloader.erl               |  161 ---
 36 files changed, 9848 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/internal.hrl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/internal.hrl b/src/mochiweb/src/internal.hrl
deleted file mode 100644
index 6db899a..0000000
--- a/src/mochiweb/src/internal.hrl
+++ /dev/null
@@ -1,3 +0,0 @@
-
--define(RECBUF_SIZE, 8192).
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochifmt.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochifmt.erl b/src/mochiweb/src/mochifmt.erl
deleted file mode 100644
index 5bc6b9c..0000000
--- a/src/mochiweb/src/mochifmt.erl
+++ /dev/null
@@ -1,425 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc String Formatting for Erlang, inspired by Python 2.6
-%%      (<a href="http://www.python.org/dev/peps/pep-3101/">PEP 3101</a>).
-%%
--module(mochifmt).
--author('bob@mochimedia.com').
--export([format/2, format_field/2, convert_field/2, get_value/2, get_field/2]).
--export([tokenize/1, format/3, get_field/3, format_field/3]).
--export([bformat/2, bformat/3]).
--export([f/2, f/3]).
-
--record(conversion, {length, precision, ctype, align, fill_char, sign}).
-
-%% @spec tokenize(S::string()) -> tokens()
-%% @doc Tokenize a format string into mochifmt's internal format.
-tokenize(S) ->
-    {?MODULE, tokenize(S, "", [])}.
-
-%% @spec convert_field(Arg, Conversion::conversion()) -> term()
-%% @doc Process Arg according to the given explicit conversion specifier.
-convert_field(Arg, "") ->
-    Arg;
-convert_field(Arg, "r") ->
-    repr(Arg);
-convert_field(Arg, "s") ->
-    str(Arg).
-
-%% @spec get_value(Key::string(), Args::args()) -> term()
-%% @doc Get the Key from Args. If Args is a tuple then convert Key to
-%%      an integer and get element(1 + Key, Args). If Args is a list and Key
-%%      can be parsed as an integer then use lists:nth(1 + Key, Args),
-%%      otherwise try and look for Key in Args as a proplist, converting
-%%      Key to an atom or binary if necessary.
-get_value(Key, Args) when is_tuple(Args) ->
-    element(1 + list_to_integer(Key), Args);
-get_value(Key, Args) when is_list(Args) ->
-    try lists:nth(1 + list_to_integer(Key), Args)
-    catch error:_ ->
-            {_K, V} = proplist_lookup(Key, Args),
-            V
-    end.
-
-%% @spec get_field(Key::string(), Args) -> term()
-%% @doc Consecutively call get_value/2 on parts of Key delimited by ".",
-%%      replacing Args with the result of the previous get_value. This
-%%      is used to implement formats such as {0.0}.
-get_field(Key, Args) ->
-    get_field(Key, Args, ?MODULE).
-
-%% @spec get_field(Key::string(), Args, Module) -> term()
-%% @doc Consecutively call Module:get_value/2 on parts of Key delimited by ".",
-%%      replacing Args with the result of the previous get_value. This
-%%      is used to implement formats such as {0.0}.
-get_field(Key, Args, Module) ->
-    {Name, Next} = lists:splitwith(fun (C) -> C =/= $. end, Key),
-    Res = try Module:get_value(Name, Args)
-          catch error:undef -> get_value(Name, Args) end,
-    case Next of
-        "" ->
-            Res;
-        "." ++ S1 ->
-            get_field(S1, Res, Module)
-    end.
-
-%% @spec format(Format::string(), Args) -> iolist()
-%% @doc Format Args with Format.
-format(Format, Args) ->
-    format(Format, Args, ?MODULE).
-
-%% @spec format(Format::string(), Args, Module) -> iolist()
-%% @doc Format Args with Format using Module.
-format({?MODULE, Parts}, Args, Module) ->
-    format2(Parts, Args, Module, []);
-format(S, Args, Module) ->
-    format(tokenize(S), Args, Module).
-
-%% @spec format_field(Arg, Format) -> iolist()
-%% @doc Format Arg with Format.
-format_field(Arg, Format) ->
-    format_field(Arg, Format, ?MODULE).
-
-%% @spec format_field(Arg, Format, _Module) -> iolist()
-%% @doc Format Arg with Format.
-format_field(Arg, Format, _Module) ->
-    F = default_ctype(Arg, parse_std_conversion(Format)),
-    fix_padding(fix_sign(convert2(Arg, F), F), F).
-
-%% @spec f(Format::string(), Args) -> string()
-%% @doc Format Args with Format and return a string().
-f(Format, Args) ->
-    f(Format, Args, ?MODULE).
-
-%% @spec f(Format::string(), Args, Module) -> string()
-%% @doc Format Args with Format using Module and return a string().
-f(Format, Args, Module) ->
-    case lists:member(${, Format) of
-        true ->
-            binary_to_list(bformat(Format, Args, Module));
-        false ->
-            Format
-    end.
-
-%% @spec bformat(Format::string(), Args) -> binary()
-%% @doc Format Args with Format and return a binary().
-bformat(Format, Args) ->
-    iolist_to_binary(format(Format, Args)).
-
-%% @spec bformat(Format::string(), Args, Module) -> binary()
-%% @doc Format Args with Format using Module and return a binary().
-bformat(Format, Args, Module) ->
-    iolist_to_binary(format(Format, Args, Module)).
-
-%% Internal API
-
-add_raw("", Acc) ->
-    Acc;
-add_raw(S, Acc) ->
-    [{raw, lists:reverse(S)} | Acc].
-
-tokenize([], S, Acc) ->
-    lists:reverse(add_raw(S, Acc));
-tokenize("{{" ++ Rest, S, Acc) ->
-    tokenize(Rest, "{" ++ S, Acc);
-tokenize("{" ++ Rest, S, Acc) ->
-    {Format, Rest1} = tokenize_format(Rest),
-    tokenize(Rest1, "", [{format, make_format(Format)} | add_raw(S, Acc)]);
-tokenize("}}" ++ Rest, S, Acc) ->
-    tokenize(Rest, "}" ++ S, Acc);
-tokenize([C | Rest], S, Acc) ->
-    tokenize(Rest, [C | S], Acc).
-
-tokenize_format(S) ->
-    tokenize_format(S, 1, []).
-
-tokenize_format("}" ++ Rest, 1, Acc) ->
-    {lists:reverse(Acc), Rest};
-tokenize_format("}" ++ Rest, N, Acc) ->
-    tokenize_format(Rest, N - 1, "}" ++ Acc);
-tokenize_format("{" ++ Rest, N, Acc) ->
-    tokenize_format(Rest, 1 + N, "{" ++ Acc);
-tokenize_format([C | Rest], N, Acc) ->
-    tokenize_format(Rest, N, [C | Acc]).
-
-make_format(S) ->
-    {Name0, Spec} = case lists:splitwith(fun (C) -> C =/= $: end, S) of
-                        {_, ""} ->
-                            {S, ""};
-                        {SN, ":" ++ SS} ->
-                            {SN, SS}
-                    end,
-    {Name, Transform} = case lists:splitwith(fun (C) -> C =/= $! end, Name0) of
-                            {_, ""} ->
-                                {Name0, ""};
-                            {TN, "!" ++ TT} ->
-                                {TN, TT}
-                        end,
-    {Name, Transform, Spec}.
-
-proplist_lookup(S, P) ->
-    A = try list_to_existing_atom(S)
-        catch error:_ -> make_ref() end,
-    B = try list_to_binary(S)
-        catch error:_ -> make_ref() end,
-    proplist_lookup2({S, A, B}, P).
-
-proplist_lookup2({KS, KA, KB}, [{K, V} | _])
-  when KS =:= K orelse KA =:= K orelse KB =:= K ->
-    {K, V};
-proplist_lookup2(Keys, [_ | Rest]) ->
-    proplist_lookup2(Keys, Rest).
-
-format2([], _Args, _Module, Acc) ->
-    lists:reverse(Acc);
-format2([{raw, S} | Rest], Args, Module, Acc) ->
-    format2(Rest, Args, Module, [S | Acc]);
-format2([{format, {Key, Convert, Format0}} | Rest], Args, Module, Acc) ->
-    Format = f(Format0, Args, Module),
-    V = case Module of
-            ?MODULE ->
-                V0 = get_field(Key, Args),
-                V1 = convert_field(V0, Convert),
-                format_field(V1, Format);
-            _ ->
-                V0 = try Module:get_field(Key, Args)
-                     catch error:undef -> get_field(Key, Args, Module) end,
-                V1 = try Module:convert_field(V0, Convert)
-                     catch error:undef -> convert_field(V0, Convert) end,
-                try Module:format_field(V1, Format)
-                catch error:undef -> format_field(V1, Format, Module) end
-        end,
-    format2(Rest, Args, Module, [V | Acc]).
-
-default_ctype(_Arg, C=#conversion{ctype=N}) when N =/= undefined ->
-    C;
-default_ctype(Arg, C) when is_integer(Arg) ->
-    C#conversion{ctype=decimal};
-default_ctype(Arg, C) when is_float(Arg) ->
-    C#conversion{ctype=general};
-default_ctype(_Arg, C) ->
-    C#conversion{ctype=string}.
-
-fix_padding(Arg, #conversion{length=undefined}) ->
-    Arg;
-fix_padding(Arg, F=#conversion{length=Length, fill_char=Fill0, align=Align0,
-                               ctype=Type}) ->
-    Padding = Length - iolist_size(Arg),
-    Fill = case Fill0 of
-               undefined ->
-                   $\s;
-               _ ->
-                   Fill0
-           end,
-    Align = case Align0 of
-                undefined ->
-                    case Type of
-                        string ->
-                            left;
-                        _ ->
-                            right
-                    end;
-                _ ->
-                    Align0
-            end,
-    case Padding > 0 of
-        true ->
-            do_padding(Arg, Padding, Fill, Align, F);
-        false ->
-            Arg
-    end.
-
-do_padding(Arg, Padding, Fill, right, _F) ->
-    [lists:duplicate(Padding, Fill), Arg];
-do_padding(Arg, Padding, Fill, center, _F) ->
-    LPadding = lists:duplicate(Padding div 2, Fill),
-    RPadding = case Padding band 1 of
-                   1 ->
-                       [Fill | LPadding];
-                   _ ->
-                       LPadding
-               end,
-    [LPadding, Arg, RPadding];
-do_padding([$- | Arg], Padding, Fill, sign_right, _F) ->
-    [[$- | lists:duplicate(Padding, Fill)], Arg];
-do_padding(Arg, Padding, Fill, sign_right, #conversion{sign=$-}) ->
-    [lists:duplicate(Padding, Fill), Arg];
-do_padding([S | Arg], Padding, Fill, sign_right, #conversion{sign=S}) ->
-    [[S | lists:duplicate(Padding, Fill)], Arg];
-do_padding(Arg, Padding, Fill, sign_right, #conversion{sign=undefined}) ->
-    [lists:duplicate(Padding, Fill), Arg];
-do_padding(Arg, Padding, Fill, left, _F) ->
-    [Arg | lists:duplicate(Padding, Fill)].
-
-fix_sign(Arg, #conversion{sign=$+}) when Arg >= 0 ->
-    [$+, Arg];
-fix_sign(Arg, #conversion{sign=$\s}) when Arg >= 0 ->
-    [$\s, Arg];
-fix_sign(Arg, _F) ->
-    Arg.
-
-ctype($\%) -> percent;
-ctype($s) -> string;
-ctype($b) -> bin;
-ctype($o) -> oct;
-ctype($X) -> upper_hex;
-ctype($x) -> hex;
-ctype($c) -> char;
-ctype($d) -> decimal;
-ctype($g) -> general;
-ctype($f) -> fixed;
-ctype($e) -> exp.
-
-align($<) -> left;
-align($>) -> right;
-align($^) -> center;
-align($=) -> sign_right.
-
-convert2(Arg, F=#conversion{ctype=percent}) ->
-    [convert2(100.0 * Arg, F#conversion{ctype=fixed}), $\%];
-convert2(Arg, #conversion{ctype=string}) ->
-    str(Arg);
-convert2(Arg, #conversion{ctype=bin}) ->
-    erlang:integer_to_list(Arg, 2);
-convert2(Arg, #conversion{ctype=oct}) ->
-    erlang:integer_to_list(Arg, 8);
-convert2(Arg, #conversion{ctype=upper_hex}) ->
-    erlang:integer_to_list(Arg, 16);
-convert2(Arg, #conversion{ctype=hex}) ->
-    string:to_lower(erlang:integer_to_list(Arg, 16));
-convert2(Arg, #conversion{ctype=char}) when Arg < 16#80 ->
-    [Arg];
-convert2(Arg, #conversion{ctype=char}) ->
-    xmerl_ucs:to_utf8(Arg);
-convert2(Arg, #conversion{ctype=decimal}) ->
-    integer_to_list(Arg);
-convert2(Arg, #conversion{ctype=general, precision=undefined}) ->
-    try mochinum:digits(Arg)
-    catch error:undef -> io_lib:format("~g", [Arg]) end;
-convert2(Arg, #conversion{ctype=fixed, precision=undefined}) ->
-    io_lib:format("~f", [Arg]);
-convert2(Arg, #conversion{ctype=exp, precision=undefined}) ->
-    io_lib:format("~e", [Arg]);
-convert2(Arg, #conversion{ctype=general, precision=P}) ->
-    io_lib:format("~." ++ integer_to_list(P) ++ "g", [Arg]);
-convert2(Arg, #conversion{ctype=fixed, precision=P}) ->
-    io_lib:format("~." ++ integer_to_list(P) ++ "f", [Arg]);
-convert2(Arg, #conversion{ctype=exp, precision=P}) ->
-    io_lib:format("~." ++ integer_to_list(P) ++ "e", [Arg]).
-
-str(A) when is_atom(A) ->
-    atom_to_list(A);
-str(I) when is_integer(I) ->
-    integer_to_list(I);
-str(F) when is_float(F) ->
-    try mochinum:digits(F)
-    catch error:undef -> io_lib:format("~g", [F]) end;
-str(L) when is_list(L) ->
-    L;
-str(B) when is_binary(B) ->
-    B;
-str(P) ->
-    repr(P).
-
-repr(P) when is_float(P) ->
-    try mochinum:digits(P)
-    catch error:undef -> float_to_list(P) end;
-repr(P) ->
-    io_lib:format("~p", [P]).
-
-parse_std_conversion(S) ->
-    parse_std_conversion(S, #conversion{}).
-
-parse_std_conversion("", Acc) ->
-    Acc;
-parse_std_conversion([Fill, Align | Spec], Acc)
-  when Align =:= $< orelse Align =:= $> orelse Align =:= $= orelse Align =:= $^ ->
-    parse_std_conversion(Spec, Acc#conversion{fill_char=Fill,
-                                              align=align(Align)});
-parse_std_conversion([Align | Spec], Acc)
-  when Align =:= $< orelse Align =:= $> orelse Align =:= $= orelse Align =:= $^ ->
-    parse_std_conversion(Spec, Acc#conversion{align=align(Align)});
-parse_std_conversion([Sign | Spec], Acc)
-  when Sign =:= $+ orelse Sign =:= $- orelse Sign =:= $\s ->
-    parse_std_conversion(Spec, Acc#conversion{sign=Sign});
-parse_std_conversion("0" ++ Spec, Acc) ->
-    Align = case Acc#conversion.align of
-                undefined ->
-                    sign_right;
-                A ->
-                    A
-            end,
-    parse_std_conversion(Spec, Acc#conversion{fill_char=$0, align=Align});
-parse_std_conversion(Spec=[D|_], Acc) when D >= $0 andalso D =< $9 ->
-    {W, Spec1} = lists:splitwith(fun (C) -> C >= $0 andalso C =< $9 end, Spec),
-    parse_std_conversion(Spec1, Acc#conversion{length=list_to_integer(W)});
-parse_std_conversion([$. | Spec], Acc) ->
-    case lists:splitwith(fun (C) -> C >= $0 andalso C =< $9 end, Spec) of
-        {"", Spec1} ->
-            parse_std_conversion(Spec1, Acc);
-        {P, Spec1} ->
-            parse_std_conversion(Spec1,
-                                 Acc#conversion{precision=list_to_integer(P)})
-    end;
-parse_std_conversion([Type], Acc) ->
-    parse_std_conversion("", Acc#conversion{ctype=ctype(Type)}).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-tokenize_test() ->
-    {?MODULE, [{raw, "ABC"}]} = tokenize("ABC"),
-    {?MODULE, [{format, {"0", "", ""}}]} = tokenize("{0}"),
-    {?MODULE, [{raw, "ABC"}, {format, {"1", "", ""}}, {raw, "DEF"}]} =
-        tokenize("ABC{1}DEF"),
-    ok.
-
-format_test() ->
-    <<"  -4">> = bformat("{0:4}", [-4]),
-    <<"   4">> = bformat("{0:4}", [4]),
-    <<"   4">> = bformat("{0:{0}}", [4]),
-    <<"4   ">> = bformat("{0:4}", ["4"]),
-    <<"4   ">> = bformat("{0:{0}}", ["4"]),
-    <<"1.2yoDEF">> = bformat("{2}{0}{1}{3}", {yo, "DE", 1.2, <<"F">>}),
-    <<"cafebabe">> = bformat("{0:x}", {16#cafebabe}),
-    <<"CAFEBABE">> = bformat("{0:X}", {16#cafebabe}),
-    <<"CAFEBABE">> = bformat("{0:X}", {16#cafebabe}),
-    <<"755">> = bformat("{0:o}", {8#755}),
-    <<"a">> = bformat("{0:c}", {97}),
-    %% Horizontal ellipsis
-    <<226, 128, 166>> = bformat("{0:c}", {16#2026}),
-    <<"11">> = bformat("{0:b}", {3}),
-    <<"11">> = bformat("{0:b}", [3]),
-    <<"11">> = bformat("{three:b}", [{three, 3}]),
-    <<"11">> = bformat("{three:b}", [{"three", 3}]),
-    <<"11">> = bformat("{three:b}", [{<<"three">>, 3}]),
-    <<"\"foo\"">> = bformat("{0!r}", {"foo"}),
-    <<"2008-5-4">> = bformat("{0.0}-{0.1}-{0.2}", {{2008,5,4}}),
-    <<"2008-05-04">> = bformat("{0.0:04}-{0.1:02}-{0.2:02}", {{2008,5,4}}),
-    <<"foo6bar-6">> = bformat("foo{1}{0}-{1}", {bar, 6}),
-    <<"-'atom test'-">> = bformat("-{arg!r}-", [{arg, 'atom test'}]),
-    <<"2008-05-04">> = bformat("{0.0:0{1.0}}-{0.1:0{1.1}}-{0.2:0{1.2}}",
-                               {{2008,5,4}, {4, 2, 2}}),
-    ok.
-
-std_test() ->
-    M = mochifmt_std:new(),
-    <<"01">> = bformat("{0}{1}", [0, 1], M),
-    ok.
-
-records_test() ->
-    M = mochifmt_records:new([{conversion, record_info(fields, conversion)}]),
-    R = #conversion{length=long, precision=hard, sign=peace},
-    long = M:get_value("length", R),
-    hard = M:get_value("precision", R),
-    peace = M:get_value("sign", R),
-    <<"long hard">> = bformat("{length} {precision}", R, M),
-    <<"long hard">> = bformat("{0.length} {0.precision}", [R], M),
-    ok.
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochifmt_records.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochifmt_records.erl b/src/mochiweb/src/mochifmt_records.erl
deleted file mode 100644
index 2326d1d..0000000
--- a/src/mochiweb/src/mochifmt_records.erl
+++ /dev/null
@@ -1,38 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc Formatter that understands records.
-%%
-%% Usage:
-%%
-%%    1> M = mochifmt_records:new([{rec, record_info(fields, rec)}]),
-%%    M:format("{0.bar}", [#rec{bar=foo}]).
-%%    foo
-
--module(mochifmt_records, [Recs]).
--author('bob@mochimedia.com').
--export([get_value/2]).
-
-get_value(Key, Rec) when is_tuple(Rec) and is_atom(element(1, Rec)) ->
-    try begin
-            Atom = list_to_existing_atom(Key),
-            {_, Fields} = proplists:lookup(element(1, Rec), Recs),
-            element(get_rec_index(Atom, Fields, 2), Rec)
-        end
-    catch error:_ -> mochifmt:get_value(Key, Rec)
-    end;
-get_value(Key, Args) ->
-    mochifmt:get_value(Key, Args).
-
-get_rec_index(Atom, [Atom | _], Index) ->
-    Index;
-get_rec_index(Atom, [_ | Rest], Index) ->
-    get_rec_index(Atom, Rest, 1 + Index).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochifmt_std.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochifmt_std.erl b/src/mochiweb/src/mochifmt_std.erl
deleted file mode 100644
index d4d74f6..0000000
--- a/src/mochiweb/src/mochifmt_std.erl
+++ /dev/null
@@ -1,30 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2008 Mochi Media, Inc.
-
-%% @doc Template module for a mochifmt formatter.
-
--module(mochifmt_std, []).
--author('bob@mochimedia.com').
--export([format/2, get_value/2, format_field/2, get_field/2, convert_field/2]).
-
-format(Format, Args) ->
-    mochifmt:format(Format, Args, THIS).
-
-get_field(Key, Args) ->
-    mochifmt:get_field(Key, Args, THIS).
-
-convert_field(Key, Args) ->
-    mochifmt:convert_field(Key, Args).
-
-get_value(Key, Args) ->
-    mochifmt:get_value(Key, Args).
-
-format_field(Arg, Format) ->
-    mochifmt:format_field(Arg, Format, THIS).
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochiglobal.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochiglobal.erl b/src/mochiweb/src/mochiglobal.erl
deleted file mode 100644
index c740b87..0000000
--- a/src/mochiweb/src/mochiglobal.erl
+++ /dev/null
@@ -1,107 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-%% @doc Abuse module constant pools as a "read-only shared heap" (since erts 5.6)
-%%      <a href="http://www.erlang.org/pipermail/erlang-questions/2009-March/042503.html">[1]</a>.
--module(mochiglobal).
--author("Bob Ippolito <bo...@mochimedia.com>").
--export([get/1, get/2, put/2, delete/1]).
-
--spec get(atom()) -> any() | undefined.
-%% @equiv get(K, undefined)
-get(K) ->
-    get(K, undefined).
-
--spec get(atom(), T) -> any() | T.
-%% @doc Get the term for K or return Default.
-get(K, Default) ->
-    get(K, Default, key_to_module(K)).
-
-get(_K, Default, Mod) ->
-    try Mod:term()
-    catch error:undef ->
-            Default
-    end.
-
--spec put(atom(), any()) -> ok.
-%% @doc Store term V at K, replaces an existing term if present.
-put(K, V) ->
-    put(K, V, key_to_module(K)).
-
-put(_K, V, Mod) ->
-    Bin = compile(Mod, V),
-    code:purge(Mod),
-    code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
-    ok.
-
--spec delete(atom()) -> boolean().
-%% @doc Delete term stored at K, no-op if non-existent.
-delete(K) ->
-    delete(K, key_to_module(K)).
-
-delete(_K, Mod) ->
-    code:purge(Mod),
-    code:delete(Mod).
-
--spec key_to_module(atom()) -> atom().
-key_to_module(K) ->
-    list_to_atom("mochiglobal:" ++ atom_to_list(K)).
-
--spec compile(atom(), any()) -> binary().
-compile(Module, T) ->
-    {ok, Module, Bin} = compile:forms(forms(Module, T),
-                                      [verbose, report_errors]),
-    Bin.
-
--spec forms(atom(), any()) -> [erl_syntax:syntaxTree()].
-forms(Module, T) ->
-    [erl_syntax:revert(X) || X <- term_to_abstract(Module, term, T)].
-
--spec term_to_abstract(atom(), atom(), any()) -> [erl_syntax:syntaxTree()].
-term_to_abstract(Module, Getter, T) ->
-    [%% -module(Module).
-     erl_syntax:attribute(
-       erl_syntax:atom(module),
-       [erl_syntax:atom(Module)]),
-     %% -export([Getter/0]).
-     erl_syntax:attribute(
-       erl_syntax:atom(export),
-       [erl_syntax:list(
-         [erl_syntax:arity_qualifier(
-            erl_syntax:atom(Getter),
-            erl_syntax:integer(0))])]),
-     %% Getter() -> T.
-     erl_syntax:function(
-       erl_syntax:atom(Getter),
-       [erl_syntax:clause([], none, [erl_syntax:abstract(T)])])].
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-get_put_delete_test() ->
-    K = '$$test$$mochiglobal',
-    delete(K),
-    ?assertEqual(
-       bar,
-       get(K, bar)),
-    try
-        ?MODULE:put(K, baz),
-        ?assertEqual(
-           baz,
-           get(K, bar)),
-        ?MODULE:put(K, wibble),
-        ?assertEqual(
-           wibble,
-           ?MODULE:get(K))
-    after
-        delete(K)
-    end,
-    ?assertEqual(
-       bar,
-       get(K, bar)),
-    ?assertEqual(
-       undefined,
-       ?MODULE:get(K)),
-    ok.
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochihex.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochihex.erl b/src/mochiweb/src/mochihex.erl
deleted file mode 100644
index 44a2aa7..0000000
--- a/src/mochiweb/src/mochihex.erl
+++ /dev/null
@@ -1,91 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2006 Mochi Media, Inc.
-
-%% @doc Utilities for working with hexadecimal strings.
-
--module(mochihex).
--author('bob@mochimedia.com').
-
--export([to_hex/1, to_bin/1, to_int/1, dehex/1, hexdigit/1]).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-
-%% @spec to_hex(integer | iolist()) -> string()
-%% @doc Convert an iolist to a hexadecimal string.
-to_hex(0) ->
-    "0";
-to_hex(I) when is_integer(I), I > 0 ->
-    to_hex_int(I, []);
-to_hex(B) ->
-    to_hex(iolist_to_binary(B), []).
-
-%% @spec to_bin(string()) -> binary()
-%% @doc Convert a hexadecimal string to a binary.
-to_bin(L) ->
-    to_bin(L, []).
-
-%% @spec to_int(string()) -> integer()
-%% @doc Convert a hexadecimal string to an integer.
-to_int(L) ->
-    erlang:list_to_integer(L, 16).
-
-%% @spec dehex(char()) -> integer()
-%% @doc Convert a hex digit to its integer value.
-dehex(C) when C >= $0, C =< $9 ->
-    C - $0;
-dehex(C) when C >= $a, C =< $f ->
-    C - $a + 10;
-dehex(C) when C >= $A, C =< $F ->
-    C - $A + 10.
-
-%% @spec hexdigit(integer()) -> char()
-%% @doc Convert an integer less than 16 to a hex digit.
-hexdigit(C) when C >= 0, C =< 9 ->
-    C + $0;
-hexdigit(C) when C =< 15 ->
-    C + $a - 10.
-
-%% Internal API
-
-to_hex(<<>>, Acc) ->
-    lists:reverse(Acc);
-to_hex(<<C1:4, C2:4, Rest/binary>>, Acc) ->
-    to_hex(Rest, [hexdigit(C2), hexdigit(C1) | Acc]).
-
-to_hex_int(0, Acc) ->
-    Acc;
-to_hex_int(I, Acc) ->
-    to_hex_int(I bsr 4, [hexdigit(I band 15) | Acc]).
-
-to_bin([], Acc) ->
-    iolist_to_binary(lists:reverse(Acc));
-to_bin([C1, C2 | Rest], Acc) ->
-    to_bin(Rest, [(dehex(C1) bsl 4) bor dehex(C2) | Acc]).
-
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-to_hex_test() ->
-    "ff000ff1" = to_hex([255, 0, 15, 241]),
-    "ff000ff1" = to_hex(16#ff000ff1),
-    "0" = to_hex(16#0),
-    ok.
-
-to_bin_test() ->
-    <<255, 0, 15, 241>> = to_bin("ff000ff1"),
-    <<255, 0, 10, 161>> = to_bin("Ff000aA1"),
-    ok.
-
-to_int_test() ->
-    16#ff000ff1 = to_int("ff000ff1"),
-    16#ff000aa1 = to_int("FF000Aa1"),
-    16#0 = to_int("0"),
-    ok.
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochijson.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochijson.erl b/src/mochiweb/src/mochijson.erl
deleted file mode 100644
index 2e3d145..0000000
--- a/src/mochiweb/src/mochijson.erl
+++ /dev/null
@@ -1,531 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2006 Mochi Media, Inc.
-
-%% @doc Yet another JSON (RFC 4627) library for Erlang.
--module(mochijson).
--author('bob@mochimedia.com').
--export([encoder/1, encode/1]).
--export([decoder/1, decode/1]).
--export([binary_encoder/1, binary_encode/1]).
--export([binary_decoder/1, binary_decode/1]).
-
-% This is a macro to placate syntax highlighters..
--define(Q, $\").
--define(ADV_COL(S, N), S#decoder{column=N+S#decoder.column}).
--define(INC_COL(S), S#decoder{column=1+S#decoder.column}).
--define(INC_LINE(S), S#decoder{column=1, line=1+S#decoder.line}).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-%% @type json_string() = atom | string() | binary()
-%% @type json_number() = integer() | float()
-%% @type json_array() = {array, [json_term()]}
-%% @type json_object() = {struct, [{json_string(), json_term()}]}
-%% @type json_term() = json_string() | json_number() | json_array() |
-%%                     json_object()
-%% @type encoding() = utf8 | unicode
-%% @type encoder_option() = {input_encoding, encoding()} |
-%%                          {handler, function()}
-%% @type decoder_option() = {input_encoding, encoding()} |
-%%                          {object_hook, function()}
-%% @type bjson_string() = binary()
-%% @type bjson_number() = integer() | float()
-%% @type bjson_array() = [bjson_term()]
-%% @type bjson_object() = {struct, [{bjson_string(), bjson_term()}]}
-%% @type bjson_term() = bjson_string() | bjson_number() | bjson_array() |
-%%                      bjson_object()
-%% @type binary_encoder_option() = {handler, function()}
-%% @type binary_decoder_option() = {object_hook, function()}
-
--record(encoder, {input_encoding=unicode,
-                  handler=null}).
-
--record(decoder, {input_encoding=utf8,
-                  object_hook=null,
-                  line=1,
-                  column=1,
-                  state=null}).
-
-%% @spec encoder([encoder_option()]) -> function()
-%% @doc Create an encoder/1 with the given options.
-encoder(Options) ->
-    State = parse_encoder_options(Options, #encoder{}),
-    fun (O) -> json_encode(O, State) end.
-
-%% @spec encode(json_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist.
-encode(Any) ->
-    json_encode(Any, #encoder{}).
-
-%% @spec decoder([decoder_option()]) -> function()
-%% @doc Create a decoder/1 with the given options.
-decoder(Options) ->
-    State = parse_decoder_options(Options, #decoder{}),
-    fun (O) -> json_decode(O, State) end.
-
-%% @spec decode(iolist()) -> json_term()
-%% @doc Decode the given iolist to Erlang terms.
-decode(S) ->
-    json_decode(S, #decoder{}).
-
-%% @spec binary_decoder([binary_decoder_option()]) -> function()
-%% @doc Create a binary_decoder/1 with the given options.
-binary_decoder(Options) ->
-    mochijson2:decoder(Options).
-
-%% @spec binary_encoder([binary_encoder_option()]) -> function()
-%% @doc Create a binary_encoder/1 with the given options.
-binary_encoder(Options) ->
-    mochijson2:encoder(Options).
-
-%% @spec binary_encode(bjson_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist, using lists for arrays and
-%%      binaries for strings.
-binary_encode(Any) ->
-    mochijson2:encode(Any).
-
-%% @spec binary_decode(iolist()) -> bjson_term()
-%% @doc Decode the given iolist to Erlang terms, using lists for arrays and
-%%      binaries for strings.
-binary_decode(S) ->
-    mochijson2:decode(S).
-
-%% Internal API
-
-parse_encoder_options([], State) ->
-    State;
-parse_encoder_options([{input_encoding, Encoding} | Rest], State) ->
-    parse_encoder_options(Rest, State#encoder{input_encoding=Encoding});
-parse_encoder_options([{handler, Handler} | Rest], State) ->
-    parse_encoder_options(Rest, State#encoder{handler=Handler}).
-
-parse_decoder_options([], State) ->
-    State;
-parse_decoder_options([{input_encoding, Encoding} | Rest], State) ->
-    parse_decoder_options(Rest, State#decoder{input_encoding=Encoding});
-parse_decoder_options([{object_hook, Hook} | Rest], State) ->
-    parse_decoder_options(Rest, State#decoder{object_hook=Hook}).
-
-json_encode(true, _State) ->
-    "true";
-json_encode(false, _State) ->
-    "false";
-json_encode(null, _State) ->
-    "null";
-json_encode(I, _State) when is_integer(I) ->
-    integer_to_list(I);
-json_encode(F, _State) when is_float(F) ->
-    mochinum:digits(F);
-json_encode(L, State) when is_list(L); is_binary(L); is_atom(L) ->
-    json_encode_string(L, State);
-json_encode({array, Props}, State) when is_list(Props) ->
-    json_encode_array(Props, State);
-json_encode({struct, Props}, State) when is_list(Props) ->
-    json_encode_proplist(Props, State);
-json_encode(Bad, #encoder{handler=null}) ->
-    exit({json_encode, {bad_term, Bad}});
-json_encode(Bad, State=#encoder{handler=Handler}) ->
-    json_encode(Handler(Bad), State).
-
-json_encode_array([], _State) ->
-    "[]";
-json_encode_array(L, State) ->
-    F = fun (O, Acc) ->
-                [$,, json_encode(O, State) | Acc]
-        end,
-    [$, | Acc1] = lists:foldl(F, "[", L),
-    lists:reverse([$\] | Acc1]).
-
-json_encode_proplist([], _State) ->
-    "{}";
-json_encode_proplist(Props, State) ->
-    F = fun ({K, V}, Acc) ->
-                KS = case K of 
-                         K when is_atom(K) ->
-                             json_encode_string_utf8(atom_to_list(K));
-                         K when is_integer(K) ->
-                             json_encode_string(integer_to_list(K), State);
-                         K when is_list(K); is_binary(K) ->
-                             json_encode_string(K, State)
-                     end,
-                VS = json_encode(V, State),
-                [$,, VS, $:, KS | Acc]
-        end,
-    [$, | Acc1] = lists:foldl(F, "{", Props),
-    lists:reverse([$\} | Acc1]).
-
-json_encode_string(A, _State) when is_atom(A) ->
-    json_encode_string_unicode(xmerl_ucs:from_utf8(atom_to_list(A)));
-json_encode_string(B, _State) when is_binary(B) ->
-    json_encode_string_unicode(xmerl_ucs:from_utf8(B));
-json_encode_string(S, #encoder{input_encoding=utf8}) ->
-    json_encode_string_utf8(S);
-json_encode_string(S, #encoder{input_encoding=unicode}) ->
-    json_encode_string_unicode(S).
-
-json_encode_string_utf8(S) ->
-    [?Q | json_encode_string_utf8_1(S)].
-
-json_encode_string_utf8_1([C | Cs]) when C >= 0, C =< 16#7f ->
-    NewC = case C of
-               $\\ -> "\\\\";
-               ?Q -> "\\\"";
-               _ when C >= $\s, C < 16#7f -> C;
-               $\t -> "\\t";
-               $\n -> "\\n";
-               $\r -> "\\r";
-               $\f -> "\\f";
-               $\b -> "\\b";
-               _ when C >= 0, C =< 16#7f -> unihex(C);
-               _ -> exit({json_encode, {bad_char, C}})
-           end,
-    [NewC | json_encode_string_utf8_1(Cs)];
-json_encode_string_utf8_1(All=[C | _]) when C >= 16#80, C =< 16#10FFFF ->
-    [?Q | Rest] = json_encode_string_unicode(xmerl_ucs:from_utf8(All)),
-    Rest;
-json_encode_string_utf8_1([]) ->
-    "\"".
-
-json_encode_string_unicode(S) ->
-    [?Q | json_encode_string_unicode_1(S)].
-
-json_encode_string_unicode_1([C | Cs]) ->
-    NewC = case C of
-               $\\ -> "\\\\";
-               ?Q -> "\\\"";
-               _ when C >= $\s, C < 16#7f -> C;
-               $\t -> "\\t";
-               $\n -> "\\n";
-               $\r -> "\\r";
-               $\f -> "\\f";
-               $\b -> "\\b";
-               _ when C >= 0, C =< 16#10FFFF -> unihex(C);
-               _ -> exit({json_encode, {bad_char, C}})
-           end,
-    [NewC | json_encode_string_unicode_1(Cs)];
-json_encode_string_unicode_1([]) ->
-    "\"".
-
-dehex(C) when C >= $0, C =< $9 ->
-    C - $0;
-dehex(C) when C >= $a, C =< $f ->
-    C - $a + 10;
-dehex(C) when C >= $A, C =< $F ->
-    C - $A + 10.
-
-hexdigit(C) when C >= 0, C =< 9 ->
-    C + $0;
-hexdigit(C) when C =< 15 ->
-    C + $a - 10.
-
-unihex(C) when C < 16#10000 ->
-    <<D3:4, D2:4, D1:4, D0:4>> = <<C:16>>,
-    Digits = [hexdigit(D) || D <- [D3, D2, D1, D0]],
-    [$\\, $u | Digits];
-unihex(C) when C =< 16#10FFFF ->
-    N = C - 16#10000,
-    S1 = 16#d800 bor ((N bsr 10) band 16#3ff),
-    S2 = 16#dc00 bor (N band 16#3ff),
-    [unihex(S1), unihex(S2)].
-
-json_decode(B, S) when is_binary(B) ->
-    json_decode(binary_to_list(B), S);
-json_decode(L, S) ->
-    {Res, L1, S1} = decode1(L, S),
-    {eof, [], _} = tokenize(L1, S1#decoder{state=trim}),
-    Res.
-
-decode1(L, S=#decoder{state=null}) ->
-    case tokenize(L, S#decoder{state=any}) of
-        {{const, C}, L1, S1} ->
-            {C, L1, S1};
-        {start_array, L1, S1} ->
-            decode_array(L1, S1#decoder{state=any}, []);
-        {start_object, L1, S1} ->
-            decode_object(L1, S1#decoder{state=key}, [])
-    end.
-
-make_object(V, #decoder{object_hook=null}) ->
-    V;
-make_object(V, #decoder{object_hook=Hook}) ->
-    Hook(V).
-
-decode_object(L, S=#decoder{state=key}, Acc) ->
-    case tokenize(L, S) of
-        {end_object, Rest, S1} ->
-            V = make_object({struct, lists:reverse(Acc)}, S1),
-            {V, Rest, S1#decoder{state=null}};
-        {{const, K}, Rest, S1} when is_list(K) ->
-            {colon, L2, S2} = tokenize(Rest, S1),
-            {V, L3, S3} = decode1(L2, S2#decoder{state=null}),
-            decode_object(L3, S3#decoder{state=comma}, [{K, V} | Acc])
-    end;
-decode_object(L, S=#decoder{state=comma}, Acc) ->
-    case tokenize(L, S) of
-        {end_object, Rest, S1} ->
-            V = make_object({struct, lists:reverse(Acc)}, S1),
-            {V, Rest, S1#decoder{state=null}};
-        {comma, Rest, S1} ->
-            decode_object(Rest, S1#decoder{state=key}, Acc)
-    end.
-
-decode_array(L, S=#decoder{state=any}, Acc) ->
-    case tokenize(L, S) of
-        {end_array, Rest, S1} ->
-            {{array, lists:reverse(Acc)}, Rest, S1#decoder{state=null}};
-        {start_array, Rest, S1} ->
-            {Array, Rest1, S2} = decode_array(Rest, S1#decoder{state=any}, []),
-            decode_array(Rest1, S2#decoder{state=comma}, [Array | Acc]);
-        {start_object, Rest, S1} ->
-            {Array, Rest1, S2} = decode_object(Rest, S1#decoder{state=key}, []),
-            decode_array(Rest1, S2#decoder{state=comma}, [Array | Acc]);
-        {{const, Const}, Rest, S1} ->
-            decode_array(Rest, S1#decoder{state=comma}, [Const | Acc])
-    end;
-decode_array(L, S=#decoder{state=comma}, Acc) ->
-    case tokenize(L, S) of
-        {end_array, Rest, S1} ->
-            {{array, lists:reverse(Acc)}, Rest, S1#decoder{state=null}};
-        {comma, Rest, S1} ->
-            decode_array(Rest, S1#decoder{state=any}, Acc)
-    end.
-
-tokenize_string(IoList=[C | _], S=#decoder{input_encoding=utf8}, Acc)
-  when is_list(C); is_binary(C); C >= 16#7f ->
-    List = xmerl_ucs:from_utf8(iolist_to_binary(IoList)),
-    tokenize_string(List, S#decoder{input_encoding=unicode}, Acc);
-tokenize_string("\"" ++ Rest, S, Acc) ->
-    {lists:reverse(Acc), Rest, ?INC_COL(S)};
-tokenize_string("\\\"" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\" | Acc]);
-tokenize_string("\\\\" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\\ | Acc]);
-tokenize_string("\\/" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$/ | Acc]);
-tokenize_string("\\b" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\b | Acc]);
-tokenize_string("\\f" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\f | Acc]);
-tokenize_string("\\n" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\n | Acc]);
-tokenize_string("\\r" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\r | Acc]);
-tokenize_string("\\t" ++ Rest, S, Acc) ->
-    tokenize_string(Rest, ?ADV_COL(S, 2), [$\t | Acc]);
-tokenize_string([$\\, $u, C3, C2, C1, C0 | Rest], S, Acc) ->
-    % coalesce UTF-16 surrogate pair?
-    C = dehex(C0) bor
-        (dehex(C1) bsl 4) bor
-        (dehex(C2) bsl 8) bor 
-        (dehex(C3) bsl 12),
-    tokenize_string(Rest, ?ADV_COL(S, 6), [C | Acc]);
-tokenize_string([C | Rest], S, Acc) when C >= $\s; C < 16#10FFFF ->
-    tokenize_string(Rest, ?ADV_COL(S, 1), [C | Acc]).
-    
-tokenize_number(IoList=[C | _], Mode, S=#decoder{input_encoding=utf8}, Acc)
-  when is_list(C); is_binary(C); C >= 16#7f ->
-    List = xmerl_ucs:from_utf8(iolist_to_binary(IoList)),
-    tokenize_number(List, Mode, S#decoder{input_encoding=unicode}, Acc);
-tokenize_number([$- | Rest], sign, S, []) ->
-    tokenize_number(Rest, int, ?INC_COL(S), [$-]);
-tokenize_number(Rest, sign, S, []) ->
-    tokenize_number(Rest, int, S, []);
-tokenize_number([$0 | Rest], int, S, Acc) ->
-    tokenize_number(Rest, frac, ?INC_COL(S), [$0 | Acc]);
-tokenize_number([C | Rest], int, S, Acc) when C >= $1, C =< $9 ->
-    tokenize_number(Rest, int1, ?INC_COL(S), [C | Acc]);
-tokenize_number([C | Rest], int1, S, Acc) when C >= $0, C =< $9 ->
-    tokenize_number(Rest, int1, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, int1, S, Acc) ->
-    tokenize_number(Rest, frac, S, Acc);
-tokenize_number([$., C | Rest], frac, S, Acc) when C >= $0, C =< $9 ->
-    tokenize_number(Rest, frac1, ?ADV_COL(S, 2), [C, $. | Acc]);
-tokenize_number([E | Rest], frac, S, Acc) when E == $e; E == $E ->
-    tokenize_number(Rest, esign, ?INC_COL(S), [$e, $0, $. | Acc]);
-tokenize_number(Rest, frac, S, Acc) ->
-    {{int, lists:reverse(Acc)}, Rest, S};
-tokenize_number([C | Rest], frac1, S, Acc) when C >= $0, C =< $9 ->
-    tokenize_number(Rest, frac1, ?INC_COL(S), [C | Acc]);
-tokenize_number([E | Rest], frac1, S, Acc) when E == $e; E == $E ->
-    tokenize_number(Rest, esign, ?INC_COL(S), [$e | Acc]);
-tokenize_number(Rest, frac1, S, Acc) ->
-    {{float, lists:reverse(Acc)}, Rest, S};
-tokenize_number([C | Rest], esign, S, Acc) when C == $-; C == $+ ->
-    tokenize_number(Rest, eint, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, esign, S, Acc) ->
-    tokenize_number(Rest, eint, S, Acc);
-tokenize_number([C | Rest], eint, S, Acc) when C >= $0, C =< $9 ->
-    tokenize_number(Rest, eint1, ?INC_COL(S), [C | Acc]);
-tokenize_number([C | Rest], eint1, S, Acc) when C >= $0, C =< $9 ->
-    tokenize_number(Rest, eint1, ?INC_COL(S), [C | Acc]);
-tokenize_number(Rest, eint1, S, Acc) ->
-    {{float, lists:reverse(Acc)}, Rest, S}.
-
-tokenize([], S=#decoder{state=trim}) ->
-    {eof, [], S};
-tokenize([L | Rest], S) when is_list(L) ->
-    tokenize(L ++ Rest, S);
-tokenize([B | Rest], S) when is_binary(B) ->
-    tokenize(xmerl_ucs:from_utf8(B) ++ Rest, S);
-tokenize("\r\n" ++ Rest, S) ->
-    tokenize(Rest, ?INC_LINE(S));
-tokenize("\n" ++ Rest, S) ->
-    tokenize(Rest, ?INC_LINE(S));
-tokenize([C | Rest], S) when C == $\s; C == $\t ->
-    tokenize(Rest, ?INC_COL(S));
-tokenize("{" ++ Rest, S) ->
-    {start_object, Rest, ?INC_COL(S)};
-tokenize("}" ++ Rest, S) ->
-    {end_object, Rest, ?INC_COL(S)};
-tokenize("[" ++ Rest, S) ->
-    {start_array, Rest, ?INC_COL(S)};
-tokenize("]" ++ Rest, S) ->
-    {end_array, Rest, ?INC_COL(S)};
-tokenize("," ++ Rest, S) ->
-    {comma, Rest, ?INC_COL(S)};
-tokenize(":" ++ Rest, S) ->
-    {colon, Rest, ?INC_COL(S)};
-tokenize("null" ++ Rest, S) ->
-    {{const, null}, Rest, ?ADV_COL(S, 4)};
-tokenize("true" ++ Rest, S) ->
-    {{const, true}, Rest, ?ADV_COL(S, 4)};
-tokenize("false" ++ Rest, S) ->
-    {{const, false}, Rest, ?ADV_COL(S, 5)};
-tokenize("\"" ++ Rest, S) ->
-    {String, Rest1, S1} = tokenize_string(Rest, ?INC_COL(S), []),
-    {{const, String}, Rest1, S1};
-tokenize(L=[C | _], S) when C >= $0, C =< $9; C == $- ->
-    case tokenize_number(L, sign, S, []) of
-        {{int, Int}, Rest, S1} ->
-            {{const, list_to_integer(Int)}, Rest, S1};
-        {{float, Float}, Rest, S1} ->
-            {{const, list_to_float(Float)}, Rest, S1}
-    end.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-%% testing constructs borrowed from the Yaws JSON implementation.
-
-%% Create an object from a list of Key/Value pairs.
-
-obj_new() ->
-    {struct, []}.
-
-is_obj({struct, Props}) ->
-    F = fun ({K, _}) when is_list(K) ->
-                true;
-            (_) ->
-                false
-        end,    
-    lists:all(F, Props).
-
-obj_from_list(Props) ->
-    Obj = {struct, Props},
-    case is_obj(Obj) of
-        true -> Obj;
-        false -> exit(json_bad_object)
-    end.
-
-%% Test for equivalence of Erlang terms.
-%% Due to arbitrary order of construction, equivalent objects might
-%% compare unequal as erlang terms, so we need to carefully recurse
-%% through aggregates (tuples and objects).
-
-equiv({struct, Props1}, {struct, Props2}) ->
-    equiv_object(Props1, Props2);
-equiv({array, L1}, {array, L2}) ->
-    equiv_list(L1, L2);
-equiv(N1, N2) when is_number(N1), is_number(N2) -> N1 == N2;
-equiv(S1, S2) when is_list(S1), is_list(S2)     -> S1 == S2;
-equiv(true, true) -> true;
-equiv(false, false) -> true;
-equiv(null, null) -> true.
-
-%% Object representation and traversal order is unknown.
-%% Use the sledgehammer and sort property lists.
-
-equiv_object(Props1, Props2) ->
-    L1 = lists:keysort(1, Props1),
-    L2 = lists:keysort(1, Props2),
-    Pairs = lists:zip(L1, L2),
-    true = lists:all(fun({{K1, V1}, {K2, V2}}) ->
-        equiv(K1, K2) and equiv(V1, V2)
-    end, Pairs).
-
-%% Recursively compare tuple elements for equivalence.
-
-equiv_list([], []) ->
-    true;
-equiv_list([V1 | L1], [V2 | L2]) ->
-    equiv(V1, V2) andalso equiv_list(L1, L2).
-
-e2j_vec_test() ->
-    test_one(e2j_test_vec(utf8), 1).
-
-issue33_test() ->
-    %% http://code.google.com/p/mochiweb/issues/detail?id=33
-    Js = {struct, [{"key", [194, 163]}]},
-    Encoder = encoder([{input_encoding, utf8}]),
-    "{\"key\":\"\\u00a3\"}" = lists:flatten(Encoder(Js)).
-
-test_one([], _N) ->
-    %% io:format("~p tests passed~n", [N-1]),
-    ok;
-test_one([{E, J} | Rest], N) ->
-    %% io:format("[~p] ~p ~p~n", [N, E, J]),
-    true = equiv(E, decode(J)),
-    true = equiv(E, decode(encode(E))),
-    test_one(Rest, 1+N).
-
-e2j_test_vec(utf8) ->
-    [
-    {1, "1"},
-    {3.1416, "3.14160"}, % text representation may truncate, trail zeroes
-    {-1, "-1"},
-    {-3.1416, "-3.14160"},
-    {12.0e10, "1.20000e+11"},
-    {1.234E+10, "1.23400e+10"},
-    {-1.234E-10, "-1.23400e-10"},
-    {10.0, "1.0e+01"},
-    {123.456, "1.23456E+2"},
-    {10.0, "1e1"},
-    {"foo", "\"foo\""},
-    {"foo" ++ [5] ++ "bar", "\"foo\\u0005bar\""},
-    {"", "\"\""},
-    {"\"", "\"\\\"\""},
-    {"\n\n\n", "\"\\n\\n\\n\""},
-    {"\\", "\"\\\\\""},
-    {"\" \b\f\r\n\t\"", "\"\\\" \\b\\f\\r\\n\\t\\\"\""},
-    {obj_new(), "{}"},
-    {obj_from_list([{"foo", "bar"}]), "{\"foo\":\"bar\"}"},
-    {obj_from_list([{"foo", "bar"}, {"baz", 123}]),
-     "{\"foo\":\"bar\",\"baz\":123}"},
-    {{array, []}, "[]"},
-    {{array, [{array, []}]}, "[[]]"},
-    {{array, [1, "foo"]}, "[1,\"foo\"]"},
-
-    % json array in a json object
-    {obj_from_list([{"foo", {array, [123]}}]),
-     "{\"foo\":[123]}"},
-
-    % json object in a json object
-    {obj_from_list([{"foo", obj_from_list([{"bar", true}])}]),
-     "{\"foo\":{\"bar\":true}}"},
-
-    % fold evaluation order
-    {obj_from_list([{"foo", {array, []}},
-                     {"bar", obj_from_list([{"baz", true}])},
-                     {"alice", "bob"}]),
-     "{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}"},
-
-    % json object in a json array
-    {{array, [-123, "foo", obj_from_list([{"bar", {array, []}}]), null]},
-     "[-123,\"foo\",{\"bar\":[]},null]"}
-    ].
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochijson2.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochijson2.erl b/src/mochiweb/src/mochijson2.erl
deleted file mode 100644
index bdf6d77..0000000
--- a/src/mochiweb/src/mochijson2.erl
+++ /dev/null
@@ -1,849 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2007 Mochi Media, Inc.
-
-%% @doc Yet another JSON (RFC 4627) library for Erlang. mochijson2 works
-%%      with binaries as strings, arrays as lists (without an {array, _})
-%%      wrapper and it only knows how to decode UTF-8 (and ASCII).
-%%
-%%      JSON terms are decoded as follows (javascript -> erlang):
-%%      <ul>
-%%          <li>{"key": "value"} ->
-%%              {struct, [{&lt;&lt;"key">>, &lt;&lt;"value">>}]}</li>
-%%          <li>["array", 123, 12.34, true, false, null] ->
-%%              [&lt;&lt;"array">>, 123, 12.34, true, false, null]
-%%          </li>
-%%      </ul>
-%%      <ul>
-%%          <li>Strings in JSON decode to UTF-8 binaries in Erlang</li>
-%%          <li>Objects decode to {struct, PropList}</li>
-%%          <li>Numbers decode to integer or float</li>
-%%          <li>true, false, null decode to their respective terms.</li>
-%%      </ul>
-%%      The encoder will accept the same format that the decoder will produce,
-%%      but will also allow additional cases for leniency:
-%%      <ul>
-%%          <li>atoms other than true, false, null will be considered UTF-8
-%%              strings (even as a proplist key)
-%%          </li>
-%%          <li>{json, IoList} will insert IoList directly into the output
-%%              with no validation
-%%          </li>
-%%          <li>{array, Array} will be encoded as Array
-%%              (legacy mochijson style)
-%%          </li>
-%%          <li>A non-empty raw proplist will be encoded as an object as long
-%%              as the first pair does not have an atom key of json, struct,
-%%              or array
-%%          </li>
-%%      </ul>
-
--module(mochijson2).
--author('bob@mochimedia.com').
--export([encoder/1, encode/1]).
--export([decoder/1, decode/1]).
-
-% This is a macro to placate syntax highlighters..
--define(Q, $\").
--define(ADV_COL(S, N), S#decoder{offset=N+S#decoder.offset,
-                                 column=N+S#decoder.column}).
--define(INC_COL(S), S#decoder{offset=1+S#decoder.offset,
-                              column=1+S#decoder.column}).
--define(INC_LINE(S), S#decoder{offset=1+S#decoder.offset,
-                               column=1,
-                               line=1+S#decoder.line}).
--define(INC_CHAR(S, C),
-        case C of
-            $\n ->
-                S#decoder{column=1,
-                          line=1+S#decoder.line,
-                          offset=1+S#decoder.offset};
-            _ ->
-                S#decoder{column=1+S#decoder.column,
-                          offset=1+S#decoder.offset}
-        end).
--define(IS_WHITESPACE(C),
-        (C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
-
-%% @type iolist() = [char() | binary() | iolist()]
-%% @type iodata() = iolist() | binary()
-%% @type json_string() = atom | binary()
-%% @type json_number() = integer() | float()
-%% @type json_array() = [json_term()]
-%% @type json_object() = {struct, [{json_string(), json_term()}]}
-%% @type json_iolist() = {json, iolist()}
-%% @type json_term() = json_string() | json_number() | json_array() |
-%%                     json_object() | json_iolist()
-
--record(encoder, {handler=null,
-                  utf8=false}).
-
--record(decoder, {object_hook=null,
-                  offset=0,
-                  line=1,
-                  column=1,
-                  state=null}).
-
-%% @spec encoder([encoder_option()]) -> function()
-%% @doc Create an encoder/1 with the given options.
-%% @type encoder_option() = handler_option() | utf8_option()
-%% @type utf8_option() = boolean(). Emit unicode as utf8 (default - false)
-encoder(Options) ->
-    State = parse_encoder_options(Options, #encoder{}),
-    fun (O) -> json_encode(O, State) end.
-
-%% @spec encode(json_term()) -> iolist()
-%% @doc Encode the given as JSON to an iolist.
-encode(Any) ->
-    json_encode(Any, #encoder{}).
-
-%% @spec decoder([decoder_option()]) -> function()
-%% @doc Create a decoder/1 with the given options.
-decoder(Options) ->
-    State = parse_decoder_options(Options, #decoder{}),
-    fun (O) -> json_decode(O, State) end.
-
-%% @spec decode(iolist()) -> json_term()
-%% @doc Decode the given iolist to Erlang terms.
-decode(S) ->
-    json_decode(S, #decoder{}).
-
-%% Internal API
-
-parse_encoder_options([], State) ->
-    State;
-parse_encoder_options([{handler, Handler} | Rest], State) ->
-    parse_encoder_options(Rest, State#encoder{handler=Handler});
-parse_encoder_options([{utf8, Switch} | Rest], State) ->
-    parse_encoder_options(Rest, State#encoder{utf8=Switch}).
-
-parse_decoder_options([], State) ->
-    State;
-parse_decoder_options([{object_hook, Hook} | Rest], State) ->
-    parse_decoder_options(Rest, State#decoder{object_hook=Hook}).
-
-json_encode(true, _State) ->
-    <<"true">>;
-json_encode(false, _State) ->
-    <<"false">>;
-json_encode(null, _State) ->
-    <<"null">>;
-json_encode(I, _State) when is_integer(I) ->
-    integer_to_list(I);
-json_encode(F, _State) when is_float(F) ->
-    mochinum:digits(F);
-json_encode(S, State) when is_binary(S); is_atom(S) ->
-    json_encode_string(S, State);
-json_encode([{K, _}|_] = Props, State) when (K =/= struct andalso
-                                             K =/= array andalso
-                                             K =/= json) ->
-    json_encode_proplist(Props, State);
-json_encode({struct, Props}, State) when is_list(Props) ->
-    json_encode_proplist(Props, State);
-json_encode(Array, State) when is_list(Array) ->
-    json_encode_array(Array, State);
-json_encode({array, Array}, State) when is_list(Array) ->
-    json_encode_array(Array, State);
-json_encode({json, IoList}, _State) ->
-    IoList;
-json_encode(Bad, #encoder{handler=null}) ->
-    exit({json_encode, {bad_term, Bad}});
-json_encode(Bad, State=#encoder{handler=Handler}) ->
-    json_encode(Handler(Bad), State).
-
-json_encode_array([], _State) ->
-    <<"[]">>;
-json_encode_array(L, State) ->
-    F = fun (O, Acc) ->
-                [$,, json_encode(O, State) | Acc]
-        end,
-    [$, | Acc1] = lists:foldl(F, "[", L),
-    lists:reverse([$\] | Acc1]).
-
-json_encode_proplist([], _State) ->
-    <<"{}">>;
-json_encode_proplist(Props, State) ->
-    F = fun ({K, V}, Acc) ->
-                KS = json_encode_string(K, State),
-                VS = json_encode(V, State),
-                [$,, VS, $:, KS | Acc]
-        end,
-    [$, | Acc1] = lists:foldl(F, "{", Props),
-    lists:reverse([$\} | Acc1]).
-
-json_encode_string(A, State) when is_atom(A) ->
-    L = atom_to_list(A),
-    case json_string_is_safe(L) of
-        true ->
-            [?Q, L, ?Q];
-        false ->
-            json_encode_string_unicode(xmerl_ucs:from_utf8(L), State, [?Q])
-    end;
-json_encode_string(B, State) when is_binary(B) ->
-    case json_bin_is_safe(B) of
-        true ->
-            [?Q, B, ?Q];
-        false ->
-            json_encode_string_unicode(xmerl_ucs:from_utf8(B), State, [?Q])
-    end;
-json_encode_string(I, _State) when is_integer(I) ->
-    [?Q, integer_to_list(I), ?Q];
-json_encode_string(L, State) when is_list(L) ->
-    case json_string_is_safe(L) of
-        true ->
-            [?Q, L, ?Q];
-        false ->
-            json_encode_string_unicode(L, State, [?Q])
-    end.
-
-json_string_is_safe([]) ->
-    true;
-json_string_is_safe([C | Rest]) ->
-    case C of
-        ?Q ->
-            false;
-        $\\ ->
-            false;
-        $\b ->
-            false;
-        $\f ->
-            false;
-        $\n ->
-            false;
-        $\r ->
-            false;
-        $\t ->
-            false;
-        C when C >= 0, C < $\s; C >= 16#7f, C =< 16#10FFFF ->
-            false;
-        C when C < 16#7f ->
-            json_string_is_safe(Rest);
-        _ ->
-            false
-    end.
-
-json_bin_is_safe(<<>>) ->
-    true;
-json_bin_is_safe(<<C, Rest/binary>>) ->
-    case C of
-        ?Q ->
-            false;
-        $\\ ->
-            false;
-        $\b ->
-            false;
-        $\f ->
-            false;
-        $\n ->
-            false;
-        $\r ->
-            false;
-        $\t ->
-            false;
-        C when C >= 0, C < $\s; C >= 16#7f ->
-            false;
-        C when C < 16#7f ->
-            json_bin_is_safe(Rest)
-    end.
-
-json_encode_string_unicode([], _State, Acc) ->
-    lists:reverse([$\" | Acc]);
-json_encode_string_unicode([C | Cs], State, Acc) ->
-    Acc1 = case C of
-               ?Q ->
-                   [?Q, $\\ | Acc];
-               %% Escaping solidus is only useful when trying to protect
-               %% against "</script>" injection attacks which are only
-               %% possible when JSON is inserted into a HTML document
-               %% in-line. mochijson2 does not protect you from this, so
-               %% if you do insert directly into HTML then you need to
-               %% uncomment the following case or escape the output of encode.
-               %%
-               %% $/ ->
-               %%    [$/, $\\ | Acc];
-               %%
-               $\\ ->
-                   [$\\, $\\ | Acc];
-               $\b ->
-                   [$b, $\\ | Acc];
-               $\f ->
-                   [$f, $\\ | Acc];
-               $\n ->
-                   [$n, $\\ | Acc];
-               $\r ->
-                   [$r, $\\ | Acc];
-               $\t ->
-                   [$t, $\\ | Acc];
-               C when C >= 0, C < $\s ->
-                   [unihex(C) | Acc];
-               C when C >= 16#7f, C =< 16#10FFFF, State#encoder.utf8 ->
-                   [xmerl_ucs:to_utf8(C) | Acc];
-               C when  C >= 16#7f, C =< 16#10FFFF, not State#encoder.utf8 ->
-                   [unihex(C) | Acc];
-               C when C < 16#7f ->
-                   [C | Acc];
-               _ ->
-                   exit({json_encode, {bad_char, C}})
-           end,
-    json_encode_string_unicode(Cs, State, Acc1).
-
-hexdigit(C) when C >= 0, C =< 9 ->
-    C + $0;
-hexdigit(C) when C =< 15 ->
-    C + $a - 10.
-
-unihex(C) when C < 16#10000 ->
-    <<D3:4, D2:4, D1:4, D0:4>> = <<C:16>>,
-    Digits = [hexdigit(D) || D <- [D3, D2, D1, D0]],
-    [$\\, $u | Digits];
-unihex(C) when C =< 16#10FFFF ->
-    N = C - 16#10000,
-    S1 = 16#d800 bor ((N bsr 10) band 16#3ff),
-    S2 = 16#dc00 bor (N band 16#3ff),
-    [unihex(S1), unihex(S2)].
-
-json_decode(L, S) when is_list(L) ->
-    json_decode(iolist_to_binary(L), S);
-json_decode(B, S) ->
-    {Res, S1} = decode1(B, S),
-    {eof, _} = tokenize(B, S1#decoder{state=trim}),
-    Res.
-
-decode1(B, S=#decoder{state=null}) ->
-    case tokenize(B, S#decoder{state=any}) of
-        {{const, C}, S1} ->
-            {C, S1};
-        {start_array, S1} ->
-            decode_array(B, S1);
-        {start_object, S1} ->
-            decode_object(B, S1)
-    end.
-
-make_object(V, #decoder{object_hook=null}) ->
-    V;
-make_object(V, #decoder{object_hook=Hook}) ->
-    Hook(V).
-
-decode_object(B, S) ->
-    decode_object(B, S#decoder{state=key}, []).
-
-decode_object(B, S=#decoder{state=key}, Acc) ->
-    case tokenize(B, S) of
-        {end_object, S1} ->
-            V = make_object({struct, lists:reverse(Acc)}, S1),
-            {V, S1#decoder{state=null}};
-        {{const, K}, S1} ->
-            {colon, S2} = tokenize(B, S1),
-            {V, S3} = decode1(B, S2#decoder{state=null}),
-            decode_object(B, S3#decoder{state=comma}, [{K, V} | Acc])
-    end;
-decode_object(B, S=#decoder{state=comma}, Acc) ->
-    case tokenize(B, S) of
-        {end_object, S1} ->
-            V = make_object({struct, lists:reverse(Acc)}, S1),
-            {V, S1#decoder{state=null}};
-        {comma, S1} ->
-            decode_object(B, S1#decoder{state=key}, Acc)
-    end.
-
-decode_array(B, S) ->
-    decode_array(B, S#decoder{state=any}, []).
-
-decode_array(B, S=#decoder{state=any}, Acc) ->
-    case tokenize(B, S) of
-        {end_array, S1} ->
-            {lists:reverse(Acc), S1#decoder{state=null}};
-        {start_array, S1} ->
-            {Array, S2} = decode_array(B, S1),
-            decode_array(B, S2#decoder{state=comma}, [Array | Acc]);
-        {start_object, S1} ->
-            {Array, S2} = decode_object(B, S1),
-            decode_array(B, S2#decoder{state=comma}, [Array | Acc]);
-        {{const, Const}, S1} ->
-            decode_array(B, S1#decoder{state=comma}, [Const | Acc])
-    end;
-decode_array(B, S=#decoder{state=comma}, Acc) ->
-    case tokenize(B, S) of
-        {end_array, S1} ->
-            {lists:reverse(Acc), S1#decoder{state=null}};
-        {comma, S1} ->
-            decode_array(B, S1#decoder{state=any}, Acc)
-    end.
-
-tokenize_string(B, S=#decoder{offset=O}) ->
-    case tokenize_string_fast(B, O) of
-        {escape, O1} ->
-            Length = O1 - O,
-            S1 = ?ADV_COL(S, Length),
-            <<_:O/binary, Head:Length/binary, _/binary>> = B,
-            tokenize_string(B, S1, lists:reverse(binary_to_list(Head)));
-        O1 ->
-            Length = O1 - O,
-            <<_:O/binary, String:Length/binary, ?Q, _/binary>> = B,
-            {{const, String}, ?ADV_COL(S, Length + 1)}
-    end.
-
-tokenize_string_fast(B, O) ->
-    case B of
-        <<_:O/binary, ?Q, _/binary>> ->
-            O;
-        <<_:O/binary, $\\, _/binary>> ->
-            {escape, O};
-        <<_:O/binary, C1, _/binary>> when C1 < 128 ->
-            tokenize_string_fast(B, 1 + O);
-        <<_:O/binary, C1, C2, _/binary>> when C1 >= 194, C1 =< 223,
-                C2 >= 128, C2 =< 191 ->
-            tokenize_string_fast(B, 2 + O);
-        <<_:O/binary, C1, C2, C3, _/binary>> when C1 >= 224, C1 =< 239,
-                C2 >= 128, C2 =< 191,
-                C3 >= 128, C3 =< 191 ->
-            tokenize_string_fast(B, 3 + O);
-        <<_:O/binary, C1, C2, C3, C4, _/binary>> when C1 >= 240, C1 =< 244,
-                C2 >= 128, C2 =< 191,
-                C3 >= 128, C3 =< 191,
-                C4 >= 128, C4 =< 191 ->
-            tokenize_string_fast(B, 4 + O);
-        _ ->
-            throw(invalid_utf8)
-    end.
-
-tokenize_string(B, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, ?Q, _/binary>> ->
-            {{const, iolist_to_binary(lists:reverse(Acc))}, ?INC_COL(S)};
-        <<_:O/binary, "\\\"", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\" | Acc]);
-        <<_:O/binary, "\\\\", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\\ | Acc]);
-        <<_:O/binary, "\\/", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$/ | Acc]);
-        <<_:O/binary, "\\b", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\b | Acc]);
-        <<_:O/binary, "\\f", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\f | Acc]);
-        <<_:O/binary, "\\n", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\n | Acc]);
-        <<_:O/binary, "\\r", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\r | Acc]);
-        <<_:O/binary, "\\t", _/binary>> ->
-            tokenize_string(B, ?ADV_COL(S, 2), [$\t | Acc]);
-        <<_:O/binary, "\\u", C3, C2, C1, C0, Rest/binary>> ->
-            C = erlang:list_to_integer([C3, C2, C1, C0], 16),
-            if C > 16#D7FF, C < 16#DC00 ->
-                %% coalesce UTF-16 surrogate pair
-                <<"\\u", D3, D2, D1, D0, _/binary>> = Rest,
-                D = erlang:list_to_integer([D3,D2,D1,D0], 16),
-                [CodePoint] = xmerl_ucs:from_utf16be(<<C:16/big-unsigned-integer,
-                    D:16/big-unsigned-integer>>),
-                Acc1 = lists:reverse(xmerl_ucs:to_utf8(CodePoint), Acc),
-                tokenize_string(B, ?ADV_COL(S, 12), Acc1);
-            true ->
-                Acc1 = lists:reverse(xmerl_ucs:to_utf8(C), Acc),
-                tokenize_string(B, ?ADV_COL(S, 6), Acc1)
-            end;
-        <<_:O/binary, C1, _/binary>> when C1 < 128 ->
-            tokenize_string(B, ?INC_CHAR(S, C1), [C1 | Acc]);
-        <<_:O/binary, C1, C2, _/binary>> when C1 >= 194, C1 =< 223,
-                C2 >= 128, C2 =< 191 ->
-            tokenize_string(B, ?ADV_COL(S, 2), [C2, C1 | Acc]);
-        <<_:O/binary, C1, C2, C3, _/binary>> when C1 >= 224, C1 =< 239,
-                C2 >= 128, C2 =< 191,
-                C3 >= 128, C3 =< 191 ->
-            tokenize_string(B, ?ADV_COL(S, 3), [C3, C2, C1 | Acc]);
-        <<_:O/binary, C1, C2, C3, C4, _/binary>> when C1 >= 240, C1 =< 244,
-                C2 >= 128, C2 =< 191,
-                C3 >= 128, C3 =< 191,
-                C4 >= 128, C4 =< 191 ->
-            tokenize_string(B, ?ADV_COL(S, 4), [C4, C3, C2, C1 | Acc]);
-        _ ->
-            throw(invalid_utf8)
-    end.
-
-tokenize_number(B, S) ->
-    case tokenize_number(B, sign, S, []) of
-        {{int, Int}, S1} ->
-            {{const, list_to_integer(Int)}, S1};
-        {{float, Float}, S1} ->
-            {{const, list_to_float(Float)}, S1}
-    end.
-
-tokenize_number(B, sign, S=#decoder{offset=O}, []) ->
-    case B of
-        <<_:O/binary, $-, _/binary>> ->
-            tokenize_number(B, int, ?INC_COL(S), [$-]);
-        _ ->
-            tokenize_number(B, int, S, [])
-    end;
-tokenize_number(B, int, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, $0, _/binary>> ->
-            tokenize_number(B, frac, ?INC_COL(S), [$0 | Acc]);
-        <<_:O/binary, C, _/binary>> when C >= $1 andalso C =< $9 ->
-            tokenize_number(B, int1, ?INC_COL(S), [C | Acc])
-    end;
-tokenize_number(B, int1, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
-            tokenize_number(B, int1, ?INC_COL(S), [C | Acc]);
-        _ ->
-            tokenize_number(B, frac, S, Acc)
-    end;
-tokenize_number(B, frac, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, $., C, _/binary>> when C >= $0, C =< $9 ->
-            tokenize_number(B, frac1, ?ADV_COL(S, 2), [C, $. | Acc]);
-        <<_:O/binary, E, _/binary>> when E =:= $e orelse E =:= $E ->
-            tokenize_number(B, esign, ?INC_COL(S), [$e, $0, $. | Acc]);
-        _ ->
-            {{int, lists:reverse(Acc)}, S}
-    end;
-tokenize_number(B, frac1, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
-            tokenize_number(B, frac1, ?INC_COL(S), [C | Acc]);
-        <<_:O/binary, E, _/binary>> when E =:= $e orelse E =:= $E ->
-            tokenize_number(B, esign, ?INC_COL(S), [$e | Acc]);
-        _ ->
-            {{float, lists:reverse(Acc)}, S}
-    end;
-tokenize_number(B, esign, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when C =:= $- orelse C=:= $+ ->
-            tokenize_number(B, eint, ?INC_COL(S), [C | Acc]);
-        _ ->
-            tokenize_number(B, eint, S, Acc)
-    end;
-tokenize_number(B, eint, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
-            tokenize_number(B, eint1, ?INC_COL(S), [C | Acc])
-    end;
-tokenize_number(B, eint1, S=#decoder{offset=O}, Acc) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when C >= $0 andalso C =< $9 ->
-            tokenize_number(B, eint1, ?INC_COL(S), [C | Acc]);
-        _ ->
-            {{float, lists:reverse(Acc)}, S}
-    end.
-
-tokenize(B, S=#decoder{offset=O}) ->
-    case B of
-        <<_:O/binary, C, _/binary>> when ?IS_WHITESPACE(C) ->
-            tokenize(B, ?INC_CHAR(S, C));
-        <<_:O/binary, "{", _/binary>> ->
-            {start_object, ?INC_COL(S)};
-        <<_:O/binary, "}", _/binary>> ->
-            {end_object, ?INC_COL(S)};
-        <<_:O/binary, "[", _/binary>> ->
-            {start_array, ?INC_COL(S)};
-        <<_:O/binary, "]", _/binary>> ->
-            {end_array, ?INC_COL(S)};
-        <<_:O/binary, ",", _/binary>> ->
-            {comma, ?INC_COL(S)};
-        <<_:O/binary, ":", _/binary>> ->
-            {colon, ?INC_COL(S)};
-        <<_:O/binary, "null", _/binary>> ->
-            {{const, null}, ?ADV_COL(S, 4)};
-        <<_:O/binary, "true", _/binary>> ->
-            {{const, true}, ?ADV_COL(S, 4)};
-        <<_:O/binary, "false", _/binary>> ->
-            {{const, false}, ?ADV_COL(S, 5)};
-        <<_:O/binary, "\"", _/binary>> ->
-            tokenize_string(B, ?INC_COL(S));
-        <<_:O/binary, C, _/binary>> when (C >= $0 andalso C =< $9)
-                                         orelse C =:= $- ->
-            tokenize_number(B, S);
-        <<_:O/binary>> ->
-            trim = S#decoder.state,
-            {eof, S}
-    end.
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-
-%% testing constructs borrowed from the Yaws JSON implementation.
-
-%% Create an object from a list of Key/Value pairs.
-
-obj_new() ->
-    {struct, []}.
-
-is_obj({struct, Props}) ->
-    F = fun ({K, _}) when is_binary(K) -> true end,
-    lists:all(F, Props).
-
-obj_from_list(Props) ->
-    Obj = {struct, Props},
-    ?assert(is_obj(Obj)),
-    Obj.
-
-%% Test for equivalence of Erlang terms.
-%% Due to arbitrary order of construction, equivalent objects might
-%% compare unequal as erlang terms, so we need to carefully recurse
-%% through aggregates (tuples and objects).
-
-equiv({struct, Props1}, {struct, Props2}) ->
-    equiv_object(Props1, Props2);
-equiv(L1, L2) when is_list(L1), is_list(L2) ->
-    equiv_list(L1, L2);
-equiv(N1, N2) when is_number(N1), is_number(N2) -> N1 == N2;
-equiv(B1, B2) when is_binary(B1), is_binary(B2) -> B1 == B2;
-equiv(A, A) when A =:= true orelse A =:= false orelse A =:= null -> true.
-
-%% Object representation and traversal order is unknown.
-%% Use the sledgehammer and sort property lists.
-
-equiv_object(Props1, Props2) ->
-    L1 = lists:keysort(1, Props1),
-    L2 = lists:keysort(1, Props2),
-    Pairs = lists:zip(L1, L2),
-    true = lists:all(fun({{K1, V1}, {K2, V2}}) ->
-                             equiv(K1, K2) and equiv(V1, V2)
-                     end, Pairs).
-
-%% Recursively compare tuple elements for equivalence.
-
-equiv_list([], []) ->
-    true;
-equiv_list([V1 | L1], [V2 | L2]) ->
-    equiv(V1, V2) andalso equiv_list(L1, L2).
-
-decode_test() ->
-    [1199344435545.0, 1] = decode(<<"[1199344435545.0,1]">>),
-    <<16#F0,16#9D,16#9C,16#95>> = decode([34,"\\ud835","\\udf15",34]).
-
-e2j_vec_test() ->
-    test_one(e2j_test_vec(utf8), 1).
-
-test_one([], _N) ->
-    %% io:format("~p tests passed~n", [N-1]),
-    ok;
-test_one([{E, J} | Rest], N) ->
-    %% io:format("[~p] ~p ~p~n", [N, E, J]),
-    true = equiv(E, decode(J)),
-    true = equiv(E, decode(encode(E))),
-    test_one(Rest, 1+N).
-
-e2j_test_vec(utf8) ->
-    [
-     {1, "1"},
-     {3.1416, "3.14160"}, %% text representation may truncate, trail zeroes
-     {-1, "-1"},
-     {-3.1416, "-3.14160"},
-     {12.0e10, "1.20000e+11"},
-     {1.234E+10, "1.23400e+10"},
-     {-1.234E-10, "-1.23400e-10"},
-     {10.0, "1.0e+01"},
-     {123.456, "1.23456E+2"},
-     {10.0, "1e1"},
-     {<<"foo">>, "\"foo\""},
-     {<<"foo", 5, "bar">>, "\"foo\\u0005bar\""},
-     {<<"">>, "\"\""},
-     {<<"\n\n\n">>, "\"\\n\\n\\n\""},
-     {<<"\" \b\f\r\n\t\"">>, "\"\\\" \\b\\f\\r\\n\\t\\\"\""},
-     {obj_new(), "{}"},
-     {obj_from_list([{<<"foo">>, <<"bar">>}]), "{\"foo\":\"bar\"}"},
-     {obj_from_list([{<<"foo">>, <<"bar">>}, {<<"baz">>, 123}]),
-      "{\"foo\":\"bar\",\"baz\":123}"},
-     {[], "[]"},
-     {[[]], "[[]]"},
-     {[1, <<"foo">>], "[1,\"foo\"]"},
-
-     %% json array in a json object
-     {obj_from_list([{<<"foo">>, [123]}]),
-      "{\"foo\":[123]}"},
-
-     %% json object in a json object
-     {obj_from_list([{<<"foo">>, obj_from_list([{<<"bar">>, true}])}]),
-      "{\"foo\":{\"bar\":true}}"},
-
-     %% fold evaluation order
-     {obj_from_list([{<<"foo">>, []},
-                     {<<"bar">>, obj_from_list([{<<"baz">>, true}])},
-                     {<<"alice">>, <<"bob">>}]),
-      "{\"foo\":[],\"bar\":{\"baz\":true},\"alice\":\"bob\"}"},
-
-     %% json object in a json array
-     {[-123, <<"foo">>, obj_from_list([{<<"bar">>, []}]), null],
-      "[-123,\"foo\",{\"bar\":[]},null]"}
-    ].
-
-%% test utf8 encoding
-encoder_utf8_test() ->
-    %% safe conversion case (default)
-    [34,"\\u0001","\\u0442","\\u0435","\\u0441","\\u0442",34] =
-        encode(<<1,"\321\202\320\265\321\201\321\202">>),
-
-    %% raw utf8 output (optional)
-    Enc = mochijson2:encoder([{utf8, true}]),
-    [34,"\\u0001",[209,130],[208,181],[209,129],[209,130],34] =
-        Enc(<<1,"\321\202\320\265\321\201\321\202">>).
-
-input_validation_test() ->
-    Good = [
-        {16#00A3, <<?Q, 16#C2, 16#A3, ?Q>>}, %% pound
-        {16#20AC, <<?Q, 16#E2, 16#82, 16#AC, ?Q>>}, %% euro
-        {16#10196, <<?Q, 16#F0, 16#90, 16#86, 16#96, ?Q>>} %% denarius
-    ],
-    lists:foreach(fun({CodePoint, UTF8}) ->
-        Expect = list_to_binary(xmerl_ucs:to_utf8(CodePoint)),
-        Expect = decode(UTF8)
-    end, Good),
-
-    Bad = [
-        %% 2nd, 3rd, or 4th byte of a multi-byte sequence w/o leading byte
-        <<?Q, 16#80, ?Q>>,
-        %% missing continuations, last byte in each should be 80-BF
-        <<?Q, 16#C2, 16#7F, ?Q>>,
-        <<?Q, 16#E0, 16#80,16#7F, ?Q>>,
-        <<?Q, 16#F0, 16#80, 16#80, 16#7F, ?Q>>,
-        %% we don't support code points > 10FFFF per RFC 3629
-        <<?Q, 16#F5, 16#80, 16#80, 16#80, ?Q>>,
-        %% escape characters trigger a different code path
-        <<?Q, $\\, $\n, 16#80, ?Q>>
-    ],
-    lists:foreach(
-      fun(X) ->
-              ok = try decode(X) catch invalid_utf8 -> ok end,
-              %% could be {ucs,{bad_utf8_character_code}} or
-              %%          {json_encode,{bad_char,_}}
-              {'EXIT', _} = (catch encode(X))
-      end, Bad).
-
-inline_json_test() ->
-    ?assertEqual(<<"\"iodata iodata\"">>,
-                 iolist_to_binary(
-                   encode({json, [<<"\"iodata">>, " iodata\""]}))),
-    ?assertEqual({struct, [{<<"key">>, <<"iodata iodata">>}]},
-                 decode(
-                   encode({struct,
-                           [{key, {json, [<<"\"iodata">>, " iodata\""]}}]}))),
-    ok.
-
-big_unicode_test() ->
-    UTF8Seq = list_to_binary(xmerl_ucs:to_utf8(16#0001d120)),
-    ?assertEqual(
-       <<"\"\\ud834\\udd20\"">>,
-       iolist_to_binary(encode(UTF8Seq))),
-    ?assertEqual(
-       UTF8Seq,
-       decode(iolist_to_binary(encode(UTF8Seq)))),
-    ok.
-
-custom_decoder_test() ->
-    ?assertEqual(
-       {struct, [{<<"key">>, <<"value">>}]},
-       (decoder([]))("{\"key\": \"value\"}")),
-    F = fun ({struct, [{<<"key">>, <<"value">>}]}) -> win end,
-    ?assertEqual(
-       win,
-       (decoder([{object_hook, F}]))("{\"key\": \"value\"}")),
-    ok.
-
-atom_test() ->
-    %% JSON native atoms
-    [begin
-         ?assertEqual(A, decode(atom_to_list(A))),
-         ?assertEqual(iolist_to_binary(atom_to_list(A)),
-                      iolist_to_binary(encode(A)))
-     end || A <- [true, false, null]],
-    %% Atom to string
-    ?assertEqual(
-       <<"\"foo\"">>,
-       iolist_to_binary(encode(foo))),
-    ?assertEqual(
-       <<"\"\\ud834\\udd20\"">>,
-       iolist_to_binary(encode(list_to_atom(xmerl_ucs:to_utf8(16#0001d120))))),
-    ok.
-
-key_encode_test() ->
-    %% Some forms are accepted as keys that would not be strings in other
-    %% cases
-    ?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode({struct, [{foo, 1}]}))),
-    ?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode({struct, [{<<"foo">>, 1}]}))),
-    ?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode({struct, [{"foo", 1}]}))),
-	?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode([{foo, 1}]))),
-    ?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode([{<<"foo">>, 1}]))),
-    ?assertEqual(
-       <<"{\"foo\":1}">>,
-       iolist_to_binary(encode([{"foo", 1}]))),
-    ?assertEqual(
-       <<"{\"\\ud834\\udd20\":1}">>,
-       iolist_to_binary(
-         encode({struct, [{[16#0001d120], 1}]}))),
-    ?assertEqual(
-       <<"{\"1\":1}">>,
-       iolist_to_binary(encode({struct, [{1, 1}]}))),
-    ok.
-
-unsafe_chars_test() ->
-    Chars = "\"\\\b\f\n\r\t",
-    [begin
-         ?assertEqual(false, json_string_is_safe([C])),
-         ?assertEqual(false, json_bin_is_safe(<<C>>)),
-         ?assertEqual(<<C>>, decode(encode(<<C>>)))
-     end || C <- Chars],
-    ?assertEqual(
-       false,
-       json_string_is_safe([16#0001d120])),
-    ?assertEqual(
-       false,
-       json_bin_is_safe(list_to_binary(xmerl_ucs:to_utf8(16#0001d120)))),
-    ?assertEqual(
-       [16#0001d120],
-       xmerl_ucs:from_utf8(
-         binary_to_list(
-           decode(encode(list_to_atom(xmerl_ucs:to_utf8(16#0001d120))))))),
-    ?assertEqual(
-       false,
-       json_string_is_safe([16#110000])),
-    ?assertEqual(
-       false,
-       json_bin_is_safe(list_to_binary(xmerl_ucs:to_utf8([16#110000])))),
-    %% solidus can be escaped but isn't unsafe by default
-    ?assertEqual(
-       <<"/">>,
-       decode(<<"\"\\/\"">>)),
-    ok.
-
-int_test() ->
-    ?assertEqual(0, decode("0")),
-    ?assertEqual(1, decode("1")),
-    ?assertEqual(11, decode("11")),
-    ok.
-
-large_int_test() ->
-    ?assertEqual(<<"-2147483649214748364921474836492147483649">>,
-        iolist_to_binary(encode(-2147483649214748364921474836492147483649))),
-    ?assertEqual(<<"2147483649214748364921474836492147483649">>,
-        iolist_to_binary(encode(2147483649214748364921474836492147483649))),
-    ok.
-
-float_test() ->
-    ?assertEqual(<<"-2147483649.0">>, iolist_to_binary(encode(-2147483649.0))),
-    ?assertEqual(<<"2147483648.0">>, iolist_to_binary(encode(2147483648.0))),
-    ok.
-
-handler_test() ->
-    ?assertEqual(
-       {'EXIT',{json_encode,{bad_term,{}}}},
-       catch encode({})),
-    F = fun ({}) -> [] end,
-    ?assertEqual(
-       <<"[]">>,
-       iolist_to_binary((encoder([{handler, F}]))({}))),
-    ok.
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochilists.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochilists.erl b/src/mochiweb/src/mochilists.erl
deleted file mode 100644
index 8981e7b..0000000
--- a/src/mochiweb/src/mochilists.erl
+++ /dev/null
@@ -1,104 +0,0 @@
-%% @copyright Copyright (c) 2010 Mochi Media, Inc.
-%% @author David Reid <dr...@mochimedia.com>
-
-%% @doc Utility functions for dealing with proplists.
-
--module(mochilists).
--author("David Reid <dr...@mochimedia.com>").
--export([get_value/2, get_value/3, is_defined/2, set_default/2, set_defaults/2]).
-
-%% @spec set_default({Key::term(), Value::term()}, Proplist::list()) -> list()
-%%
-%% @doc Return new Proplist with {Key, Value} set if not is_defined(Key, Proplist).
-set_default({Key, Value}, Proplist) ->
-    case is_defined(Key, Proplist) of
-        true ->
-            Proplist;
-        false ->
-            [{Key, Value} | Proplist]
-    end.
-
-%% @spec set_defaults([{Key::term(), Value::term()}], Proplist::list()) -> list()
-%%
-%% @doc Return new Proplist with {Key, Value} set if not is_defined(Key, Proplist).
-set_defaults(DefaultProps, Proplist) ->
-    lists:foldl(fun set_default/2, Proplist, DefaultProps).
-
-
-%% @spec is_defined(Key::term(), Proplist::list()) -> bool()
-%%
-%% @doc Returns true if Propist contains at least one entry associated
-%%      with Key, otherwise false is returned.
-is_defined(Key, Proplist) ->
-    lists:keyfind(Key, 1, Proplist) =/= false.
-
-
-%% @spec get_value(Key::term(), Proplist::list()) -> term() | undefined
-%%
-%% @doc Return the value of <code>Key</code> or undefined
-get_value(Key, Proplist) ->
-    get_value(Key, Proplist, undefined).
-
-%% @spec get_value(Key::term(), Proplist::list(), Default::term()) -> term()
-%%
-%% @doc Return the value of <code>Key</code> or <code>Default</code>
-get_value(_Key, [], Default) ->
-    Default;
-get_value(Key, Proplist, Default) ->
-    case lists:keyfind(Key, 1, Proplist) of
-        false ->
-            Default;
-        {Key, Value} ->
-            Value
-    end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-
-set_defaults_test() ->
-    ?assertEqual(
-       [{k, v}],
-       set_defaults([{k, v}], [])),
-    ?assertEqual(
-       [{k, v}],
-       set_defaults([{k, vee}], [{k, v}])),
-    ?assertEqual(
-       lists:sort([{kay, vee}, {k, v}]),
-       lists:sort(set_defaults([{k, vee}, {kay, vee}], [{k, v}]))),
-    ok.
-
-set_default_test() ->
-    ?assertEqual(
-       [{k, v}],
-       set_default({k, v}, [])),
-    ?assertEqual(
-       [{k, v}],
-       set_default({k, vee}, [{k, v}])),
-    ok.
-
-get_value_test() ->
-    ?assertEqual(
-       undefined,
-       get_value(foo, [])),
-    ?assertEqual(
-       undefined,
-       get_value(foo, [{bar, baz}])),
-    ?assertEqual(
-       bar,
-       get_value(foo, [{foo, bar}])),
-    ?assertEqual(
-       default,
-       get_value(foo, [], default)),
-    ?assertEqual(
-       default,
-       get_value(foo, [{bar, baz}], default)),
-    ?assertEqual(
-       bar,
-       get_value(foo, [{foo, bar}], default)),
-    ok.
-
--endif.
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/acf8eaff/src/mochiweb/src/mochilogfile2.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb/src/mochilogfile2.erl b/src/mochiweb/src/mochilogfile2.erl
deleted file mode 100644
index c34ee73..0000000
--- a/src/mochiweb/src/mochilogfile2.erl
+++ /dev/null
@@ -1,140 +0,0 @@
-%% @author Bob Ippolito <bo...@mochimedia.com>
-%% @copyright 2010 Mochi Media, Inc.
-
-%% @doc Write newline delimited log files, ensuring that if a truncated
-%%      entry is found on log open then it is fixed before writing. Uses
-%%      delayed writes and raw files for performance.
--module(mochilogfile2).
--author('bob@mochimedia.com').
-
--export([open/1, write/2, close/1, name/1]).
-
-%% @spec open(Name) -> Handle
-%% @doc Open the log file Name, creating or appending as necessary. All data
-%%      at the end of the file will be truncated until a newline is found, to
-%%      ensure that all records are complete.
-open(Name) ->
-    {ok, FD} = file:open(Name, [raw, read, write, delayed_write, binary]),
-    fix_log(FD),
-    {?MODULE, Name, FD}.
-
-%% @spec name(Handle) -> string()
-%% @doc Return the path of the log file.
-name({?MODULE, Name, _FD}) ->
-    Name.
-
-%% @spec write(Handle, IoData) -> ok
-%% @doc Write IoData to the log file referenced by Handle.
-write({?MODULE, _Name, FD}, IoData) ->
-    ok = file:write(FD, [IoData, $\n]),
-    ok.
-
-%% @spec close(Handle) -> ok
-%% @doc Close the log file referenced by Handle.
-close({?MODULE, _Name, FD}) ->
-    ok = file:sync(FD),
-    ok = file:close(FD),
-    ok.
-
-fix_log(FD) ->
-    {ok, Location} = file:position(FD, eof),
-    Seek = find_last_newline(FD, Location),
-    {ok, Seek} = file:position(FD, Seek),
-    ok = file:truncate(FD),
-    ok.
-
-%% Seek backwards to the last valid log entry
-find_last_newline(_FD, N) when N =< 1 ->
-    0;
-find_last_newline(FD, Location) ->
-    case file:pread(FD, Location - 1, 1) of
-	{ok, <<$\n>>} ->
-            Location;
-	{ok, _} ->
-	    find_last_newline(FD, Location - 1)
-    end.
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
-name_test() ->
-    D = mochitemp:mkdtemp(),
-    FileName = filename:join(D, "open_close_test.log"),
-    H = open(FileName),
-    ?assertEqual(
-       FileName,
-       name(H)),
-    close(H),
-    file:delete(FileName),
-    file:del_dir(D),
-    ok.
-
-open_close_test() ->
-    D = mochitemp:mkdtemp(),
-    FileName = filename:join(D, "open_close_test.log"),
-    OpenClose = fun () ->
-                        H = open(FileName),
-                        ?assertEqual(
-                           true,
-                           filelib:is_file(FileName)),
-                        ok = close(H),
-                        ?assertEqual(
-                           {ok, <<>>},
-                           file:read_file(FileName)),
-                        ok
-                end,
-    OpenClose(),
-    OpenClose(),
-    file:delete(FileName),
-    file:del_dir(D),
-    ok.
-
-write_test() ->
-    D = mochitemp:mkdtemp(),
-    FileName = filename:join(D, "write_test.log"),
-    F = fun () ->
-                H = open(FileName),
-                write(H, "test line"),
-                close(H),
-                ok
-        end,
-    F(),
-    ?assertEqual(
-       {ok, <<"test line\n">>},
-       file:read_file(FileName)),
-    F(),
-    ?assertEqual(
-       {ok, <<"test line\ntest line\n">>},
-       file:read_file(FileName)),
-    file:delete(FileName),
-    file:del_dir(D),
-    ok.
-
-fix_log_test() ->
-    D = mochitemp:mkdtemp(),
-    FileName = filename:join(D, "write_test.log"),
-    file:write_file(FileName, <<"first line good\nsecond line bad">>),
-    F = fun () ->
-                H = open(FileName),
-                write(H, "test line"),
-                close(H),
-                ok
-        end,
-    F(),
-    ?assertEqual(
-       {ok, <<"first line good\ntest line\n">>},
-       file:read_file(FileName)),
-    file:write_file(FileName, <<"first line bad">>),
-    F(),
-    ?assertEqual(
-       {ok, <<"test line\n">>},
-       file:read_file(FileName)),
-    F(),
-    ?assertEqual(
-       {ok, <<"test line\ntest line\n">>},
-       file:read_file(FileName)),
-    ok.
-
--endif.