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

Commit

Permalink
Fixed kson writing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
StaticDefaultTester2 committed Aug 11, 2020
1 parent 1fe9a63 commit 29678f0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void write(char[] src) {
}

public void write(char[] src, int offset, int length) {
int size = length - offset;
int size = length;
int need = this.currentIndex + size;
if (need >= this.currentSize) {
raise(need);
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/realtimetech/kson/writer/KsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,33 @@ private void writeString(String value) throws IOException {

int last = 0;
int length = value.length();

for (int i = 0; i < length; i++) {
char c = value.charAt(i);
char[] replacement;
char[] replacement = null;
if (c < 128) {
replacement = CONST_REPLACEMENT_CHARS[c];

if (replacement == null) {
continue;
}
} else if (c == '\u2028') {
replacement = CONST_U2028;
} else if (c == '\u2029') {
replacement = CONST_U2029;
} else {
continue;
}

if (last < i) {
stringWriter.write(charArray, last, i - last);
}
if(replacement != null){
if (last < i) {
stringWriter.write(charArray, last, i - last);
}

stringWriter.write(replacement);
last = i + 1;
stringWriter.write(replacement);
last = i + 1;
}
}

if (last < length) {
stringWriter.write(charArray, last, length - last);
}

stringWriter.write('\"');

}
}

0 comments on commit 29678f0

Please sign in to comment.