Class SourceCodeEscapers


  • public final class SourceCodeEscapers
    extends java.lang.Object
    A factory for Escaper instances used to escape strings for safe use in various common programming languages.

    NOTE: This class is cribbed from the Guava libraries SourceCodeEscapers which is not part of the current Guava release. https://github.com/google/guava/issues/1620

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendWithJavascriptEscaper​(java.lang.CharSequence c, java.lang.Appendable to)
      Uses javascriptEscaper() to append the escaped transformation of c to to.
      static com.google.common.escape.Escaper javascriptEscaper()
      Returns an Escaper instance that replaces non-ASCII characters in a string with their equivalent Javascript UTF-16 escape sequences "\unnnn", "\xnn" or special replacement sequences "\b", "\t", "\n", "\f", "\r" or "\\".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • javascriptEscaper

        public static com.google.common.escape.Escaper javascriptEscaper()
        Returns an Escaper instance that replaces non-ASCII characters in a string with their equivalent Javascript UTF-16 escape sequences "\unnnn", "\xnn" or special replacement sequences "\b", "\t", "\n", "\f", "\r" or "\\".

        Warning: This escaper is not suitable for JSON. JSON users may wish to use GSON or other high-level APIs when possible.

      • appendWithJavascriptEscaper

        public static void appendWithJavascriptEscaper​(java.lang.CharSequence c,
                                                       java.lang.Appendable to)
                                                throws java.io.IOException
        Uses javascriptEscaper() to append the escaped transformation of c to to. Using this method can be more memory efficient than calling Escaper.escape(String).
        Throws:
        java.io.IOException