Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit 29678f0

Browse files
Fixed kson writing issue
1 parent 1fe9a63 commit 29678f0

File tree

8 files changed

+77
-13
lines changed

8 files changed

+77
-13
lines changed

.idea/.gitignore

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/realtimetech/kson/util/string/StringWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void write(char[] src) {
5353
}
5454

5555
public void write(char[] src, int offset, int length) {
56-
int size = length - offset;
56+
int size = length;
5757
int need = this.currentIndex + size;
5858
if (need >= this.currentSize) {
5959
raise(need);

src/main/java/com/realtimetech/kson/writer/KsonWriter.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,33 @@ private void writeString(String value) throws IOException {
139139

140140
int last = 0;
141141
int length = value.length();
142+
142143
for (int i = 0; i < length; i++) {
143144
char c = value.charAt(i);
144-
char[] replacement;
145+
char[] replacement = null;
145146
if (c < 128) {
146147
replacement = CONST_REPLACEMENT_CHARS[c];
147-
148-
if (replacement == null) {
149-
continue;
150-
}
151148
} else if (c == '\u2028') {
152149
replacement = CONST_U2028;
153150
} else if (c == '\u2029') {
154151
replacement = CONST_U2029;
155-
} else {
156-
continue;
157152
}
158153

159-
if (last < i) {
160-
stringWriter.write(charArray, last, i - last);
161-
}
154+
if(replacement != null){
155+
if (last < i) {
156+
stringWriter.write(charArray, last, i - last);
157+
}
162158

163-
stringWriter.write(replacement);
164-
last = i + 1;
159+
stringWriter.write(replacement);
160+
last = i + 1;
161+
}
165162
}
166163

167164
if (last < length) {
168165
stringWriter.write(charArray, last, length - last);
169166
}
170167

171168
stringWriter.write('\"');
169+
172170
}
173171
}

0 commit comments

Comments
 (0)