pl.chilldev.commons.text.slugifier.SimpleSlugifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-text Show documentation
Show all versions of commons-text Show documentation
Text processing utilities.
// Generated by delombok at Wed Jun 06 18:27:19 UTC 2018
/**
* This file is part of the ChillDev-Commons.
*
* @license http://mit-license.org/ The MIT license
* @copyright 2015 - 2016 © by Rafał Wrzeszcz - Wrzasq.pl.
*/
package pl.chilldev.commons.text.slugifier;
import java.text.Normalizer;
import java.util.Locale;
/**
* Simple implementation of slugifier.
*/
public class SimpleSlugifier implements Slugifier {
/**
* Default separator.
*/
public static final String DEFAULT_DELIMITER = "-";
/**
* Separator for URL parts.
*/
private String delimiter = SimpleSlugifier.DEFAULT_DELIMITER;
/**
* {@inheritDoc}
*/
@Override
public String slugify(String text) {
return Normalizer.normalize(text, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").replaceAll("\\W+", this.delimiter).replaceAll(this.delimiter + "+", this.delimiter).replaceAll("^" + this.delimiter, "").replaceAll(this.delimiter + "$", "").toLowerCase(Locale.ROOT);
}
/**
* {@inheritDoc}
*/
@Override
public String slugify(String... texts) {
return this.slugify(String.join(this.delimiter, texts));
}
/**
* Separator for URL parts.
*/
@SuppressWarnings("all")
public void setDelimiter(final String delimiter) {
this.delimiter = delimiter;
}
}