anchor.diff:      end.
   
   %%--------------------------------------------------------------------
  -%% Function: remove_v6_brackets(H)
  -%%           H = string()
  -%% Descrip.: ???
  -%% Returns : ip6_address() | string()
  -%%--------------------------------------------------------------------
  -remove_v6_brackets([$[ | R] = H) ->
  +%% Function: remove_v6_brackets(In)
  +%%           In = string()
  +%% Descrip.: If In is "[IPv6Address]" then return "IPv6Address".
  +%%           Otherwise, return whatever In was.
  +%% Returns : Addr = string(), IPv6 address |
  +%%           In
  +%%--------------------------------------------------------------------
  +remove_v6_brackets([$[ | Rest] = In) ->
       %% Might be IPv6 formatted address, check if it ends with "]"
  -    case string:substr(R, length(R), 1) of
  +    case string:substr(Rest, length(Rest), 1) of
   	"]" ->
  -	    A = string:substr(R, 1, length(R) - 1),
  +	    A = string:substr(Rest, 1, length(Rest) - 1),
   	    case inet_parse:ipv6_address(A) of
   		{ok, _} ->
   		    A;
   		_ ->
   		    %% what was between [ and ] was not a valid v6 address
  -		    H
  +		    In
   	    end;
   	_ ->
   	    %% No ending "]"
  -	    H
  +	    In
       end;
  -remove_v6_brackets(H) ->
  -    H.
  -
  -%%====================================================================
  -%% Behaviour functions
  -%%====================================================================
  +remove_v6_brackets(In) ->
  +    In.
  +
   
   %%====================================================================
   %% Internal functions
   %%====================================================================
   
   %%--------------------------------------------------------------------
  -%% Function:
  -%% Descrip.:
  -%% Returns :
  -%%--------------------------------------------------------------------
  +%% Function: apply_rewrite(Rewrite, List)
  +%% Descrip.: Do regexp group substitution. Part of regexp_rewrite.
  +%%           Easiest to explain with examples :
  +%%
  +%%           Rewrite = "\\1@foo", List = ["first"] -> "first@foo"
  +%%           Rewrite = "abc\\1def\\2", List = ["123", "456"] ->
  +%%                        "abc123def456"
  +%% Returns : Res = string() |
  +%%           []
  +%% Note    : Function is not tail recursive.
  +%%--------------------------------------------------------------------
  +apply_rewrite([], _List) ->
  +    [];
  +apply_rewrite([$\\, $\\ | Rest], List) ->
  +    %% Double backslash - not a group.
  +    [$\\ | apply_rewrite(Rest, List)];
  +apply_rewrite([$\\, C | Rest], List) ->
  +    case digit(C) of
  +	error ->
  +	    %% Backslash not followed by digit, not a group.
  +	    [C | apply_rewrite(Rest, List)];
  +	0 ->
  +	    %% Backslash followed by the digit zero, not a group.
  +	    [C | apply_rewrite(Rest, List)];
  +	Number ->
  +	    %% Backslash followed by a digit between 1 and 9.
  +	    %% Substitute with that element from List.
  +	    %% XXX we crash with a slightly cryptic error if List does
  +	    %% not have enough elements ({function_clause, ...})!
  +	    lists:nth(Number, List) ++ apply_rewrite(Rest, List)
  +    end;
  +apply_rewrite([C | Rest], List) ->
  +    %% Not a backslash. Check next character.
  +    [C | apply_rewrite(Rest, List)].
  +
  +%% return integer value (0-9) of the chars $0-$9
  +%% return error if Digit is a non-numerical char (or other type)
  +digit(Digit) when is_integer(Digit), Digit >= $0, Digit =< $9 ->
  +    Digit - $0;
  +digit(_Digit) ->
  +    error.
  +
  +
  +%%====================================================================
  +%% Test functions
  +%%====================================================================
  +
  
positive.code:     false.
  
  %%--------------------------------------------------------------------
  %% Function:
  %% Descrip.:
  %% Returns :
  %%--------------------------------------------------------------------
  regexp_rewrite(_Input, []) ->
      nomatch;
  
negative.code:     case casecompare(String1, String2) of
  	true ->
  	    true;
  	false ->
  	    casegrep(String1, Rest)
      end.
  
  