Home | History | Annotate | Download | only in text
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4 **********************************************************************
      5 *   Copyright (c) 2002, International Business Machines Corporation
      6 *   and others.  All Rights Reserved.
      7 **********************************************************************
      8 *   Date        Name        Description
      9 *   01/14/2002  aliu        Creation.
     10 **********************************************************************
     11 */
     12 
     13 package com.ibm.icu.text;
     14 
     15 /**
     16  * <code>UnicodeReplacer</code> defines a protocol for objects that
     17  * replace a range of characters in a Replaceable string with output
     18  * text.  The replacement is done via the Replaceable API so as to
     19  * preserve out-of-band data.
     20  * @author Alan Liu
     21  */
     22 interface UnicodeReplacer {
     23 
     24     /**
     25      * Replace characters in 'text' from 'start' to 'limit' with the
     26      * output text of this object.  Update the 'cursor' parameter to
     27      * give the cursor position and return the length of the
     28      * replacement text.
     29      *
     30      * @param text the text to be matched
     31      * @param start inclusive start index of text to be replaced
     32      * @param limit exclusive end index of text to be replaced;
     33      * must be greater than or equal to start
     34      * @param cursor output parameter for the cursor position.
     35      * Not all replacer objects will update this, but in a complete
     36      * tree of replacer objects, representing the entire output side
     37      * of a transliteration rule, at least one must update it.
     38      * @return the number of 16-bit code units in the text replacing
     39      * the characters at offsets start..(limit-1) in text
     40      */
     41     public abstract int replace(Replaceable text,
     42                                 int start,
     43                                 int limit,
     44                                 int[] cursor);
     45 
     46     /**
     47      * Returns a string representation of this replacer.  If the
     48      * result of calling this function is passed to the appropriate
     49      * parser, typically TransliteratorParser, it will produce another
     50      * replacer that is equal to this one.
     51      * @param escapeUnprintable if TRUE then convert unprintable
     52      * character to their hex escape representations, \\uxxxx or
     53      * \\Uxxxxxxxx.  Unprintable characters are defined by
     54      * Utility.isUnprintable().
     55      */
     56     public abstract String toReplacerPattern(boolean escapeUnprintable);
     57 
     58     /**
     59      * Union the set of all characters that may output by this object
     60      * into the given set.
     61      * @param toUnionTo the set into which to union the output characters
     62      */
     63     public abstract void addReplacementSetTo(UnicodeSet toUnionTo);
     64 }
     65 
     66 //eof
     67