Here you can find the source of toSlug(final String input)
Parameter | Description |
---|---|
input | The string to be converted to a Slug |
public static String toSlug(final String input)
//package com.java2s; //License from project: Open Source License import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.Locale; import java.util.regex.Pattern; public class Main { /**//from w w w. ja va 2 s. co m * Convert the String input to a slug. * * @param input The string to be converted to a Slug * @return Slug-String representation of the given input string */ public static String toSlug(final String input) { if (input == null) { throw new IllegalArgumentException("Input cannot be null"); } final Pattern NONLATIN = Pattern.compile("[^\\w-]"); final Pattern WHITESPACE = Pattern.compile("[\\s]"); String nowhitespace = WHITESPACE.matcher(input).replaceAll("-"); String normalized = Normalizer.normalize(nowhitespace, Form.NFD); String slug = NONLATIN.matcher(normalized).replaceAll(""); return slug.toLowerCase(Locale.ENGLISH); } }