@@ -32,19 +32,19 @@ public String process() {
32
32
return escapedJson .toString ();
33
33
}
34
34
35
- private void handleQuoteCharacter (char currentChar , int i ) {
35
+ private void handleQuoteCharacter (char currentChar , int position ) {
36
36
if (!inQuotes ) {
37
37
inQuotes = true ;
38
38
escapedJson .append (currentChar );
39
39
return ;
40
40
}
41
- if (isValidCloseQuote ( i )) {
41
+ if (isValidCloseQuoteAtPosition ( position )) {
42
42
inQuotes = false ;
43
43
escapedJson .append (currentChar );
44
44
return ;
45
45
}
46
- if (hasNextQuoteRightAfterCurrentQuoteWithoutComma (i + 1 )) {
47
- handleQuoteNextToQuoteCase (currentChar , i );
46
+ if (hasNextQuoteRightAfterCurrentQuoteWithoutComma (position + 1 )) {
47
+ handleQuoteNextToQuoteCase (currentChar , position );
48
48
return ;
49
49
}
50
50
escapedJson .append (ESCAPE_CHAR );
@@ -54,7 +54,7 @@ private void handleQuoteCharacter(char currentChar, int i) {
54
54
private void handleQuoteNextToQuoteCase (char currentChar , int i ) {
55
55
int nextQuotePosition = getNextNonSpaceCharPosition (i + 1 );
56
56
// If next valid quote is a good close quote, then the current quote MUST be an escaped quote
57
- if (isValidCloseQuote (nextQuotePosition )) {
57
+ if (isValidCloseQuoteAtPosition (nextQuotePosition )) {
58
58
escapedJson .append (ESCAPE_CHAR );
59
59
escapedJson .append (currentChar );
60
60
}
@@ -69,20 +69,9 @@ private void handleQuoteNextToQuoteCase(char currentChar, int i) {
69
69
}
70
70
71
71
private boolean hasNextQuoteRightAfterCurrentQuoteWithoutComma (int position ) {
72
- return findNextValidChar (position + 1 ) == DOUBLE_QUOTE_CHAR ;
72
+ return findNextNonSpaceChar (position + 1 ) == DOUBLE_QUOTE_CHAR ;
73
73
}
74
74
75
- private int getNextNonSpaceCharPosition (int position ) {
76
- for (int i = position ; i < inputString .length (); i ++) {
77
- char currentChar = inputString .charAt (i );
78
- if (currentChar != SPACE_CHAR && currentChar != BREAK_LINE_CHAR && currentChar != TAB_CHAR ) {
79
- return i ;
80
- }
81
- }
82
- return -1 ;
83
- }
84
-
85
-
86
75
private void handleNonQuoteCharacter (char currentChar ) {
87
76
if (!inQuotes ) {
88
77
escapedJson .append (currentChar );
@@ -102,16 +91,16 @@ private String getEscapeSequence(char currentChar) {
102
91
default -> "" ;
103
92
};
104
93
}
105
- private boolean isValidCloseQuote (int i ) {
106
- char nextValidChar = findNextValidChar ( i + 1 );
94
+ private boolean isValidCloseQuoteAtPosition (int position ) {
95
+ char nextValidChar = findNextNonSpaceChar ( position + 1 );
107
96
return nextValidChar == EOF
108
97
|| nextValidChar == ','
109
98
|| nextValidChar == '}'
110
99
|| nextValidChar == ']'
111
100
|| nextValidChar == ':' ;
112
101
}
113
102
114
- private char findNextValidChar (int position ) {
103
+ private char findNextNonSpaceChar (int position ) {
115
104
for (int i = position ; i < inputString .length (); i ++) {
116
105
char currentChar = inputString .charAt (i );
117
106
if (currentChar != SPACE_CHAR && currentChar != BREAK_LINE_CHAR && currentChar != TAB_CHAR ) {
@@ -121,4 +110,14 @@ private char findNextValidChar(int position) {
121
110
return EOF ;
122
111
}
123
112
113
+ private int getNextNonSpaceCharPosition (int position ) {
114
+ for (int i = position ; i < inputString .length (); i ++) {
115
+ char currentChar = inputString .charAt (i );
116
+ if (currentChar != SPACE_CHAR && currentChar != BREAK_LINE_CHAR && currentChar != TAB_CHAR ) {
117
+ return i ;
118
+ }
119
+ }
120
+ return -1 ;
121
+ }
122
+
124
123
}
0 commit comments