Class SourceCodeEscapers

java.lang.Object
com.google.errorprone.util.SourceCodeEscapers

public final class SourceCodeEscapers extends Object
A factory for Escaper instances used to escape strings for safe use in Java.

This is a subset of source code escapers that are in the process of being open-sources as part of guava, see: https://github.com/google/guava/issues/1620

  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.common.escape.CharEscaper
    Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java text block.
    static com.google.common.escape.CharEscaper
    Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal.

    Methods inherited from class Object

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

    • javaCharEscaper

      public static com.google.common.escape.CharEscaper javaCharEscaper()
      Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal. This is the preferred way to escape Java characters for use in String or character literals.

      See: The Java Language Specification for more details.

    • getJavaTextBlockEscaper

      public static com.google.common.escape.CharEscaper getJavaTextBlockEscaper()
      Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java text block.

      Double quotes are not escaped. If the string contents contain a run of three or more consecutive double quotes, additional action is required to make it safe to include in a text block.

      See: The Java Language Specification for more details.

      The Guava FR for this is: https://github.com/google/guava/issues/7421