Created
October 10, 2011 21:50
-
-
Save ricardotealdi/1276662 to your computer and use it in GitHub Desktop.
Hyphenator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.tealdi.testing; | |
import java.text.Normalizer; | |
public class Hyphenator { | |
public String hyphenizeIt(String text) { | |
return trimmingHyphens( | |
removeNonCharactersButHyphen( | |
convertSpacesIntoHyphens( | |
removeAccents( | |
text.toLowerCase())))); | |
} | |
private static String trimmingHyphens(String text) { | |
return text.replaceAll("^\\W|\\W$", ""); | |
} | |
private static String removeAccents(String text) { | |
return Normalizer | |
.normalize(text, Normalizer.Form.NFD) | |
.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); | |
} | |
private static String removeNonCharactersButHyphen(String text) { | |
return text.replaceAll("[^\\w|-]", ""); | |
} | |
private static String convertSpacesIntoHyphens(String text) { | |
return text | |
.trim() | |
.replaceAll("[\\s]+", "-"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment