Class AnyTransliterator

java.lang.Object
com.ibm.icu.text.Transliterator
com.ibm.icu.text.AnyTransliterator
All Implemented Interfaces:
StringTransform, Transform<String,String>

class AnyTransliterator extends Transliterator
A transliterator that translates multiple input scripts to a single output script. It is named Any-T or Any-T/V, where T is the target and V is the optional variant. The target T is a script.

An AnyTransliterator partitions text into runs of the same script, together with adjacent COMMON or INHERITED characters. After determining the script of each run, it transliterates from that script to the given target/variant. It does so by instantiating a transliterator from the source script to the target/variant. If a run consists only of the target script, COMMON, or INHERITED characters, then the run is not changed.

At startup, all possible AnyTransliterators are registered with the system, as determined by examining the registered script transliterators.

Since:
ICU 2.2
  • Field Details

  • Constructor Details

    • AnyTransliterator

      private AnyTransliterator(String id, String theTarget, String theVariant, int theTargetScript)
      Private constructor
      Parameters:
      id - the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.
      theTarget - the target name. Must not be empty, and must name a script corresponding to theTargetScript.
      theVariant - the variant name, or the empty string if there is no variant
      theTargetScript - the script code corresponding to theTarget.
    • AnyTransliterator

      public AnyTransliterator(String id, UnicodeFilter filter, String target2, int targetScript2, Transliterator widthFix2, ConcurrentHashMap<Integer,Transliterator> cache2)
      Parameters:
      id - the ID of the form S-T or S-T/V, where T is theTarget and V is theVariant. Must not be empty.
      filter - The Unicode filter.
      target2 - the target name.
      targetScript2 - the script code corresponding to theTarget.
      widthFix2 - Not used. This parameter is deprecated.
      cache2 - The Map object for cache.
  • Method Details

    • handleTransliterate

      protected void handleTransliterate(Replaceable text, Transliterator.Position pos, boolean isIncremental)
      Specified by:
      handleTransliterate in class Transliterator
      Parameters:
      text - the buffer holding transliterated and untransliterated text
      pos - the indices indicating the start, limit, context start, and context limit of the text.
      isIncremental - if true, assume more text may be inserted at pos.limit and act accordingly. Otherwise, transliterate all text between pos.start and pos.limit and move pos.start up to pos.limit.
      See Also:
    • getTransliterator

      private Transliterator getTransliterator(int source)
      Returns a transliterator from the given source to our target or target/variant. Returns NULL if the source is the same as our target script, or if the source is USCRIPT_INVALID_CODE. Caches the result and returns the same transliterator the next time. The caller does NOT own the result and must not delete it.
    • isWide

      private boolean isWide(int script)
      Parameters:
      targetScript2 -
      Returns:
    • register

      static void register()
      Registers standard transliterators with the system. Called by Transliterator during initialization. Scan all current targets and register those that are scripts T as Any-T/V.
    • scriptNameToCode

      private static int scriptNameToCode(String name)
      Return the script code for a given name, or UScript.INVALID_CODE if not found.
    • safeClone

      public Transliterator safeClone()
      Temporary hack for registry problem. Needs to be replaced by better architecture.
    • 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
      Parameters:
      targetSet - TODO
      See Also: