@Test public void testSanitizeWithDashes() { expect: assertEquals("harry-potter", new FriendlyUrl().sanitizeWithDashes("Harry Potter")); assertEquals("harry", new FriendlyUrl().sanitizeWithDashes("Harry ")); }
public static String sanitizeWithDashes(String text) { if ( text == null ) { return ""; } text = text.replaceAll("%([a-fA-F0-9][a-fA-F0-9])","---$1---"); text = text.replaceAll("%",""); text = text.replaceAll("---([a-fA-F0-9][a-fA-F0-9])---","%$1"); text = removeAccents(text); text = text.toLowerCase(); text = text.replaceAll("&.+?;",""); text = text.replaceAll("\\.",""); text = text.replaceAll("[^%a-zA-Z0-9 _-]", ""); text = text.trim(); text = text.replaceAll("\\s+", "-"); text = text.replaceAll("-+", "-"); if ( !Character.isLetterOrDigit(text.substring(text.length() - 1).charAt(0)) ) { text = text.substring(0, text.length() - 1); } return text; }
FriendlyUrl { public static String sanitizeWithDashes(String text) { if ( text == null ) { return ""; } text = text.replaceAll("%([a-fA-F0-9][a-fA-F0-9])","---$1---"); text = text.replaceAll("%",""); text = text.replaceAll("---([a-fA-F0-9][a-fA-F0-9])---","%$1"); text = removeAccents(text); text = text.toLowerCase(); text = text.replaceAll("&.+?;",""); text = text.replaceAll("\\.",""); text = text.replaceAll("[^%a-zA-Z0-9 _-]", ""); text = text.trim(); text = text.replaceAll("\\s+", "-"); text = text.replaceAll("-+", "-"); if ( !Character.isLetterOrDigit(text.substring(text.length() - 1).charAt(0)) ) { text = text.substring(0, text.length() - 1); } return text; } }
FriendlyUrl { public static String sanitizeWithDashes(String text) { if ( text == null ) { return ""; } text = text.replaceAll("%([a-fA-F0-9][a-fA-F0-9])","---$1---"); text = text.replaceAll("%",""); text = text.replaceAll("---([a-fA-F0-9][a-fA-F0-9])---","%$1"); text = removeAccents(text); text = text.toLowerCase(); text = text.replaceAll("&.+?;",""); text = text.replaceAll("\\.",""); text = text.replaceAll("[^%a-zA-Z0-9 _-]", ""); text = text.trim(); text = text.replaceAll("\\s+", "-"); text = text.replaceAll("-+", "-"); if ( !Character.isLetterOrDigit(text.substring(text.length() - 1).charAt(0)) ) { text = text.substring(0, text.length() - 1); } return text; }  }
FriendlyUrl { public static String sanitizeWithDashes(String text) { if ( text == null ) { return ""; } text = text.replaceAll("%([a-fA-F0-9][a-fA-F0-9])","---$1---"); text = text.replaceAll("%",""); text = text.replaceAll("---([a-fA-F0-9][a-fA-F0-9])---","%$1"); text = removeAccents(text); text = text.toLowerCase(); text = text.replaceAll("&.+?;",""); text = text.replaceAll("\\.",""); text = text.replaceAll("[^%a-zA-Z0-9 _-]", ""); text = text.trim(); text = text.replaceAll("\\s+", "-"); text = text.replaceAll("-+", "-"); if ( !Character.isLetterOrDigit(text.substring(text.length() - 1).charAt(0)) ) { text = text.substring(0, text.length() - 1); } return text; }  static String sanitizeWithDashes(String text); }
FriendlyUrl { public static String sanitizeWithDashes(String text) { if ( text == null ) { return ""; } text = text.replaceAll("%([a-fA-F0-9][a-fA-F0-9])","---$1---"); text = text.replaceAll("%",""); text = text.replaceAll("---([a-fA-F0-9][a-fA-F0-9])---","%$1"); text = removeAccents(text); text = text.toLowerCase(); text = text.replaceAll("&.+?;",""); text = text.replaceAll("\\.",""); text = text.replaceAll("[^%a-zA-Z0-9 _-]", ""); text = text.trim(); text = text.replaceAll("\\s+", "-"); text = text.replaceAll("-+", "-"); if ( !Character.isLetterOrDigit(text.substring(text.length() - 1).charAt(0)) ) { text = text.substring(0, text.length() - 1); } return text; }  static String sanitizeWithDashes(String text);  }