@Test public void filter() { assertThat(output, equalTo(Util.filter(input))); }
public static String filter(final String rsrcname) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); for(int i=0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; if (ALLOWED_CHARS.indexOf(c) < 0) { if (lastAdded == REPLACEMENT_CHAR) { continue; } toAdd = REPLACEMENT_CHAR; } else if(i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length()==0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); }
Util { public static String filter(final String rsrcname) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); for(int i=0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; if (ALLOWED_CHARS.indexOf(c) < 0) { if (lastAdded == REPLACEMENT_CHAR) { continue; } toAdd = REPLACEMENT_CHAR; } else if(i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length()==0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); } }
Util { public static String filter(final String rsrcname) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); for(int i=0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; if (ALLOWED_CHARS.indexOf(c) < 0) { if (lastAdded == REPLACEMENT_CHAR) { continue; } toAdd = REPLACEMENT_CHAR; } else if(i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length()==0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); }  }
Util { public static String filter(final String rsrcname) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); for(int i=0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; if (ALLOWED_CHARS.indexOf(c) < 0) { if (lastAdded == REPLACEMENT_CHAR) { continue; } toAdd = REPLACEMENT_CHAR; } else if(i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length()==0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); }  static String filter(final String rsrcname); }
Util { public static String filter(final String rsrcname) { final StringBuilder sb = new StringBuilder(); char lastAdded = 0; final String name = rsrcname.toLowerCase(); for(int i=0; i < name.length(); i++) { final char c = name.charAt(i); char toAdd = c; if (ALLOWED_CHARS.indexOf(c) < 0) { if (lastAdded == REPLACEMENT_CHAR) { continue; } toAdd = REPLACEMENT_CHAR; } else if(i == 0 && Character.isDigit(c)) { sb.append(REPLACEMENT_CHAR); } sb.append(toAdd); lastAdded = toAdd; } if (sb.length()==0) { sb.append(REPLACEMENT_CHAR); } return sb.toString(); }  static String filter(final String rsrcname);  }