Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (C) 1999-2007, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Date Name Description |
michael@0 | 7 | * 11/17/99 aliu Creation. |
michael@0 | 8 | ********************************************************************** |
michael@0 | 9 | */ |
michael@0 | 10 | #ifndef RBT_H |
michael@0 | 11 | #define RBT_H |
michael@0 | 12 | |
michael@0 | 13 | #include "unicode/utypes.h" |
michael@0 | 14 | |
michael@0 | 15 | #if !UCONFIG_NO_TRANSLITERATION |
michael@0 | 16 | |
michael@0 | 17 | #include "unicode/translit.h" |
michael@0 | 18 | #include "unicode/utypes.h" |
michael@0 | 19 | #include "unicode/parseerr.h" |
michael@0 | 20 | #include "unicode/udata.h" |
michael@0 | 21 | |
michael@0 | 22 | #define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit" |
michael@0 | 23 | |
michael@0 | 24 | U_NAMESPACE_BEGIN |
michael@0 | 25 | |
michael@0 | 26 | class TransliterationRuleData; |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * <code>RuleBasedTransliterator</code> is a transliterator |
michael@0 | 30 | * that reads a set of rules in order to determine how to perform |
michael@0 | 31 | * translations. Rule sets are stored in resource bundles indexed by |
michael@0 | 32 | * name. Rules within a rule set are separated by semicolons (';'). |
michael@0 | 33 | * To include a literal semicolon, prefix it with a backslash ('\'). |
michael@0 | 34 | * Whitespace, as defined by <code>Character.isWhitespace()</code>, |
michael@0 | 35 | * is ignored. If the first non-blank character on a line is '#', |
michael@0 | 36 | * the entire line is ignored as a comment. </p> |
michael@0 | 37 | * |
michael@0 | 38 | * <p>Each set of rules consists of two groups, one forward, and one |
michael@0 | 39 | * reverse. This is a convention that is not enforced; rules for one |
michael@0 | 40 | * direction may be omitted, with the result that translations in |
michael@0 | 41 | * that direction will not modify the source text. In addition, |
michael@0 | 42 | * bidirectional forward-reverse rules may be specified for |
michael@0 | 43 | * symmetrical transformations.</p> |
michael@0 | 44 | * |
michael@0 | 45 | * <p><b>Rule syntax</b> </p> |
michael@0 | 46 | * |
michael@0 | 47 | * <p>Rule statements take one of the following forms: </p> |
michael@0 | 48 | * |
michael@0 | 49 | * <dl> |
michael@0 | 50 | * <dt><code>$alefmadda=\u0622;</code></dt> |
michael@0 | 51 | * <dd><strong>Variable definition.</strong> The name on the |
michael@0 | 52 | * left is assigned the text on the right. In this example, |
michael@0 | 53 | * after this statement, instances of the left hand name, |
michael@0 | 54 | * "<code>$alefmadda</code>", will be replaced by |
michael@0 | 55 | * the Unicode character U+0622. Variable names must begin |
michael@0 | 56 | * with a letter and consist only of letters, digits, and |
michael@0 | 57 | * underscores. Case is significant. Duplicate names cause |
michael@0 | 58 | * an exception to be thrown, that is, variables cannot be |
michael@0 | 59 | * redefined. The right hand side may contain well-formed |
michael@0 | 60 | * text of any length, including no text at all ("<code>$empty=;</code>"). |
michael@0 | 61 | * The right hand side may contain embedded <code>UnicodeSet</code> |
michael@0 | 62 | * patterns, for example, "<code>$softvowel=[eiyEIY]</code>".</dd> |
michael@0 | 63 | * <dd> </dd> |
michael@0 | 64 | * <dt><code>ai>$alefmadda;</code></dt> |
michael@0 | 65 | * <dd><strong>Forward translation rule.</strong> This rule |
michael@0 | 66 | * states that the string on the left will be changed to the |
michael@0 | 67 | * string on the right when performing forward |
michael@0 | 68 | * transliteration.</dd> |
michael@0 | 69 | * <dt> </dt> |
michael@0 | 70 | * <dt><code>ai<$alefmadda;</code></dt> |
michael@0 | 71 | * <dd><strong>Reverse translation rule.</strong> This rule |
michael@0 | 72 | * states that the string on the right will be changed to |
michael@0 | 73 | * the string on the left when performing reverse |
michael@0 | 74 | * transliteration.</dd> |
michael@0 | 75 | * </dl> |
michael@0 | 76 | * |
michael@0 | 77 | * <dl> |
michael@0 | 78 | * <dt><code>ai<>$alefmadda;</code></dt> |
michael@0 | 79 | * <dd><strong>Bidirectional translation rule.</strong> This |
michael@0 | 80 | * rule states that the string on the right will be changed |
michael@0 | 81 | * to the string on the left when performing forward |
michael@0 | 82 | * transliteration, and vice versa when performing reverse |
michael@0 | 83 | * transliteration.</dd> |
michael@0 | 84 | * </dl> |
michael@0 | 85 | * |
michael@0 | 86 | * <p>Translation rules consist of a <em>match pattern</em> and an <em>output |
michael@0 | 87 | * string</em>. The match pattern consists of literal characters, |
michael@0 | 88 | * optionally preceded by context, and optionally followed by |
michael@0 | 89 | * context. Context characters, like literal pattern characters, |
michael@0 | 90 | * must be matched in the text being transliterated. However, unlike |
michael@0 | 91 | * literal pattern characters, they are not replaced by the output |
michael@0 | 92 | * text. For example, the pattern "<code>abc{def}</code>" |
michael@0 | 93 | * indicates the characters "<code>def</code>" must be |
michael@0 | 94 | * preceded by "<code>abc</code>" for a successful match. |
michael@0 | 95 | * If there is a successful match, "<code>def</code>" will |
michael@0 | 96 | * be replaced, but not "<code>abc</code>". The final '<code>}</code>' |
michael@0 | 97 | * is optional, so "<code>abc{def</code>" is equivalent to |
michael@0 | 98 | * "<code>abc{def}</code>". Another example is "<code>{123}456</code>" |
michael@0 | 99 | * (or "<code>123}456</code>") in which the literal |
michael@0 | 100 | * pattern "<code>123</code>" must be followed by "<code>456</code>". |
michael@0 | 101 | * </p> |
michael@0 | 102 | * |
michael@0 | 103 | * <p>The output string of a forward or reverse rule consists of |
michael@0 | 104 | * characters to replace the literal pattern characters. If the |
michael@0 | 105 | * output string contains the character '<code>|</code>', this is |
michael@0 | 106 | * taken to indicate the location of the <em>cursor</em> after |
michael@0 | 107 | * replacement. The cursor is the point in the text at which the |
michael@0 | 108 | * next replacement, if any, will be applied. The cursor is usually |
michael@0 | 109 | * placed within the replacement text; however, it can actually be |
michael@0 | 110 | * placed into the precending or following context by using the |
michael@0 | 111 | * special character '<code>@</code>'. Examples:</p> |
michael@0 | 112 | * |
michael@0 | 113 | * <blockquote> |
michael@0 | 114 | * <p><code>a {foo} z > | @ bar; # foo -> bar, move cursor |
michael@0 | 115 | * before a<br> |
michael@0 | 116 | * {foo} xyz > bar @@|; # foo -> bar, cursor between |
michael@0 | 117 | * y and z</code></p> |
michael@0 | 118 | * </blockquote> |
michael@0 | 119 | * |
michael@0 | 120 | * <p><b>UnicodeSet</b></p> |
michael@0 | 121 | * |
michael@0 | 122 | * <p><code>UnicodeSet</code> patterns may appear anywhere that |
michael@0 | 123 | * makes sense. They may appear in variable definitions. |
michael@0 | 124 | * Contrariwise, <code>UnicodeSet</code> patterns may themselves |
michael@0 | 125 | * contain variable references, such as "<code>$a=[a-z];$not_a=[^$a]</code>", |
michael@0 | 126 | * or "<code>$range=a-z;$ll=[$range]</code>".</p> |
michael@0 | 127 | * |
michael@0 | 128 | * <p><code>UnicodeSet</code> patterns may also be embedded directly |
michael@0 | 129 | * into rule strings. Thus, the following two rules are equivalent:</p> |
michael@0 | 130 | * |
michael@0 | 131 | * <blockquote> |
michael@0 | 132 | * <p><code>$vowel=[aeiou]; $vowel>'*'; # One way to do this<br> |
michael@0 | 133 | * [aeiou]>'*'; |
michael@0 | 134 | * # |
michael@0 | 135 | * Another way</code></p> |
michael@0 | 136 | * </blockquote> |
michael@0 | 137 | * |
michael@0 | 138 | * <p>See {@link UnicodeSet} for more documentation and examples.</p> |
michael@0 | 139 | * |
michael@0 | 140 | * <p><b>Segments</b></p> |
michael@0 | 141 | * |
michael@0 | 142 | * <p>Segments of the input string can be matched and copied to the |
michael@0 | 143 | * output string. This makes certain sets of rules simpler and more |
michael@0 | 144 | * general, and makes reordering possible. For example:</p> |
michael@0 | 145 | * |
michael@0 | 146 | * <blockquote> |
michael@0 | 147 | * <p><code>([a-z]) > $1 $1; |
michael@0 | 148 | * # |
michael@0 | 149 | * double lowercase letters<br> |
michael@0 | 150 | * ([:Lu:]) ([:Ll:]) > $2 $1; # reverse order of Lu-Ll pairs</code></p> |
michael@0 | 151 | * </blockquote> |
michael@0 | 152 | * |
michael@0 | 153 | * <p>The segment of the input string to be copied is delimited by |
michael@0 | 154 | * "<code>(</code>" and "<code>)</code>". Up to |
michael@0 | 155 | * nine segments may be defined. Segments may not overlap. In the |
michael@0 | 156 | * output string, "<code>$1</code>" through "<code>$9</code>" |
michael@0 | 157 | * represent the input string segments, in left-to-right order of |
michael@0 | 158 | * definition.</p> |
michael@0 | 159 | * |
michael@0 | 160 | * <p><b>Anchors</b></p> |
michael@0 | 161 | * |
michael@0 | 162 | * <p>Patterns can be anchored to the beginning or the end of the text. This is done with the |
michael@0 | 163 | * special characters '<code>^</code>' and '<code>$</code>'. For example:</p> |
michael@0 | 164 | * |
michael@0 | 165 | * <blockquote> |
michael@0 | 166 | * <p><code>^ a > 'BEG_A'; # match 'a' at start of text<br> |
michael@0 | 167 | * a > 'A'; # match other instances |
michael@0 | 168 | * of 'a'<br> |
michael@0 | 169 | * z $ > 'END_Z'; # match 'z' at end of text<br> |
michael@0 | 170 | * z > 'Z'; # match other instances |
michael@0 | 171 | * of 'z'</code></p> |
michael@0 | 172 | * </blockquote> |
michael@0 | 173 | * |
michael@0 | 174 | * <p>It is also possible to match the beginning or the end of the text using a <code>UnicodeSet</code>. |
michael@0 | 175 | * This is done by including a virtual anchor character '<code>$</code>' at the end of the |
michael@0 | 176 | * set pattern. Although this is usually the match chafacter for the end anchor, the set will |
michael@0 | 177 | * match either the beginning or the end of the text, depending on its placement. For |
michael@0 | 178 | * example:</p> |
michael@0 | 179 | * |
michael@0 | 180 | * <blockquote> |
michael@0 | 181 | * <p><code>$x = [a-z$]; # match 'a' through 'z' OR anchor<br> |
michael@0 | 182 | * $x 1 > 2; # match '1' after a-z or at the start<br> |
michael@0 | 183 | * 3 $x > 4; # match '3' before a-z or at the end</code></p> |
michael@0 | 184 | * </blockquote> |
michael@0 | 185 | * |
michael@0 | 186 | * <p><b>Example</b> </p> |
michael@0 | 187 | * |
michael@0 | 188 | * <p>The following example rules illustrate many of the features of |
michael@0 | 189 | * the rule language. </p> |
michael@0 | 190 | * |
michael@0 | 191 | * <table border="0" cellpadding="4"> |
michael@0 | 192 | * <tr> |
michael@0 | 193 | * <td valign="top">Rule 1.</td> |
michael@0 | 194 | * <td valign="top" nowrap><code>abc{def}>x|y</code></td> |
michael@0 | 195 | * </tr> |
michael@0 | 196 | * <tr> |
michael@0 | 197 | * <td valign="top">Rule 2.</td> |
michael@0 | 198 | * <td valign="top" nowrap><code>xyz>r</code></td> |
michael@0 | 199 | * </tr> |
michael@0 | 200 | * <tr> |
michael@0 | 201 | * <td valign="top">Rule 3.</td> |
michael@0 | 202 | * <td valign="top" nowrap><code>yz>q</code></td> |
michael@0 | 203 | * </tr> |
michael@0 | 204 | * </table> |
michael@0 | 205 | * |
michael@0 | 206 | * <p>Applying these rules to the string "<code>adefabcdefz</code>" |
michael@0 | 207 | * yields the following results: </p> |
michael@0 | 208 | * |
michael@0 | 209 | * <table border="0" cellpadding="4"> |
michael@0 | 210 | * <tr> |
michael@0 | 211 | * <td valign="top" nowrap><code>|adefabcdefz</code></td> |
michael@0 | 212 | * <td valign="top">Initial state, no rules match. Advance |
michael@0 | 213 | * cursor.</td> |
michael@0 | 214 | * </tr> |
michael@0 | 215 | * <tr> |
michael@0 | 216 | * <td valign="top" nowrap><code>a|defabcdefz</code></td> |
michael@0 | 217 | * <td valign="top">Still no match. Rule 1 does not match |
michael@0 | 218 | * because the preceding context is not present.</td> |
michael@0 | 219 | * </tr> |
michael@0 | 220 | * <tr> |
michael@0 | 221 | * <td valign="top" nowrap><code>ad|efabcdefz</code></td> |
michael@0 | 222 | * <td valign="top">Still no match. Keep advancing until |
michael@0 | 223 | * there is a match...</td> |
michael@0 | 224 | * </tr> |
michael@0 | 225 | * <tr> |
michael@0 | 226 | * <td valign="top" nowrap><code>ade|fabcdefz</code></td> |
michael@0 | 227 | * <td valign="top">...</td> |
michael@0 | 228 | * </tr> |
michael@0 | 229 | * <tr> |
michael@0 | 230 | * <td valign="top" nowrap><code>adef|abcdefz</code></td> |
michael@0 | 231 | * <td valign="top">...</td> |
michael@0 | 232 | * </tr> |
michael@0 | 233 | * <tr> |
michael@0 | 234 | * <td valign="top" nowrap><code>adefa|bcdefz</code></td> |
michael@0 | 235 | * <td valign="top">...</td> |
michael@0 | 236 | * </tr> |
michael@0 | 237 | * <tr> |
michael@0 | 238 | * <td valign="top" nowrap><code>adefab|cdefz</code></td> |
michael@0 | 239 | * <td valign="top">...</td> |
michael@0 | 240 | * </tr> |
michael@0 | 241 | * <tr> |
michael@0 | 242 | * <td valign="top" nowrap><code>adefabc|defz</code></td> |
michael@0 | 243 | * <td valign="top">Rule 1 matches; replace "<code>def</code>" |
michael@0 | 244 | * with "<code>xy</code>" and back up the cursor |
michael@0 | 245 | * to before the '<code>y</code>'.</td> |
michael@0 | 246 | * </tr> |
michael@0 | 247 | * <tr> |
michael@0 | 248 | * <td valign="top" nowrap><code>adefabcx|yz</code></td> |
michael@0 | 249 | * <td valign="top">Although "<code>xyz</code>" is |
michael@0 | 250 | * present, rule 2 does not match because the cursor is |
michael@0 | 251 | * before the '<code>y</code>', not before the '<code>x</code>'. |
michael@0 | 252 | * Rule 3 does match. Replace "<code>yz</code>" |
michael@0 | 253 | * with "<code>q</code>".</td> |
michael@0 | 254 | * </tr> |
michael@0 | 255 | * <tr> |
michael@0 | 256 | * <td valign="top" nowrap><code>adefabcxq|</code></td> |
michael@0 | 257 | * <td valign="top">The cursor is at the end; |
michael@0 | 258 | * transliteration is complete.</td> |
michael@0 | 259 | * </tr> |
michael@0 | 260 | * </table> |
michael@0 | 261 | * |
michael@0 | 262 | * <p>The order of rules is significant. If multiple rules may match |
michael@0 | 263 | * at some point, the first matching rule is applied. </p> |
michael@0 | 264 | * |
michael@0 | 265 | * <p>Forward and reverse rules may have an empty output string. |
michael@0 | 266 | * Otherwise, an empty left or right hand side of any statement is a |
michael@0 | 267 | * syntax error. </p> |
michael@0 | 268 | * |
michael@0 | 269 | * <p>Single quotes are used to quote any character other than a |
michael@0 | 270 | * digit or letter. To specify a single quote itself, inside or |
michael@0 | 271 | * outside of quotes, use two single quotes in a row. For example, |
michael@0 | 272 | * the rule "<code>'>'>o''clock</code>" changes the |
michael@0 | 273 | * string "<code>></code>" to the string "<code>o'clock</code>". |
michael@0 | 274 | * </p> |
michael@0 | 275 | * |
michael@0 | 276 | * <p><b>Notes</b> </p> |
michael@0 | 277 | * |
michael@0 | 278 | * <p>While a RuleBasedTransliterator is being built, it checks that |
michael@0 | 279 | * the rules are added in proper order. For example, if the rule |
michael@0 | 280 | * "a>x" is followed by the rule "ab>y", |
michael@0 | 281 | * then the second rule will throw an exception. The reason is that |
michael@0 | 282 | * the second rule can never be triggered, since the first rule |
michael@0 | 283 | * always matches anything it matches. In other words, the first |
michael@0 | 284 | * rule <em>masks</em> the second rule. </p> |
michael@0 | 285 | * |
michael@0 | 286 | * @author Alan Liu |
michael@0 | 287 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 288 | */ |
michael@0 | 289 | class RuleBasedTransliterator : public Transliterator { |
michael@0 | 290 | private: |
michael@0 | 291 | /** |
michael@0 | 292 | * The data object is immutable, so we can freely share it with |
michael@0 | 293 | * other instances of RBT, as long as we do NOT own this object. |
michael@0 | 294 | * TODO: data is no longer immutable. See bugs #1866, 2155 |
michael@0 | 295 | */ |
michael@0 | 296 | TransliterationRuleData* fData; |
michael@0 | 297 | |
michael@0 | 298 | /** |
michael@0 | 299 | * If true, we own the data object and must delete it. |
michael@0 | 300 | */ |
michael@0 | 301 | UBool isDataOwned; |
michael@0 | 302 | |
michael@0 | 303 | public: |
michael@0 | 304 | |
michael@0 | 305 | /** |
michael@0 | 306 | * Constructs a new transliterator from the given rules. |
michael@0 | 307 | * @param rules rules, separated by ';' |
michael@0 | 308 | * @param direction either FORWARD or REVERSE. |
michael@0 | 309 | * @exception IllegalArgumentException if rules are malformed. |
michael@0 | 310 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 311 | */ |
michael@0 | 312 | RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 313 | const UnicodeString& rules, |
michael@0 | 314 | UTransDirection direction, |
michael@0 | 315 | UnicodeFilter* adoptedFilter, |
michael@0 | 316 | UParseError& parseError, |
michael@0 | 317 | UErrorCode& status); |
michael@0 | 318 | |
michael@0 | 319 | /** |
michael@0 | 320 | * Constructs a new transliterator from the given rules. |
michael@0 | 321 | * @param rules rules, separated by ';' |
michael@0 | 322 | * @param direction either FORWARD or REVERSE. |
michael@0 | 323 | * @exception IllegalArgumentException if rules are malformed. |
michael@0 | 324 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 325 | */ |
michael@0 | 326 | /*RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 327 | const UnicodeString& rules, |
michael@0 | 328 | UTransDirection direction, |
michael@0 | 329 | UnicodeFilter* adoptedFilter, |
michael@0 | 330 | UErrorCode& status);*/ |
michael@0 | 331 | |
michael@0 | 332 | /** |
michael@0 | 333 | * Covenience constructor with no filter. |
michael@0 | 334 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 335 | */ |
michael@0 | 336 | /*RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 337 | const UnicodeString& rules, |
michael@0 | 338 | UTransDirection direction, |
michael@0 | 339 | UErrorCode& status);*/ |
michael@0 | 340 | |
michael@0 | 341 | /** |
michael@0 | 342 | * Covenience constructor with no filter and FORWARD direction. |
michael@0 | 343 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 344 | */ |
michael@0 | 345 | /*RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 346 | const UnicodeString& rules, |
michael@0 | 347 | UErrorCode& status);*/ |
michael@0 | 348 | |
michael@0 | 349 | /** |
michael@0 | 350 | * Covenience constructor with FORWARD direction. |
michael@0 | 351 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 352 | */ |
michael@0 | 353 | /*RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 354 | const UnicodeString& rules, |
michael@0 | 355 | UnicodeFilter* adoptedFilter, |
michael@0 | 356 | UErrorCode& status);*/ |
michael@0 | 357 | private: |
michael@0 | 358 | |
michael@0 | 359 | friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor |
michael@0 | 360 | /** |
michael@0 | 361 | * Covenience constructor. |
michael@0 | 362 | * @param id the id for the transliterator. |
michael@0 | 363 | * @param theData the rule data for the transliterator. |
michael@0 | 364 | * @param adoptedFilter the filter for the transliterator |
michael@0 | 365 | */ |
michael@0 | 366 | RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 367 | const TransliterationRuleData* theData, |
michael@0 | 368 | UnicodeFilter* adoptedFilter = 0); |
michael@0 | 369 | |
michael@0 | 370 | |
michael@0 | 371 | friend class Transliterator; // to access following ct |
michael@0 | 372 | |
michael@0 | 373 | /** |
michael@0 | 374 | * Internal constructor. |
michael@0 | 375 | * @param id the id for the transliterator. |
michael@0 | 376 | * @param theData the rule data for the transliterator. |
michael@0 | 377 | * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'. |
michael@0 | 378 | */ |
michael@0 | 379 | RuleBasedTransliterator(const UnicodeString& id, |
michael@0 | 380 | TransliterationRuleData* data, |
michael@0 | 381 | UBool isDataAdopted); |
michael@0 | 382 | |
michael@0 | 383 | public: |
michael@0 | 384 | |
michael@0 | 385 | /** |
michael@0 | 386 | * Copy constructor. |
michael@0 | 387 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 388 | */ |
michael@0 | 389 | RuleBasedTransliterator(const RuleBasedTransliterator&); |
michael@0 | 390 | |
michael@0 | 391 | virtual ~RuleBasedTransliterator(); |
michael@0 | 392 | |
michael@0 | 393 | /** |
michael@0 | 394 | * Implement Transliterator API. |
michael@0 | 395 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 396 | */ |
michael@0 | 397 | virtual Transliterator* clone(void) const; |
michael@0 | 398 | |
michael@0 | 399 | protected: |
michael@0 | 400 | /** |
michael@0 | 401 | * Implements {@link Transliterator#handleTransliterate}. |
michael@0 | 402 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 403 | */ |
michael@0 | 404 | virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets, |
michael@0 | 405 | UBool isIncremental) const; |
michael@0 | 406 | |
michael@0 | 407 | public: |
michael@0 | 408 | /** |
michael@0 | 409 | * Return a representation of this transliterator as source rules. |
michael@0 | 410 | * These rules will produce an equivalent transliterator if used |
michael@0 | 411 | * to construct a new transliterator. |
michael@0 | 412 | * @param result the string to receive the rules. Previous |
michael@0 | 413 | * contents will be deleted. |
michael@0 | 414 | * @param escapeUnprintable if TRUE then convert unprintable |
michael@0 | 415 | * character to their hex escape representations, \uxxxx or |
michael@0 | 416 | * \Uxxxxxxxx. Unprintable characters are those other than |
michael@0 | 417 | * U+000A, U+0020..U+007E. |
michael@0 | 418 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 419 | */ |
michael@0 | 420 | virtual UnicodeString& toRules(UnicodeString& result, |
michael@0 | 421 | UBool escapeUnprintable) const; |
michael@0 | 422 | |
michael@0 | 423 | protected: |
michael@0 | 424 | /** |
michael@0 | 425 | * Implement Transliterator framework |
michael@0 | 426 | */ |
michael@0 | 427 | virtual void handleGetSourceSet(UnicodeSet& result) const; |
michael@0 | 428 | |
michael@0 | 429 | public: |
michael@0 | 430 | /** |
michael@0 | 431 | * Override Transliterator framework |
michael@0 | 432 | */ |
michael@0 | 433 | virtual UnicodeSet& getTargetSet(UnicodeSet& result) const; |
michael@0 | 434 | |
michael@0 | 435 | /** |
michael@0 | 436 | * Return the class ID for this class. This is useful only for |
michael@0 | 437 | * comparing to a return value from getDynamicClassID(). For example: |
michael@0 | 438 | * <pre> |
michael@0 | 439 | * . Base* polymorphic_pointer = createPolymorphicObject(); |
michael@0 | 440 | * . if (polymorphic_pointer->getDynamicClassID() == |
michael@0 | 441 | * . Derived::getStaticClassID()) ... |
michael@0 | 442 | * </pre> |
michael@0 | 443 | * @return The class ID for all objects of this class. |
michael@0 | 444 | * @internal Use transliterator factory methods instead since this class will be removed in that release. |
michael@0 | 445 | */ |
michael@0 | 446 | U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 447 | |
michael@0 | 448 | /** |
michael@0 | 449 | * Returns a unique class ID <b>polymorphically</b>. This method |
michael@0 | 450 | * is to implement a simple version of RTTI, since not all C++ |
michael@0 | 451 | * compilers support genuine RTTI. Polymorphic operator==() and |
michael@0 | 452 | * clone() methods call this method. |
michael@0 | 453 | * |
michael@0 | 454 | * @return The class ID for this object. All objects of a given |
michael@0 | 455 | * class have the same class ID. Objects of other classes have |
michael@0 | 456 | * different class IDs. |
michael@0 | 457 | */ |
michael@0 | 458 | virtual UClassID getDynamicClassID(void) const; |
michael@0 | 459 | |
michael@0 | 460 | private: |
michael@0 | 461 | |
michael@0 | 462 | void _construct(const UnicodeString& rules, |
michael@0 | 463 | UTransDirection direction, |
michael@0 | 464 | UParseError& parseError, |
michael@0 | 465 | UErrorCode& status); |
michael@0 | 466 | }; |
michael@0 | 467 | |
michael@0 | 468 | |
michael@0 | 469 | U_NAMESPACE_END |
michael@0 | 470 | |
michael@0 | 471 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ |
michael@0 | 472 | |
michael@0 | 473 | #endif |