List of usage examples for com.google.gwt.user.server.rpc.impl CharVector getSize
public int getSize()
From source file:com.foo.server.rpc230.ServerSerializationStreamWriterSenasa.java
License:Apache License
/** * This method takes a string and outputs a JavaScript string literal. The * data is surrounded with quotes, and any contained characters that need to * be escaped are mapped onto their escape sequence. * //from w ww. j av a 2 s . c o m * Assumptions: We are targeting a version of JavaScript that that is later * than 1.3 that supports unicode strings. */ public static String escapeString(String toEscape) { // make output big enough to escape every character (plus the quotes) char[] input = toEscape.toCharArray(); CharVector charVector = new CharVector(input.length * 2 + 2, input.length); charVector.add(JS_QUOTE_CHAR); for (int i = 0, n = input.length; i < n; ++i) { char c = input[i]; if (needsUnicodeEscape(c)) { unicodeEscape(c, charVector); } else { charVector.add(c); } } charVector.add(JS_QUOTE_CHAR); return String.valueOf(charVector.asArray(), 0, charVector.getSize()); }