Class StringEscapeUtils

java.lang.Object
com.github.javaparser.utils.StringEscapeUtils

public final class StringEscapeUtils extends Object
Adapted from apache commons-lang3 project.

Unescapes escaped chars in strings.

  • Method Details

    • escapeJava

      public static String escapeJava(String input)

      Escapes the characters in a String using Java String rules.

      Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

      So a tab becomes the characters '\\' and 't'.

      The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.

      Example:

       input string: He didn't say, "Stop!"
       output string: He didn't say, \"Stop!\"
       
      Parameters:
      input - String to escape values in, may be null
      Returns:
      String with escaped values, null if null string input
    • unescapeJava

      public static String unescapeJava(String input)

      Unescapes any Java literals found in the String. For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.

      This can be replaced by String::translateEscapes in JDK 13

      Parameters:
      input - the String to unescape, may be null
      Returns:
      a new unescaped String, null if null string input
    • unescapeJavaTextBlock

      public static String unescapeJavaTextBlock(String input)