Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,39 @@

public class Slugifier
{
public static String run ( String text )
private Slugifier() {
}

public static String slugify ( String text ) throws UnsupportedEncodingException
{
if ( text == null || text.length () == 0 )
if ( text == null || text.isEmpty() )
{
return "";
}

String toReturn = "";
try
{
String normalizedText = normalize ( text );
normalizedText = normalizedText.replaceAll ( "[^\\w\\s\\-]", "" );
normalizedText = normalizedText.replaceAll ( " ", "-" );
normalizedText = normalizedText.toLowerCase ();
toReturn = URLEncoder.encode ( normalizedText, "UTF-8" );
}
catch ( UnsupportedEncodingException e )
{
// TODO: Log the exception
e.printStackTrace ();
}

return toReturn;
String normalizedText = normalize ( text )
.replaceAll ( "[^\\w\\s\\-]", "" )
.replaceAll ( " ", "-" )
.toLowerCase ();
return URLEncoder.encode ( normalizedText, "UTF-8" );
}

public static String convertCharactersFromTurkishToEnglish ( String text )
private static String convertCharactersFromTurkishToEnglish ( String text )
{
text = text.replaceAll ( "ü", "u" );
text = text.replaceAll ( "ı", "i" );
text = text.replaceAll ( "ö", "o" );
text = text.replaceAll ( "ü", "u" );
text = text.replaceAll ( "ş", "s" );
text = text.replaceAll ( "ğ", "g" );
text = text.replaceAll ( "ç", "c" );
text = text.replaceAll ( "Ü", "U" );
text = text.replaceAll ( "İ", "I" );
text = text.replaceAll ( "Ö", "O" );
text = text.replaceAll ( "Ü", "U" );
text = text.replaceAll ( "Ş", "S" );
text = text.replaceAll ( "Ğ", "G" );
text = text.replaceAll ( "Ç", "C" );
return text;
return text.replaceAll ( "ü", "u" )
.replaceAll ( "ı", "i" )
.replaceAll ( "ö", "o" )
.replaceAll ( "ü", "u" )
.replaceAll ( "ş", "s" )
.replaceAll ( "ğ", "g" )
.replaceAll ( "ç", "c" )
.replaceAll ( "Ü", "U" )
.replaceAll ( "İ", "I" )
.replaceAll ( "Ö", "O" )
.replaceAll ( "Ü", "U" )
.replaceAll ( "Ş", "S" )
.replaceAll ( "Ğ", "G" )
.replaceAll ( "Ç", "C" );
}

private static String normalize ( String input )
Expand Down