@Test public void testNeedsQuoting() throws Exception { assertTrue(HtmlQuoting.needsQuoting("abcde>")); assertTrue(HtmlQuoting.needsQuoting("<abcde")); assertTrue(HtmlQuoting.needsQuoting("abc'de")); assertTrue(HtmlQuoting.needsQuoting("abcde\"")); assertTrue(HtmlQuoting.needsQuoting("&")); assertFalse(HtmlQuoting.needsQuoting("")); assertFalse(HtmlQuoting.needsQuoting("ab\ncdef")); assertFalse(HtmlQuoting.needsQuoting(null)); }
public static boolean needsQuoting(byte[] data, int off, int len) { if (off+len > data.length) { throw new IllegalStateException("off+len=" + off+len + " should be lower" + " than data length=" + data.length); } for(int i=off; i< off+len; ++i) { switch(data[i]) { case '&': case '<': case '>': case '\'': case '"': return true; default: break; } } return false; }
HtmlQuoting { public static boolean needsQuoting(byte[] data, int off, int len) { if (off+len > data.length) { throw new IllegalStateException("off+len=" + off+len + " should be lower" + " than data length=" + data.length); } for(int i=off; i< off+len; ++i) { switch(data[i]) { case '&': case '<': case '>': case '\'': case '"': return true; default: break; } } return false; } }
HtmlQuoting { public static boolean needsQuoting(byte[] data, int off, int len) { if (off+len > data.length) { throw new IllegalStateException("off+len=" + off+len + " should be lower" + " than data length=" + data.length); } for(int i=off; i< off+len; ++i) { switch(data[i]) { case '&': case '<': case '>': case '\'': case '"': return true; default: break; } } return false; }  }
HtmlQuoting { public static boolean needsQuoting(byte[] data, int off, int len) { if (off+len > data.length) { throw new IllegalStateException("off+len=" + off+len + " should be lower" + " than data length=" + data.length); } for(int i=off; i< off+len; ++i) { switch(data[i]) { case '&': case '<': case '>': case '\'': case '"': return true; default: break; } } return false; }  static boolean needsQuoting(byte[] data, int off, int len); static boolean needsQuoting(String str); static void quoteHtmlChars(OutputStream output, byte[] buffer,
                                    int off, int len); static String quoteHtmlChars(String item); static OutputStream quoteOutputStream(final OutputStream out
                                               ); static String unquoteHtmlChars(String item); static void main(String[] args); }
HtmlQuoting { public static boolean needsQuoting(byte[] data, int off, int len) { if (off+len > data.length) { throw new IllegalStateException("off+len=" + off+len + " should be lower" + " than data length=" + data.length); } for(int i=off; i< off+len; ++i) { switch(data[i]) { case '&': case '<': case '>': case '\'': case '"': return true; default: break; } } return false; }  static boolean needsQuoting(byte[] data, int off, int len); static boolean needsQuoting(String str); static void quoteHtmlChars(OutputStream output, byte[] buffer,
                                    int off, int len); static String quoteHtmlChars(String item); static OutputStream quoteOutputStream(final OutputStream out
                                               ); static String unquoteHtmlChars(String item); static void main(String[] args);  }