if (s == null) return; char[] chars = s.toCharArray(); char c; int last = 0; for (int pos = 0; pos < chars.length; ++pos) { c = chars[pos];  if (c < 32 || c > 127) { d.print(chars, last, (pos-last)); if ( c=='\n' ) { d.print("<br>"); } else { d.print("&#"); d.print((int) c); d.print(";"); } last = pos+1; } else switch (c) { case '&': d.print(chars, last, (pos-last)); d.print("&amp;"); last = pos+1; break; case '"': d.print(chars, last, (pos-last)); d.print("&quot;"); last = pos+1; break; case '<': d.print(chars, last, (pos-last)); d.print("&lt;"); last = pos+1; break; case '>': d.print(chars, last, (pos-last)); d.print("&gt;"); last = pos+1; break;  } } d.print(chars, last, chars.length-last);
quote(d, s, true);
    private static void quote(Device d, String s) throws IOException {	if (s == null) return;        char[] chars = s.toCharArray();	char c;        int last = 0;	for (int pos = 0; pos < chars.length; ++pos) {            c = chars[pos];            // write special characters as code ..            if (c < 32 || c > 127) {                d.print(chars, last, (pos-last));                if ( c=='\n' ) {                    d.print("<br>");                } else {                    d.print("&#");                    d.print((int) c);                    d.print(";");                } // end of if ()                last = pos+1;            }	    else switch (c) {	    case '&':                 d.print(chars, last, (pos-last));                d.print("&amp;");                last = pos+1;                break;	    case '"':                 d.print(chars, last, (pos-last));                d.print("&quot;");                last = pos+1;                break;	    case '<':                 d.print(chars, last, (pos-last));                d.print("&lt;");                last = pos+1;                break;	    case '>':                d.print(chars, last, (pos-last));                d.print("&gt;");                last = pos+1;                break;                /*                 * watchout: we cannot replace _space_ by &nbsp;                 * since non-breakable-space is a different                 * character: isolatin-char 160, not 32.                  * This will result in a confusion in forms:                 *   - the user enters space, presses submit                 *   - the form content is written to the Device by wingS,                 *     space is replaced by &nbsp;                 *   - the next time the form is submitted, we get                 *     isolatin-char 160, _not_ space.                 * (at least Konqueror behaves this correct; mozilla does not)                 *                                                       Henner                 */	    }	}        d.print(chars, last, chars.length-last);    }