public static void encodeTextInJavaScript(char ch, Appendable out) throws IOException { String escaped = getEscapedCharacter(ch); if(escaped!=null) out.append(escaped); else out.append(ch); }
public static void encodeTextInJavaScript(char[] cbuf, int start, int len, Writer out) throws IOException { int end = start+len; int toPrint = 0; for (int c = start; c < end; c++) { String escaped = getEscapedCharacter(cbuf[c]); if(escaped!=null) { if(toPrint>0) { out.write(cbuf, c-toPrint, toPrint); toPrint=0; } out.write(escaped); } else { toPrint++; } } if(toPrint>0) out.write(cbuf, end-toPrint, toPrint); }
public static void encodeTextInJavaScript(CharSequence S, int start, int end, Appendable out) throws IOException { if(S!=null) { int toPrint = 0; for (int c = start; c < end; c++) { String escaped = getEscapedCharacter(S.charAt(c)); if(escaped!=null) { if(toPrint>0) { out.append(S, c-toPrint, c); toPrint=0; } out.append(escaped); } else { toPrint++; } } if(toPrint>0) out.append(S, end-toPrint, end); } } // </editor-fold>