<commit_before>-module(url_tools).
-export([urljoin/2, subslashes/1, ensure_ends_with_slash/1]).

-define(REPLACE_LAST_PART(X, Y), lists:reverse(subslashes(lists:reverse(X)), Y)).
-define(CLEAN_LAST_PART(X), ?REPLACE_LAST_PART(X, [])).

urljoin(Base, [$/, $/ | _] = Path) ->
	re:replace(Base, "^([^:]+:)//.*$", "\\1" ++ Path, [{return, list}]);
urljoin(Base, [$/ | _] = Path) ->
	re:replace(Base, "^([^:]+://[^/]+)/.*$", "\\1" ++ Path, [{return, list}]);
urljoin(Base, [$., $/ | Rest]) ->
	urljoin(?CLEAN_LAST_PART(Base), Rest);
urljoin(Base, [$., $., $/ | Rest] = Path) ->
	case has_at_least_three_slashes(Base) of
		true -> urljoin(urljoin(Base, ".."), Rest);
		false -> ?REPLACE_LAST_PART(Base, Path)
	end;
urljoin(Base, [Sym | Rest]) when Sym =:= $#; Sym =:= $?; Sym =:= $; ->
	case strip_symbol(lists:reverse(Base), Sym) of
		not_found -> Base ++ Rest;
		Stripped -> lists:reverse(Stripped, Rest)
	end;
urljoin(Base, "") -> Base;
urljoin(Base, ".") -> ?CLEAN_LAST_PART(Base);
urljoin(Base, "..") -><commit_msg>urljoin: simplified ./ case like ../<commit_after>-module(url_tools).
-export([urljoin/2, subslashes/1, ensure_ends_with_slash/1]).

-define(REPLACE_LAST_PART(X, Y), lists:reverse(subslashes(lists:reverse(X)), Y)).
-define(CLEAN_LAST_PART(X), ?REPLACE_LAST_PART(X, [])).

urljoin(Base, [$/, $/ | _] = Path) ->
	re:replace(Base, "^([^:]+:)//.*$", "\\1" ++ Path, [{return, list}]);
urljoin(Base, [$/ | _] = Path) ->
	re:replace(Base, "^([^:]+://[^/]+)/.*$", "\\1" ++ Path, [{return, list}]);
urljoin(Base, [$., $/ | Rest]) ->
	urljoin(urljoin(Base, "."), Rest);
urljoin(Base, [$., $., $/ | Rest] = Path) ->
	case has_at_least_three_slashes(Base) of
		true -> urljoin(urljoin(Base, ".."), Rest);
		false -> ?REPLACE_LAST_PART(Base, Path)
	end;
urljoin(Base, [Sym | Rest]) when Sym =:= $#; Sym =:= $?; Sym =:= $; ->
	case strip_symbol(lists:reverse(Base), Sym) of
		not_found -> Base ++ Rest;
		Stripped -> lists:reverse(Stripped, Rest)
	end;
urljoin(Base, "") -> Base;
urljoin(Base, ".") -> ?CLEAN_LAST_PART(Base);
urljoin(Base, "..") ->
{'fraction_non_alphanumeric': 0.27574426549536357, 'fraction_numerical': 0.004880429477794046, 'mean_word_length': 4.678670360110804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1622381', 'n_tokens_mistral': 874, 'n_tokens_neox': 831, 'n_words': 132}