Skip to content

Commit

Permalink
Apply Felix Meschberger's patch to fix the high unicode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaustein committed Aug 18, 2017
1 parent f9aba22 commit 49758b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/org/kxml2/io/KXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,14 @@ private final void push(int c) {
txtBuf = bigger;
}

txtBuf[txtPos++] = (char) c;
if (c > 0xffff) {
// write high Unicode value as surrogate pair
int offset = c - 0x010000;
txtBuf[txtPos++] = (char)((offset >>> 10) + 0xd800);
txtBuf[txtPos++] = (char)((offset & 0x3ff) + 0xdc00);
} else {
txtBuf[txtPos++] = (char) c;
}
}

/** Sets name and attributes */
Expand Down
13 changes: 10 additions & 3 deletions src/org/kxml2/io/KXmlSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,18 @@ private final void writeEscaped(String s, int quot)
//if(c < ' ')
// throw new IllegalArgumentException("Illegal control code:"+((int) c));

if (c >= ' ' && c !='@' && (c < 127 || unicode))
if (c >= 0xd800 && c <= 0xdfff && i < s.length() - 1) {
// write surrogate pair as single code value
i++;
int h = c;
int l = s.charAt(i);
int n = ((h - 0xd800) << 10) + (l - 0xdc00) + 0x010000;
writer.write("&#" + n + ";");
} if (c >= ' ' && c !='@' && (c < 127 || unicode)) {
writer.write(c);
else
} else {
writer.write("&#" + ((int) c) + ";");

}
}
}
}
Expand Down

0 comments on commit 49758b4

Please sign in to comment.