Skip to content

Commit a894ae4

Browse files
committed
Refactor naming
1 parent ab5faec commit a894ae4

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/main/java/com/cdpn/jsonautorepair/internal/EscapeProcessor.java

+19-20
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ public String process() {
3232
return escapedJson.toString();
3333
}
3434

35-
private void handleQuoteCharacter(char currentChar, int i) {
35+
private void handleQuoteCharacter(char currentChar, int position) {
3636
if (!inQuotes) {
3737
inQuotes = true;
3838
escapedJson.append(currentChar);
3939
return;
4040
}
41-
if(isValidCloseQuote(i)) {
41+
if(isValidCloseQuoteAtPosition(position)) {
4242
inQuotes = false;
4343
escapedJson.append(currentChar);
4444
return;
4545
}
46-
if(hasNextQuoteRightAfterCurrentQuoteWithoutComma(i + 1)) {
47-
handleQuoteNextToQuoteCase(currentChar, i);
46+
if(hasNextQuoteRightAfterCurrentQuoteWithoutComma(position + 1)) {
47+
handleQuoteNextToQuoteCase(currentChar, position);
4848
return;
4949
}
5050
escapedJson.append(ESCAPE_CHAR);
@@ -54,7 +54,7 @@ private void handleQuoteCharacter(char currentChar, int i) {
5454
private void handleQuoteNextToQuoteCase(char currentChar, int i) {
5555
int nextQuotePosition = getNextNonSpaceCharPosition(i + 1);
5656
// 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)) {
5858
escapedJson.append(ESCAPE_CHAR);
5959
escapedJson.append(currentChar);
6060
}
@@ -69,20 +69,9 @@ private void handleQuoteNextToQuoteCase(char currentChar, int i) {
6969
}
7070

7171
private boolean hasNextQuoteRightAfterCurrentQuoteWithoutComma(int position) {
72-
return findNextValidChar(position + 1) == DOUBLE_QUOTE_CHAR;
72+
return findNextNonSpaceChar(position + 1) == DOUBLE_QUOTE_CHAR;
7373
}
7474

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-
8675
private void handleNonQuoteCharacter(char currentChar) {
8776
if (!inQuotes) {
8877
escapedJson.append(currentChar);
@@ -102,16 +91,16 @@ private String getEscapeSequence(char currentChar) {
10291
default -> "";
10392
};
10493
}
105-
private boolean isValidCloseQuote(int i) {
106-
char nextValidChar = findNextValidChar(i + 1);
94+
private boolean isValidCloseQuoteAtPosition(int position) {
95+
char nextValidChar = findNextNonSpaceChar(position + 1);
10796
return nextValidChar == EOF
10897
|| nextValidChar == ','
10998
|| nextValidChar == '}'
11099
|| nextValidChar == ']'
111100
|| nextValidChar == ':';
112101
}
113102

114-
private char findNextValidChar(int position) {
103+
private char findNextNonSpaceChar(int position) {
115104
for (int i = position; i < inputString.length(); i++) {
116105
char currentChar = inputString.charAt(i);
117106
if (currentChar != SPACE_CHAR && currentChar != BREAK_LINE_CHAR && currentChar != TAB_CHAR) {
@@ -121,4 +110,14 @@ private char findNextValidChar(int position) {
121110
return EOF;
122111
}
123112

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+
124123
}

0 commit comments

Comments
 (0)