anchor.diff:  %%-------------------------------------------------------------------------
   %% Helper functions for calculating the parsed binary.
   %%-------------------------------------------------------------------------
  -
  -%% Returns the parsed binary based on Input and the Unparsed part.
  -%% Handles the following special cases:
  -%%
  -%%    #{host => [],path => "/",query => []} = uri_string:parse("///?")
  -%%    #{fragment => [],host => [],path => "/"} = uri_string:parse("///#")
  -%%
  +-spec calculate_parsed_scheme(binary(), binary()) -> binary().
  +calculate_parsed_scheme(Input, <<>>) ->
  +    strip_last_char(Input, [$:]);
  +calculate_parsed_scheme(Input, Unparsed) ->
  +    get_parsed_binary(Input, Unparsed).
  +
  +
   -spec calculate_parsed_part(binary(), binary()) -> binary().
  -calculate_parsed_part(<<$?>>, _) -> <<>>;
  -calculate_parsed_part(<<$#>>, _) -> <<>>;
  -calculate_parsed_part(<<>>, _) -> <<>>;
   calculate_parsed_part(Input, <<>>) ->
  +    strip_last_char(Input, [$?,$#]);
  +calculate_parsed_part(Input, Unparsed) ->
  +    get_parsed_binary(Input, Unparsed).
  +
  +
  +-spec calculate_parsed_userinfo(binary(), binary()) -> binary().
  +calculate_parsed_userinfo(Input, <<>>) ->
  +    strip_last_char(Input, [$?,$#,$@]);
  +calculate_parsed_userinfo(Input, Unparsed) ->
  +    get_parsed_binary(Input, Unparsed).
  +
  +
  +-spec calculate_parsed_host_port(binary(), binary()) -> binary().
  +calculate_parsed_host_port(Input, <<>>) ->
  +    strip_last_char(Input, [$?,$#,$/]);
  +calculate_parsed_host_port(Input, Unparsed) ->
  +    get_parsed_binary(Input, Unparsed).
  +
  +
  +calculate_parsed_query_fragment(Input, <<>>) ->
  +    strip_last_char(Input, [$#]);
  +calculate_parsed_query_fragment(Input, Unparsed) ->
  +    get_parsed_binary(Input, Unparsed).
  +
  +
  +%% Strip last char if it is in list
  +strip_last_char(<<>>, _) -> <<>>;
  +strip_last_char(Input, [C0]) ->
       case binary:last(Input) of
  -        $? ->
  -            init_binary(Input);
  -        $# ->
  +        C0 ->
               init_binary(Input);
           _Else ->
               Input
       end;
  -calculate_parsed_part(Input, Unparsed) ->
  -    {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
  -    First.
  -
  -
  --spec calculate_parsed_userinfo(binary(), binary()) -> binary().
  -calculate_parsed_userinfo(<<$?>>, _) -> <<>>;
  -calculate_parsed_userinfo(<<$#>>, _) -> <<>>;
  -calculate_parsed_userinfo(<<>>, _) -> <<>>;
  -calculate_parsed_userinfo(Input, <<>>) ->
  +strip_last_char(Input, [C0,C1]) ->
       case binary:last(Input) of
  -        $? ->
  +        C0 ->
               init_binary(Input);
  -        $# ->
  -            init_binary(Input);
  -        $@ ->
  +        C1 ->
               init_binary(Input);
           _Else ->
               Input
       end;
  -calculate_parsed_userinfo(Input, Unparsed) ->
  -    {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
  -    First.
  -
  -
  --spec calculate_parsed_host(binary(), binary()) -> binary().
  -calculate_parsed_host(<<$?>>, _) -> <<>>;
  -calculate_parsed_host(<<$#>>, _) -> <<>>;
  -calculate_parsed_host(<<>>, _) -> <<>>;
  -calculate_parsed_host(Input, <<>>) ->
  +strip_last_char(Input, [C0,C1,C2]) ->
       case binary:last(Input) of
  -        $? ->
  +        C0 ->
               init_binary(Input);
  -        $# ->
  +        C1 ->
               init_binary(Input);
  -        $/ ->
  +        C2 ->
               init_binary(Input);
           _Else ->
               Input
  -    end;
  -calculate_parsed_host(Input, Unparsed) ->
  +    end.
  +
  +
  +%% Get parsed binary
  +get_parsed_binary(Input, Unparsed) ->
       {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
       First.
   
  -
  --spec calculate_parsed_port(binary(), binary()) -> binary().
  -calculate_parsed_port(<<$?>>, _) -> <<>>;
  -calculate_parsed_port(<<$#>>, _) -> <<>>;
  -calculate_parsed_port(<<>>, _) -> <<>>;
  -calculate_parsed_port(Input, <<>>) ->
  -    case binary:last(Input) of
  -        $? ->
  -            init_binary(Input);
  -        $# ->
  -            init_binary(Input);
  -        $/ ->
  -            init_binary(Input);
  -        _Else ->
  -            Input
  -    end;
  -calculate_parsed_port(Input, Unparsed) ->
  -    {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
  -    First.
  -
  -
  -calculate_parsed_query(<<$#>>, _) -> <<>>;
  -calculate_parsed_query(<<>>, _) -> <<>>;
  -calculate_parsed_query(Input, <<>>) ->
  -    case binary:last(Input) of
  -        $# ->
  -            init_binary(Input);
  -        _Else ->
  -            Input
  -    end;
  -calculate_parsed_query(Input, Unparsed) ->
  -    {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
  -    First.
  -
  -
  --spec calculate_parsed_fragment(binary(), binary()) -> binary().
  -calculate_parsed_fragment(<<$#>>, _) -> <<>>;
  -calculate_parsed_fragment(Input, Unparsed) ->
  -    {First, _} = split_binary(Input, byte_size(Input) - byte_size_exl_head(Unparsed)),
  -    First.
  -
  -
  -%% Returns the parsed binary based on Input and the Unparsed part.
  -%% Used when parsing authority.
  -%%
  -%% Handles the following special cases:
  -%%
  -%%    #{host => "foo",query => []} = uri_string:parse("//foo?")
  -%%    #{fragment => [],host => "foo"} = uri_string:parse("//foo#")
  -%%    #{host => "foo",path => "/"} = uri_string:parse("//foo/")
  -%%    #{host => "foo",query => [],scheme => "http"} = uri_string:parse("http://foo?")
  -%%    #{fragment => [],host => "foo",scheme => "http"} = uri_string:parse("http://foo#")
  -%%    #{host => "foo",path => "/",scheme => "http"} = uri_string:parse("http://foo/")
  -%%
  --spec calculate_parsed_part_sl(binary(), binary()) -> binary().
  -calculate_parsed_part_sl(<<$?>>, _) -> <<>>;
  -calculate_parsed_part_sl(<<$#>>, _) -> <<>>;
  -calculate_parsed_part_sl(<<>>, _) -> <<>>;
  -calculate_parsed_part_sl(Input, <<>>) ->
  -    case binary:last(Input) of
  -        $? ->
  -            init_binary(Input);
  -        $# ->
  -            init_binary(Input);
  -        $/ ->
  -            init_binary(Input);
  -        _Else ->
  -            Input
  -    end;
  -calculate_parsed_part_sl(Input, Unparsed) ->
  -    {First, _} =
  -        split_binary(Input, byte_size_exl_single_slash(Input) - byte_size_exl_head(Unparsed)),
  -    First.
   
   %% Return all bytes of the binary except the last one. The binary must be non-empty.
   init_binary(B) ->
  
positive.code: -spec parse_reg_name(binary(), uri_map()) -> {binary(), uri_map()}.
  parse_reg_name(?STRING_REST($:, Rest), URI) ->
      {T, URI1} = parse_port(Rest, URI),
      H = calculate_parsed_port(Rest, T),
      Port = binary_to_integer(H),
      {Rest, URI1#{port => Port}};
  parse_reg_name(?STRING_REST($/, Rest), URI) ->
  
negative.code:     Init.
  
  
  %% Returns the size of a binary exluding the first element.
  %% Used in calls to split_binary().
  -spec byte_size_exl_head(binary()) -> number().
  byte_size_exl_head(<<>>) -> 0;
  byte_size_exl_head(Binary) -> byte_size(Binary) + 1.
  
  
  %%-------------------------------------------------------------------------
  