anchor.diff:  %%      invalid bytes.
   
   -module(mochiutf8).
  --export([valid_utf8_bytes/1, codepoint_to_bytes/1]).
  +-export([valid_utf8_bytes/1, codepoint_to_bytes/1, bytes_to_codepoints/1]).
  +-export([bytes_foldl/3, codepoint_foldl/3, read_codepoint/1, len/1]).
   
   %% External API
   
  -%% @spec codepoint_to_binary(integer()) -> binary()
  +-type unichar_low() :: 0..16#d7ff.
  +-type unichar_high() :: 16#e000..16#10ffff.
  +-type unichar() :: unichar_low() | unichar_high().
  +
  +-spec codepoint_to_bytes(unichar()) -> binary().
   %% @doc Convert a unicode codepoint to UTF-8 bytes.
   codepoint_to_bytes(C) when (C >= 16#00 andalso C =< 16#7f) ->
       %% U+0000 - U+007F - 7 bits
  
positive.code:     binary_skip_bytes(B, L, 0, []).
  
  %% @private
  binary_skip_bytes(B, [], _N, Acc) ->
      iolist_to_binary(lists:reverse([B | Acc]));
  binary_skip_bytes(<<_, RestB/binary>>, [N | RestL], N, Acc) ->
  
negative.code:        codepoint_to_bytes(16#10ffff)),
      ok.
  
  bytes_foldl_test() ->
      ?assertEqual(
         <<"abc">>,
         bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>, <<"abc">>)),
      ?assertEqual(
         <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>,
         bytes_foldl(fun (B, Acc) -> <<Acc/binary, B/binary>> end, <<>>,
                     <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
      ok.
  
  bytes_to_codepoints_test() ->
      ?assertEqual(
         "abc" ++ [16#2603, 16#4e2d, 16#85, 16#10ffff],
         bytes_to_codepoints(<<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
      ok.
  
  codepoint_foldl_test() ->
      ?assertEqual(
         "cba",
         codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [], <<"abc">>)),
      ?assertEqual(
         [16#10ffff, 16#85, 16#4e2d, 16#2603 | "cba"],
         codepoint_foldl(fun (C, Acc) -> [C | Acc] end, [],
                         <<"abc", 226, 152, 131, 228, 184, 173, 194, 133, 244,143,191,191>>)),
      ok.
  
  len_test() ->
      ?assertEqual(
         29,
         len(<<"unicode snowman for you: ", 226, 152, 131, 228, 184, 173, 194, 133, 244, 143, 191, 191>>)),
      ok.
  
  codepoints_to_bytes_test() ->
      ?assertEqual(
         iolist_to_binary(lists:map(fun codepoint_to_bytes/1, lists:seq(1, 1000))),
         codepoints_to_bytes(lists:seq(1, 1000))),
      ok.
  
  valid_utf8_bytes_test() ->
      ?assertEqual(
         <<"invalid U+11ffff: ">>,
  