Java String Slugify slugify(String input)

Here you can find the source of slugify(String input)

Description

slugify

License

Mozilla Public License

Declaration

public static String slugify(String input) 

Method Source Code


//package com.java2s;
//License from project: Mozilla Public License 

import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.util.Locale;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
    private static final Pattern WHITESPACE = Pattern.compile("[\\s]");

    public static String slugify(String input) {
        if (input == null)
            return "";

        String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
        String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
        String slug = NONLATIN.matcher(normalized).replaceAll("");
        return slug.toLowerCase(Locale.ENGLISH).replaceAll("--+", "-");
    }//from  w  w w. j  a  v a 2  s  .com
}

Related

  1. slugify(final String s)
  2. slugify(final String s)
  3. slugify(String input)
  4. slugify(String s)
  5. toSlug(final String input)
  6. toSlug(String input)