Class XMLCommentEncoder


  • class XMLCommentEncoder
    extends Encoder
    XMLCommentEncoder -- Encodes for the XML/HTML comment context. The sequence "--" is not allowed in comments, and must be removed/replaced. We also must be careful of trailing hyphens at end of input, as they could combine with the external comment ending sequence "-->" to become "--->", which is also invalid. As with all XML-based context, invalid XML characters are not allowed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static char HYPHEN_REPLACEMENT
      This is the character used to replace a hyphen when a sequence of hypens is encountered.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.nio.charset.CoderResult encodeArrays​(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
      The core encoding loop used when both the input and output buffers are array backed.
      protected int firstEncodedOffset​(java.lang.String input, int off, int len)
      Scans the input string for the first character index that requires encoding.
      protected int maxEncodedLength​(int n)
      Returns the maximum encoded length (in chars) of an input sequence of n characters.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • HYPHEN_REPLACEMENT

        static final char HYPHEN_REPLACEMENT
        This is the character used to replace a hyphen when a sequence of hypens is encountered.
        See Also:
        Constant Field Values
    • Constructor Detail

      • XMLCommentEncoder

        XMLCommentEncoder()
    • Method Detail

      • maxEncodedLength

        protected int maxEncodedLength​(int n)
        Description copied from class: Encoder
        Returns the maximum encoded length (in chars) of an input sequence of n characters.
        Specified by:
        maxEncodedLength in class Encoder
        Parameters:
        n - the number of characters of input
        Returns:
        the worst-case number of characters required to encode
      • firstEncodedOffset

        protected int firstEncodedOffset​(java.lang.String input,
                                         int off,
                                         int len)
        Description copied from class: Encoder
        Scans the input string for the first character index that requires encoding. If the entire input does not require encoding then the length is returned. This method is used by the Encode.forXYZ methods to return input strings unchanged when possible.
        Specified by:
        firstEncodedOffset in class Encoder
        Parameters:
        input - the input to check for encoding
        off - the offset of the first character to check
        len - the number of characters to check
        Returns:
        the index of the first character to encode. The return value will be off+len if no characters in the input require encoding.
      • encodeArrays

        protected java.nio.charset.CoderResult encodeArrays​(java.nio.CharBuffer input,
                                                            java.nio.CharBuffer output,
                                                            boolean endOfInput)
        Description copied from class: Encoder
        The core encoding loop used when both the input and output buffers are array backed. The loop is expected to fetch the arrays and interact with the arrays directly for performance.
        Overrides:
        encodeArrays in class Encoder
        Parameters:
        input - the input buffer.
        output - the output buffer.
        endOfInput - when true, this is the last input to encode
        Returns:
        UNDERFLOW or OVERFLOW
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object