Class EscapeTransliterator

  • All Implemented Interfaces:
    StringTransform, Transform<java.lang.String,​java.lang.String>

    class EscapeTransliterator
    extends Transliterator
    A transliterator that converts Unicode characters to an escape form. Examples of escape forms are "U+4E01" and "􏿿". Escape forms have a prefix and suffix, either of which may be empty, a radix, typically 16 or 10, a minimum digit count, typically 1, 4, or 8, and a boolean that specifies whether supplemental characters are handled as 32-bit code points or as two 16-bit code units. Most escape forms handle 32-bit code points, but some, such as the Java form, intentionally break them into two surrogate pairs, for backward compatibility.

    Some escape forms actually have two different patterns, one for BMP characters (0..FFFF) and one for supplements (>FFFF). To handle this, a second EscapeTransliterator may be defined that specifies the pattern to be produced for supplementals. An example of a form that requires this is the C form, which uses "\\uFFFF" for BMP characters and "\\U0010FFFF" for supplementals.

    This class is package private. It registers several standard variants with the system which are then accessed via their IDs.

    • Field Detail

      • prefix

        private java.lang.String prefix
        The prefix of the escape form; may be empty, but usually isn't. May not be null.
      • suffix

        private java.lang.String suffix
        The prefix of the escape form; often empty. May not be null.
      • radix

        private int radix
        The radix to display the number in. Typically 16 or 10. Must be in the range 2 to 36.
      • minDigits

        private int minDigits
        The minimum number of digits. Typically 1, 4, or 8. Values less than 1 are equivalent to 1.
      • grokSupplementals

        private boolean grokSupplementals
        If true, supplementals are handled as 32-bit code points. If false, they are handled as two 16-bit code units.
      • supplementalHandler

        private EscapeTransliterator supplementalHandler
        The form to be used for supplementals. If this is null then the same form is used for BMP characters and supplementals. If this is not null and if grokSupplementals is true then the prefix, suffix, radix, and minDigits of this object are used for supplementals.
    • Constructor Detail

      • EscapeTransliterator

        EscapeTransliterator​(java.lang.String ID,
                             java.lang.String prefix,
                             java.lang.String suffix,
                             int radix,
                             int minDigits,
                             boolean grokSupplementals,
                             EscapeTransliterator supplementalHandler)
        Constructs an escape transliterator with the given ID and parameters. See the class member documentation for details.
    • Method Detail

      • register

        static void register()
        Registers standard variants with the system. Called by Transliterator during initialization.
      • addSourceTargetSet

        public void addSourceTargetSet​(UnicodeSet inputFilter,
                                       UnicodeSet sourceSet,
                                       UnicodeSet targetSet)
        Description copied from class: Transliterator
        Returns the set of all characters that may be generated as replacement text by this transliterator, filtered by BOTH the input filter, and the current getFilter().

        SHOULD BE OVERRIDDEN BY SUBCLASSES. It is probably an error for any transliterator to NOT override this, but we can't force them to for backwards compatibility.

        Other methods vector through this.

        When gathering the information on source and target, the compound transliterator makes things complicated. For example, suppose we have:

         Global FILTER = [ax]
         a > b;
         :: NULL;
         b > c;
         x > d;
         
        While the filter just allows a and x, b is an intermediate result, which could produce c. So the source and target sets cannot be gathered independently. What we have to do is filter the sources for the first transliterator according to the global filter, intersect that transliterator's filter. Based on that we get the target. The next transliterator gets as a global filter (global + last target). And so on.

        There is another complication:

         Global FILTER = [ax]
         a >|b;
         b >c;
         
        Even though b would be filtered from the input, whenever we have a backup, it could be part of the input. So ideally we will change the global filter as we go.
        Overrides:
        addSourceTargetSet in class Transliterator
        targetSet - TODO
        See Also:
        Transliterator.getTargetSet()