All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.httpmock.util.UrlNormalizer Maven / Gradle / Ivy

There is a newer version: 1.1.9
Show newest version
package com.github.httpmock.util;

public abstract class UrlNormalizer {

	public static String normalizeUrl(String url) {
		url = removeTailingSlashes(url);
		url = addBeginngSlash(url);
		url = removeDuplicateSlashes(url);
		return url;
	}

	private static String addBeginngSlash(String url) {
		if (url.length() == 0 || url.charAt(0) != '/')
			return '/' + url;
		return url;
	}

	private static String removeTailingSlashes(String url) {
		return url.replaceAll("[/]+$", "");
	}

	private static String removeDuplicateSlashes(String url) {
		return url.replaceAll("[/][/]+", "/");
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy