code: public boolean isCompatibleWith(EscapingMode mode) {
      // TODO: Come up with a compatibility matrix.
      if (mode == EscapingMode.ESCAPE_JS_VALUE) {
        // Don't introduce quotes inside a string.
        switch (state) {
          case JS_SQ_STRING:
          case JS_DQ_STRING:
          case CSS_SQ_STRING:
          case CSS_DQ_STRING:
            return false;
          default:
            return true;
        }
      } else if (mode == EscapingMode.TEXT) {
        // The TEXT directive may only be used in TEXT mode; in any other context, it would act as
        // autoescape-cancelling.
        return state == HtmlContext.TEXT;
      } else if (delimType == AttributeEndDelimiter.SPACE_OR_TAG_END) {
        // Need ESCAPE_HTML_ATTRIBUTE_NOSPACE instead.
        if (mode == EscapingMode.ESCAPE_HTML
            || mode == EscapingMode.ESCAPE_HTML_ATTRIBUTE
            || mode == EscapingMode.ESCAPE_HTML_RCDATA) {
          return false;
        }
      }
      return true;
    }
docs: True if the given escaping mode could make sense in this context.