@Test public void removeComments_should_ignore_comments_in_strings_with_double_quotes() { String expected = "var s = \" String source = expected + " String withoutComments = cut.removeComments(source); assertThat(withoutComments).isEqualTo(expected); }
public String removeComments(String sourceCode) { state = State.IN_CODE; lastCodeStart = 0; codeSections = new ArrayList<>(); for (int index = 0; index < sourceCode.length(); index++) { char character = sourceCode.charAt(index); handleCharacter(character, index); } if (lastCodeStart != -1) { codeSections.add(new Section(lastCodeStart, sourceCode.length())); } StringBuilder builder = new StringBuilder(); for (Section section : codeSections) { builder.append(sourceCode.subSequence(section.getBegin(), section.getEnd())); } return builder.toString(); }
JavaScriptCommentRemover { public String removeComments(String sourceCode) { state = State.IN_CODE; lastCodeStart = 0; codeSections = new ArrayList<>(); for (int index = 0; index < sourceCode.length(); index++) { char character = sourceCode.charAt(index); handleCharacter(character, index); } if (lastCodeStart != -1) { codeSections.add(new Section(lastCodeStart, sourceCode.length())); } StringBuilder builder = new StringBuilder(); for (Section section : codeSections) { builder.append(sourceCode.subSequence(section.getBegin(), section.getEnd())); } return builder.toString(); } }
JavaScriptCommentRemover { public String removeComments(String sourceCode) { state = State.IN_CODE; lastCodeStart = 0; codeSections = new ArrayList<>(); for (int index = 0; index < sourceCode.length(); index++) { char character = sourceCode.charAt(index); handleCharacter(character, index); } if (lastCodeStart != -1) { codeSections.add(new Section(lastCodeStart, sourceCode.length())); } StringBuilder builder = new StringBuilder(); for (Section section : codeSections) { builder.append(sourceCode.subSequence(section.getBegin(), section.getEnd())); } return builder.toString(); }  }
JavaScriptCommentRemover { public String removeComments(String sourceCode) { state = State.IN_CODE; lastCodeStart = 0; codeSections = new ArrayList<>(); for (int index = 0; index < sourceCode.length(); index++) { char character = sourceCode.charAt(index); handleCharacter(character, index); } if (lastCodeStart != -1) { codeSections.add(new Section(lastCodeStart, sourceCode.length())); } StringBuilder builder = new StringBuilder(); for (Section section : codeSections) { builder.append(sourceCode.subSequence(section.getBegin(), section.getEnd())); } return builder.toString(); }  String removeComments(String sourceCode); }
JavaScriptCommentRemover { public String removeComments(String sourceCode) { state = State.IN_CODE; lastCodeStart = 0; codeSections = new ArrayList<>(); for (int index = 0; index < sourceCode.length(); index++) { char character = sourceCode.charAt(index); handleCharacter(character, index); } if (lastCodeStart != -1) { codeSections.add(new Section(lastCodeStart, sourceCode.length())); } StringBuilder builder = new StringBuilder(); for (Section section : codeSections) { builder.append(sourceCode.subSequence(section.getBegin(), section.getEnd())); } return builder.toString(); }  String removeComments(String sourceCode);  }