Class JSMarshaller


  • @Immutable
    public final class JSMarshaller
    extends Object
    JavaScript String helper
    Author:
    Philip Helger
    • Method Detail

      • javaScriptEscape

        @Nullable
        public static String javaScriptEscape​(@Nullable
                                              String sInput)
        Turn special characters into escaped characters conforming to JavaScript. Handles complete character set defined in HTML 4.01 recommendation.
        Reference: Core JavaScript 1.5 Guide
        Parameters:
        sInput - the input string
        Returns:
        the escaped string
      • javaScriptEscapeForRegEx

        @Nonnull
        public static String javaScriptEscapeForRegEx​(char cInput)
      • javaScriptEscapeForRegEx

        @Nullable
        public static String javaScriptEscapeForRegEx​(@Nullable
                                                      String sInput)
        Turn special regular expression characters into escaped characters conforming to JavaScript.
        Reference: MDN Regular Expressions
        Parameters:
        sInput - the input string
        Returns:
        the escaped string
      • javaScriptUnescape

        @Nullable
        public static String javaScriptUnescape​(@Nullable
                                                String sInput)
        Unescape a previously escaped string.
        Important: this is not a 100% reversion of javaScriptEscape(String) since the escaping method drops any '\r' character and it will therefore not be unescaped!
        Parameters:
        sInput - The string to be unescaped. May be null.
        Returns:
        The unescaped string.
        See Also:
        javaScriptEscape(String)
      • isJSIdentifier

        public static boolean isJSIdentifier​(@Nullable
                                             String s)