@Test public void unescape(){ try { SeparatorConverter.unescape(""); fail(); } catch(IllegalArgumentException iae){ } assertEquals(" ", SeparatorConverter.unescape(" ")); assertEquals(",", SeparatorConverter.unescape(",")); assertEquals(";", SeparatorConverter.unescape(";")); assertEquals("\t", SeparatorConverter.unescape("\t")); assertEquals("\t", SeparatorConverter.unescape("\\t")); try { SeparatorConverter.unescape("\\"); fail(); } catch(IllegalArgumentException iae){ } assertEquals("\\", SeparatorConverter.unescape("\\\\")); try { SeparatorConverter.unescape("\\x"); fail(); } catch(IllegalArgumentException iae){ } assertEquals("\\x", SeparatorConverter.unescape("\\\\x")); }
static public String unescape(String string){ StringBuilder sb = new StringBuilder(); boolean escaped = false; for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\\'){ if(escaped){ sb.append('\\'); escaped = false; } else { escaped = true; } continue; } if(escaped){ sb.append(translate(c)); } else { sb.append(c); } escaped = false; } if(escaped){ throw new IllegalArgumentException(); } if(sb.length() == 0){ throw new IllegalArgumentException(); } return sb.toString(); }
SeparatorConverter extends BaseConverter<String> { static public String unescape(String string){ StringBuilder sb = new StringBuilder(); boolean escaped = false; for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\\'){ if(escaped){ sb.append('\\'); escaped = false; } else { escaped = true; } continue; } if(escaped){ sb.append(translate(c)); } else { sb.append(c); } escaped = false; } if(escaped){ throw new IllegalArgumentException(); } if(sb.length() == 0){ throw new IllegalArgumentException(); } return sb.toString(); } }
SeparatorConverter extends BaseConverter<String> { static public String unescape(String string){ StringBuilder sb = new StringBuilder(); boolean escaped = false; for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\\'){ if(escaped){ sb.append('\\'); escaped = false; } else { escaped = true; } continue; } if(escaped){ sb.append(translate(c)); } else { sb.append(c); } escaped = false; } if(escaped){ throw new IllegalArgumentException(); } if(sb.length() == 0){ throw new IllegalArgumentException(); } return sb.toString(); } SeparatorConverter(String optionName); }
SeparatorConverter extends BaseConverter<String> { static public String unescape(String string){ StringBuilder sb = new StringBuilder(); boolean escaped = false; for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\\'){ if(escaped){ sb.append('\\'); escaped = false; } else { escaped = true; } continue; } if(escaped){ sb.append(translate(c)); } else { sb.append(c); } escaped = false; } if(escaped){ throw new IllegalArgumentException(); } if(sb.length() == 0){ throw new IllegalArgumentException(); } return sb.toString(); } SeparatorConverter(String optionName); @Override String convert(String value); static String unescape(String string); }
SeparatorConverter extends BaseConverter<String> { static public String unescape(String string){ StringBuilder sb = new StringBuilder(); boolean escaped = false; for(int i = 0; i < string.length(); i++){ char c = string.charAt(i); if(c == '\\'){ if(escaped){ sb.append('\\'); escaped = false; } else { escaped = true; } continue; } if(escaped){ sb.append(translate(c)); } else { sb.append(c); } escaped = false; } if(escaped){ throw new IllegalArgumentException(); } if(sb.length() == 0){ throw new IllegalArgumentException(); } return sb.toString(); } SeparatorConverter(String optionName); @Override String convert(String value); static String unescape(String string);  }