Home | History | Annotate | Download | only in impl
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5  *******************************************************************************
      6  * Copyright (C) 2002-2010, International Business Machines Corporation and    *
      7  * others. All Rights Reserved.                                                *
      8  *******************************************************************************
      9  */
     10 package android.icu.impl;
     11 
     12 import android.icu.text.Replaceable;
     13 import android.icu.text.ReplaceableString;
     14 import android.icu.text.Transliterator;
     15 import android.icu.text.UnicodeMatcher;
     16 /**
     17  * @author Ram
     18  * @hide Only a subset of ICU is exposed in Android
     19  */
     20 //This class contains utility functions so testing not needed
     21 ///CLOVER:OFF
     22 public class UtilityExtensions {
     23     /**
     24      * Append the given string to the rule.  Calls the single-character
     25      * version of appendToRule for each character.
     26      */
     27     public static void appendToRule(StringBuffer rule,
     28                                     String text,
     29                                     boolean isLiteral,
     30                                     boolean escapeUnprintable,
     31                                     StringBuffer quoteBuf) {
     32         for (int i=0; i<text.length(); ++i) {
     33             // Okay to process in 16-bit code units here
     34             Utility.appendToRule(rule, text.charAt(i), isLiteral, escapeUnprintable, quoteBuf);
     35         }
     36     }
     37 
     38 
     39     /**
     40      * Given a matcher reference, which may be null, append its
     41      * pattern as a literal to the given rule.
     42      */
     43     public static void appendToRule(StringBuffer rule,
     44                                     UnicodeMatcher matcher,
     45                                     boolean escapeUnprintable,
     46                                     StringBuffer quoteBuf) {
     47         if (matcher != null) {
     48             appendToRule(rule, matcher.toPattern(escapeUnprintable),
     49                          true, escapeUnprintable, quoteBuf);
     50         }
     51     }
     52     /**
     53      * For debugging purposes; format the given text in the form
     54      * aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
     55      * and limit, and the || indicate the start and limit.
     56      */
     57     public static String formatInput(ReplaceableString input,
     58                                      Transliterator.Position pos) {
     59         StringBuffer appendTo = new StringBuffer();
     60         formatInput(appendTo, input, pos);
     61         return android.icu.impl.Utility.escape(appendTo.toString());
     62     }
     63 
     64     /**
     65      * For debugging purposes; format the given text in the form
     66      * aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
     67      * and limit, and the || indicate the start and limit.
     68      */
     69     public static StringBuffer formatInput(StringBuffer appendTo,
     70                                            ReplaceableString input,
     71                                            Transliterator.Position pos) {
     72         if (0 <= pos.contextStart &&
     73             pos.contextStart <= pos.start &&
     74             pos.start <= pos.limit &&
     75             pos.limit <= pos.contextLimit &&
     76             pos.contextLimit <= input.length()) {
     77 
     78             String  b, c, d;
     79             //a = input.substring(0, pos.contextStart);
     80             b = input.substring(pos.contextStart, pos.start);
     81             c = input.substring(pos.start, pos.limit);
     82             d = input.substring(pos.limit, pos.contextLimit);
     83             //e = input.substring(pos.contextLimit, input.length());
     84             appendTo.//append(a).
     85                 append('{').append(b).
     86                 append('|').append(c).append('|').append(d).
     87                 append('}')
     88                 //.append(e)
     89                 ;
     90         } else {
     91             appendTo.append("INVALID Position {cs=" +
     92                             pos.contextStart + ", s=" + pos.start + ", l=" +
     93                             pos.limit + ", cl=" + pos.contextLimit + "} on " +
     94                             input);
     95         }
     96         return appendTo;
     97     }
     98 
     99     /**
    100      * Convenience method.
    101      */
    102     public static String formatInput(Replaceable input,
    103                                      Transliterator.Position pos) {
    104         return formatInput((ReplaceableString) input, pos);
    105     }
    106 
    107     /**
    108      * Convenience method.
    109      */
    110     public static StringBuffer formatInput(StringBuffer appendTo,
    111                                            Replaceable input,
    112                                            Transliterator.Position pos) {
    113         return formatInput(appendTo, (ReplaceableString) input, pos);
    114     }
    115 
    116 }
    117 //CLOVER:ON