2 * Copyright (C) 1996-2004, International Business Machines Corporation and
3 * others. All Rights Reserved.
6 package com.ibm.icu.text;
9 abstract class TransformTransliterator {
14 // * An abstract class for transliterators based on a transform
15 // * operation. To create a transliterator that implements a
16 // * transformation, create a subclass of this class and implement the
17 // * abstract <code>transform()</code> and <code>hasTransform()</code>
21 //abstract class TransformTransliterator extends Transliterator {
24 // * Constructs a transliterator. For use by subclasses.
26 // protected TransformTransliterator(String id, UnicodeFilter f) {
31 // * Implements {@link Transliterator#handleTransliterate}.
33 // protected void handleTransliterate(Replaceable text,
34 // Position offsets, boolean incremental) {
37 // for (start = offsets.start; start < offsets.limit; ++start) {
38 // // Scan for the first character that is != its transform.
39 // // If there are none, we fall out without doing anything.
40 // char c = text.charAt(start);
41 // if (hasTransform(c)) {
42 // // There is a transforming character at start. Break
43 // // up the remaining string, from start to
44 // // offsets.limit, into segments of unfiltered and
45 // // filtered characters. Only transform the unfiltered
46 // // characters. As always, minimize the number of
47 // // calls to Replaceable.replace().
49 // int len = offsets.limit - start;
50 // // assert(len >= 1);
52 // char[] buf = new char[len];
53 // text.getChars(start, offsets.limit, buf, 0);
57 // UnicodeFilter filt = getFilter();
59 // // lenDelta is the accumulated length difference for
60 // // all transformed segments. It is new length - old
64 // // Set segStart, segLimit to the unfiltered segment
65 // // starting with start. If the filter is null, then
66 // // segStart/Limit will be set to the whole string,
69 // // Set segLimit to the first filtered char at or
72 // if (filt != null) {
73 // segLimit = segStart;
74 // while (segLimit < len && filt.contains(buf[segLimit])) {
79 // // Transform the unfiltered chars between segStart
81 // int segLen = segLimit - segStart;
83 // String newStr = transform(
84 // new String(buf, segStart, segLen));
85 // text.replace(start, start + segLen, newStr);
86 // start += newStr.length();
87 // lenDelta += newStr.length() - segLen;
90 // // Set segStart to the first unfiltered char at or
92 // segStart = segLimit;
93 // if (filt != null) {
94 // while (segStart < len && !filt.contains(buf[segStart])) {
98 // start += segStart - segLimit;
100 // } while (segStart < len);
102 // offsets.limit += lenDelta;
103 // offsets.contextLimit += lenDelta;
104 // offsets.start = offsets.limit;
108 // // assert(start == offsets.limit);
109 // offsets.start = start;
113 // * Subclasses must implement this method to determine whether a
114 // * given character has a transform that is not equal to itself.
115 // * This is approximately equivalent to <code>c !=
116 // * transform(String.valueOf(c))</code>, where
117 // * <code>String.valueOf(c)</code> returns a String containing the
118 // * single character (not integer) <code>c</code>. Subclasses that
119 // * transform all their input can simply return <code>true</code>.
121 // protected abstract boolean hasTransform(int c);
124 // * Subclasses must implement this method to transform a string.
126 // protected abstract String transform(String s);