Class XmlOutput.StringEscaper

  • All Implemented Interfaces:
    Enclosing class:

    static class XmlOutput.StringEscaper
    extends java.lang.Object
    implements java.lang.Cloneable
    Utility for replacing special characters with escape sequences in strings.

    A StringEscaper starts out as an identity transform in the "mutable" state. Call defineEscape(char, java.lang.String) as many times as necessary to set up mappings, and then call makeImmutable() before actually applying the defined transform. Or, use one of the global mappings pre-defined here.

    • Constructor Detail

      • StringEscaper

        Identity transform
    • Method Detail

      • defineEscape

        public void defineEscape​(char from,
                                 java.lang.String to)
        Map character "from" to escape sequence "to"
      • makeImmutable

        public void makeImmutable()
        Call this before attempting to escape strings; after this, defineEscape may not be called again.
      • escapeString

        public java.lang.String escapeString​(java.lang.String s)
        Apply an immutable transformation to the given string.
      • getMutableClone

        public XmlOutput.StringEscaper getMutableClone()
        Create a mutable escaper from an existing escaper, which may already be immutable.