/****************************************************************************** * This program copies an Unicode text input stream to the console * character with the execption of the standard XML character entities * which it encodes. Also encodes codepoints above 127. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import org.pureprogrammer.Utils; public class XMLEncodingFilter { public static void main(String[] args) { int c; while ((c = Utils.getchar()) != -1) { if (c == "<".codePointAt(0)) { System.out.print("<"); } else if (c == ">".codePointAt(0)) { System.out.print(">"); } else if (c == "&".codePointAt(0)) { System.out.print("&"); } else if (c == "'".codePointAt(0)) { System.out.print("'"); } else if (c == "\"".codePointAt(0)) { System.out.print("""); } else if (c > 127) { System.out.print(Utils.format("&#x{0:04x};", c)); } else { System.out.print(String.valueOf(Character.toChars(c))); } } } }