rbt.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1999-2007, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * Date Name Description
  9. * 11/17/99 aliu Creation.
  10. **********************************************************************
  11. */
  12. #ifndef RBT_H
  13. #define RBT_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/translit.h"
  17. #include "unicode/utypes.h"
  18. #include "unicode/parseerr.h"
  19. #include "unicode/udata.h"
  20. #define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit"
  21. U_NAMESPACE_BEGIN
  22. class TransliterationRuleData;
  23. /**
  24. * <code>RuleBasedTransliterator</code> is a transliterator
  25. * built from a set of rules as defined for
  26. * Transliterator::createFromRules().
  27. * See the C++ class Transliterator documentation for the rule syntax.
  28. *
  29. * @author Alan Liu
  30. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  31. */
  32. class RuleBasedTransliterator : public Transliterator {
  33. private:
  34. /**
  35. * The data object is immutable, so we can freely share it with
  36. * other instances of RBT, as long as we do NOT own this object.
  37. * TODO: data is no longer immutable. See bugs #1866, 2155
  38. */
  39. TransliterationRuleData* fData;
  40. /**
  41. * If true, we own the data object and must delete it.
  42. */
  43. UBool isDataOwned;
  44. public:
  45. /**
  46. * Constructs a new transliterator from the given rules.
  47. * @param rules rules, separated by ';'
  48. * @param direction either FORWARD or REVERSE.
  49. * @exception IllegalArgumentException if rules are malformed.
  50. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  51. */
  52. RuleBasedTransliterator(const UnicodeString& id,
  53. const UnicodeString& rules,
  54. UTransDirection direction,
  55. UnicodeFilter* adoptedFilter,
  56. UParseError& parseError,
  57. UErrorCode& status);
  58. /**
  59. * Constructs a new transliterator from the given rules.
  60. * @param rules rules, separated by ';'
  61. * @param direction either FORWARD or REVERSE.
  62. * @exception IllegalArgumentException if rules are malformed.
  63. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  64. */
  65. /*RuleBasedTransliterator(const UnicodeString& id,
  66. const UnicodeString& rules,
  67. UTransDirection direction,
  68. UnicodeFilter* adoptedFilter,
  69. UErrorCode& status);*/
  70. /**
  71. * Convenience constructor with no filter.
  72. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  73. */
  74. /*RuleBasedTransliterator(const UnicodeString& id,
  75. const UnicodeString& rules,
  76. UTransDirection direction,
  77. UErrorCode& status);*/
  78. /**
  79. * Convenience constructor with no filter and FORWARD direction.
  80. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  81. */
  82. /*RuleBasedTransliterator(const UnicodeString& id,
  83. const UnicodeString& rules,
  84. UErrorCode& status);*/
  85. /**
  86. * Convenience constructor with FORWARD direction.
  87. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  88. */
  89. /*RuleBasedTransliterator(const UnicodeString& id,
  90. const UnicodeString& rules,
  91. UnicodeFilter* adoptedFilter,
  92. UErrorCode& status);*/
  93. private:
  94. friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor
  95. /**
  96. * Convenience constructor.
  97. * @param id the id for the transliterator.
  98. * @param theData the rule data for the transliterator.
  99. * @param adoptedFilter the filter for the transliterator
  100. */
  101. RuleBasedTransliterator(const UnicodeString& id,
  102. const TransliterationRuleData* theData,
  103. UnicodeFilter* adoptedFilter = 0);
  104. friend class Transliterator; // to access following ct
  105. /**
  106. * Internal constructor.
  107. * @param id the id for the transliterator.
  108. * @param theData the rule data for the transliterator.
  109. * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'.
  110. */
  111. RuleBasedTransliterator(const UnicodeString& id,
  112. TransliterationRuleData* data,
  113. UBool isDataAdopted);
  114. public:
  115. /**
  116. * Copy constructor.
  117. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  118. */
  119. RuleBasedTransliterator(const RuleBasedTransliterator&);
  120. virtual ~RuleBasedTransliterator();
  121. /**
  122. * Implement Transliterator API.
  123. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  124. */
  125. virtual RuleBasedTransliterator* clone() const override;
  126. protected:
  127. /**
  128. * Implements {@link Transliterator#handleTransliterate}.
  129. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  130. */
  131. virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
  132. UBool isIncremental) const override;
  133. public:
  134. /**
  135. * Return a representation of this transliterator as source rules.
  136. * These rules will produce an equivalent transliterator if used
  137. * to construct a new transliterator.
  138. * @param result the string to receive the rules. Previous
  139. * contents will be deleted.
  140. * @param escapeUnprintable if true then convert unprintable
  141. * character to their hex escape representations, \uxxxx or
  142. * \Uxxxxxxxx. Unprintable characters are those other than
  143. * U+000A, U+0020..U+007E.
  144. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  145. */
  146. virtual UnicodeString& toRules(UnicodeString& result,
  147. UBool escapeUnprintable) const override;
  148. protected:
  149. /**
  150. * Implement Transliterator framework
  151. */
  152. virtual void handleGetSourceSet(UnicodeSet& result) const override;
  153. public:
  154. /**
  155. * Override Transliterator framework
  156. */
  157. virtual UnicodeSet& getTargetSet(UnicodeSet& result) const override;
  158. /**
  159. * Return the class ID for this class. This is useful only for
  160. * comparing to a return value from getDynamicClassID(). For example:
  161. * <pre>
  162. * . Base* polymorphic_pointer = createPolymorphicObject();
  163. * . if (polymorphic_pointer->getDynamicClassID() ==
  164. * . Derived::getStaticClassID()) ...
  165. * </pre>
  166. * @return The class ID for all objects of this class.
  167. * @internal Use transliterator factory methods instead since this class will be removed in that release.
  168. */
  169. U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
  170. /**
  171. * Returns a unique class ID <b>polymorphically</b>. This method
  172. * is to implement a simple version of RTTI, since not all C++
  173. * compilers support genuine RTTI. Polymorphic operator==() and
  174. * clone() methods call this method.
  175. *
  176. * @return The class ID for this object. All objects of a given
  177. * class have the same class ID. Objects of other classes have
  178. * different class IDs.
  179. */
  180. virtual UClassID getDynamicClassID() const override;
  181. private:
  182. void _construct(const UnicodeString& rules,
  183. UTransDirection direction,
  184. UParseError& parseError,
  185. UErrorCode& status);
  186. };
  187. U_NAMESPACE_END
  188. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  189. #endif