diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..8bf4d45 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..310e0f2 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..13288e6 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e5c7225 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/com/realtimetech/kson/util/string/StringWriter.java b/src/main/java/com/realtimetech/kson/util/string/StringWriter.java index 70872a6..61a3a25 100644 --- a/src/main/java/com/realtimetech/kson/util/string/StringWriter.java +++ b/src/main/java/com/realtimetech/kson/util/string/StringWriter.java @@ -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); diff --git a/src/main/java/com/realtimetech/kson/writer/KsonWriter.java b/src/main/java/com/realtimetech/kson/writer/KsonWriter.java index 2ec4695..cf4f99a 100644 --- a/src/main/java/com/realtimetech/kson/writer/KsonWriter.java +++ b/src/main/java/com/realtimetech/kson/writer/KsonWriter.java @@ -139,29 +139,26 @@ 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) { @@ -169,5 +166,6 @@ private void writeString(String value) throws IOException { } stringWriter.write('\"'); + } }