more unicode work

This commit is contained in:
Grahame Grieve 2024-01-10 10:14:43 +11:00
parent eb95ed00b6
commit 33f43da3d7
3 changed files with 54 additions and 41 deletions

View File

@ -528,7 +528,6 @@ public class Utilities {
return value.replace("\r\n", "\r").replace("\n", "\r").replace("\r", "\r\n");
}
public static String unescapeXml(String xml) throws FHIRException {
if (xml == null)
return null;
@ -601,7 +600,7 @@ public class Utilities {
break;
case 'u':
String hex = json.substring(i + 1, i + 5);
b.append((char) Integer.parseInt(hex, 16));
b.append(Character.toString(Integer.parseInt(hex, 16)));
break;
default:
throw new FHIRException("Unknown JSON escape \\" + ch);

View File

@ -137,7 +137,14 @@ public class XhtmlComposer {
String src = node.getContent();
int i = 0;
while (i < src.length()) {
char c = src.charAt(i);
int ci = src.codePointAt(i);
if (ci > 65535) {
dst.append("&#x");
dst.append(Integer.toHexString(ci).toUpperCase());
dst.append(";");
i += Character.charCount(ci);
} else {
char c = (char) ci;
if (autoLinks && c == 'h' && Utilities.startsWithInList(src.substring(i), "http://", "https://")) {
int j = i;
while (i < src.length() && isValidUrlChar(src.charAt(i))) {
@ -182,6 +189,11 @@ public class XhtmlComposer {
}
}
}
}
boolean isTwoCharUnicodeCodePoint(char c1, char c2) {
return false;
}
private void writeComment(String indent, XhtmlNode node, boolean noPrettyOverride) throws IOException {
dst.append(indent + "<!-- " + node.getContent().trim() + " -->" + (pretty && !noPrettyOverride ? "\r\n" : ""));

View File

@ -217,6 +217,8 @@ public class XhtmlNodeTest {
public void testEntityNumberGreaterThanFFFF_Hex() throws IOException {
XhtmlNode x = new XhtmlParser().parse("<div>&#x1F637;</div>", "div");
Assertions.assertEquals("\uD83D\uDE37", x.getFirstElement().getChildNodes().get(0).getContent());
String html = new XhtmlComposer(false).compose(x);
Assertions.assertEquals("<div>&#x1F637;</div>", html);
}