@@ -5,6 +5,8 @@ public class EscapeProcessor {
55 private static final char TAB_CHAR = '\t' ;
66 private static final char BREAK_LINE_CHAR = '\n' ;
77 private static final char SPACE_CHAR = ' ' ;
8+ private static final char DOUBLE_QUOTE_CHAR = '\"' ;
9+ private static final char ESCAPE_CHAR = '\\' ;
810
911 private final String inputString ;
1012 private boolean inQuotes = false ;
@@ -20,7 +22,7 @@ public String process() {
2022 inQuotes = false ;
2123 for (int i = 0 ; i < inputString .length (); i ++) {
2224 char currentChar = inputString .charAt (i );
23- if (currentChar != '\"' ) {
25+ if (currentChar != DOUBLE_QUOTE_CHAR ) {
2426 handleNonQuoteCharacter (currentChar );
2527 }
2628 else {
@@ -45,15 +47,15 @@ private void handleQuoteCharacter(char currentChar, int i) {
4547 handleQuoteNextToQuoteCase (currentChar , i );
4648 return ;
4749 }
48- escapedJson .append ('\\' );
50+ escapedJson .append (ESCAPE_CHAR );
4951 escapedJson .append (currentChar );
5052 }
5153
5254 private void handleQuoteNextToQuoteCase (char currentChar , int i ) {
53- int nextQuotePosition = getNextValidCharPosition (i + 1 );
55+ int nextQuotePosition = getNextNoneSpaceCharPosition (i + 1 );
5456 // If next valid quote is a good close quote, then the current quote MUST be an escaped quote
5557 if (isValidCloseQuote (nextQuotePosition )) {
56- escapedJson .append ('\\' );
58+ escapedJson .append (ESCAPE_CHAR );
5759 escapedJson .append (currentChar );
5860 }
5961 else {
@@ -67,10 +69,10 @@ private void handleQuoteNextToQuoteCase(char currentChar, int i) {
6769 }
6870
6971 private boolean hasNextQuoteRightAfterCurrentQuoteWithoutComma (int position ) {
70- return findNextValidChar (position + 1 ) == '\"' ;
72+ return findNextValidChar (position + 1 ) == DOUBLE_QUOTE_CHAR ;
7173 }
7274
73- private int getNextValidCharPosition (int position ) {
75+ private int getNextNoneSpaceCharPosition (int position ) {
7476 for (int i = position ; i < inputString .length (); i ++) {
7577 char currentChar = inputString .charAt (i );
7678 if (currentChar != SPACE_CHAR && currentChar != BREAK_LINE_CHAR && currentChar != TAB_CHAR ) {
0 commit comments