@Test public void trimAll_A$String_doubleQuateInChar() throws Exception { TrimInsideOfStringFilter target = new TrimInsideOfStringFilter(); String src = "specialCharactersRepresentation['\"'] = \"&#034;\".toCharArray();specialCharactersRepresentation['\\''] = \"&#039;\".toCharArray();"; String actual = target.trimAll(src); String expected = "specialCharactersRepresentation[''] = \"\".toCharArray();specialCharactersRepresentation[''] = \"\".toCharArray();"; assertEquals(expected, actual); }
@Override public String trimAll(String src) { if (src == null) { return null; } int len = src.length(); boolean isInsideOfString = false; boolean isInsideOfChar = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char current = src.charAt(i); if (i > 0) { if (!isInsideOfChar && current == '"') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfString = !isInsideOfString; sb.append(current); continue; } } if (!isInsideOfString && current == '\'') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfChar = !isInsideOfChar; sb.append(current); continue; } } } if (isInsideOfChar || isInsideOfString) { continue; } sb.append(current); } return sb.toString(); }
TrimInsideOfStringFilter implements TrimFilter { @Override public String trimAll(String src) { if (src == null) { return null; } int len = src.length(); boolean isInsideOfString = false; boolean isInsideOfChar = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char current = src.charAt(i); if (i > 0) { if (!isInsideOfChar && current == '"') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfString = !isInsideOfString; sb.append(current); continue; } } if (!isInsideOfString && current == '\'') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfChar = !isInsideOfChar; sb.append(current); continue; } } } if (isInsideOfChar || isInsideOfString) { continue; } sb.append(current); } return sb.toString(); } }
TrimInsideOfStringFilter implements TrimFilter { @Override public String trimAll(String src) { if (src == null) { return null; } int len = src.length(); boolean isInsideOfString = false; boolean isInsideOfChar = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char current = src.charAt(i); if (i > 0) { if (!isInsideOfChar && current == '"') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfString = !isInsideOfString; sb.append(current); continue; } } if (!isInsideOfString && current == '\'') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfChar = !isInsideOfChar; sb.append(current); continue; } } } if (isInsideOfChar || isInsideOfString) { continue; } sb.append(current); } return sb.toString(); }  }
TrimInsideOfStringFilter implements TrimFilter { @Override public String trimAll(String src) { if (src == null) { return null; } int len = src.length(); boolean isInsideOfString = false; boolean isInsideOfChar = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char current = src.charAt(i); if (i > 0) { if (!isInsideOfChar && current == '"') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfString = !isInsideOfString; sb.append(current); continue; } } if (!isInsideOfString && current == '\'') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfChar = !isInsideOfChar; sb.append(current); continue; } } } if (isInsideOfChar || isInsideOfString) { continue; } sb.append(current); } return sb.toString(); }  @Override String trimAll(String src); }
TrimInsideOfStringFilter implements TrimFilter { @Override public String trimAll(String src) { if (src == null) { return null; } int len = src.length(); boolean isInsideOfString = false; boolean isInsideOfChar = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { char current = src.charAt(i); if (i > 0) { if (!isInsideOfChar && current == '"') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfString = !isInsideOfString; sb.append(current); continue; } } if (!isInsideOfString && current == '\'') { int count = countPreviousContinuedBackslash(src, i, 0); if (count % 2 == 0) { isInsideOfChar = !isInsideOfChar; sb.append(current); continue; } } } if (isInsideOfChar || isInsideOfString) { continue; } sb.append(current); } return sb.toString(); }  @Override String trimAll(String src);  }