cpdtrans.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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-2011, 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 CPDTRANS_H
  13. #define CPDTRANS_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/translit.h"
  17. U_NAMESPACE_BEGIN
  18. class U_COMMON_API UVector;
  19. class TransliteratorRegistry;
  20. /**
  21. * A transliterator that is composed of two or more other
  22. * transliterator objects linked together. For example, if one
  23. * transliterator transliterates from script A to script B, and
  24. * another transliterates from script B to script C, the two may be
  25. * combined to form a new transliterator from A to C.
  26. *
  27. * <p>Composed transliterators may not behave as expected. For
  28. * example, inverses may not combine to form the identity
  29. * transliterator. See the class documentation for {@link
  30. * Transliterator} for details.
  31. *
  32. * @author Alan Liu
  33. */
  34. class U_I18N_API CompoundTransliterator : public Transliterator {
  35. Transliterator** trans;
  36. int32_t count;
  37. int32_t numAnonymousRBTs;
  38. public:
  39. /**
  40. * Constructs a new compound transliterator given an array of
  41. * transliterators. The array of transliterators may be of any
  42. * length, including zero or one, however, useful compound
  43. * transliterators have at least two components.
  44. * @param transliterators array of <code>Transliterator</code>
  45. * objects
  46. * @param transliteratorCount The number of
  47. * <code>Transliterator</code> objects in transliterators.
  48. * @param adoptedFilter the filter. Any character for which
  49. * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
  50. * altered by this transliterator. If <tt>filter</tt> is
  51. * <tt>null</tt> then no filtering is applied.
  52. */
  53. CompoundTransliterator(Transliterator* const transliterators[],
  54. int32_t transliteratorCount,
  55. UnicodeFilter* adoptedFilter = 0);
  56. /**
  57. * Constructs a new compound transliterator.
  58. * @param id compound ID
  59. * @param dir either UTRANS_FORWARD or UTRANS_REVERSE
  60. * @param adoptedFilter a global filter for this compound transliterator
  61. * or NULL
  62. */
  63. CompoundTransliterator(const UnicodeString& id,
  64. UTransDirection dir,
  65. UnicodeFilter* adoptedFilter,
  66. UParseError& parseError,
  67. UErrorCode& status);
  68. /**
  69. * Constructs a new compound transliterator in the FORWARD
  70. * direction with a NULL filter.
  71. */
  72. CompoundTransliterator(const UnicodeString& id,
  73. UParseError& parseError,
  74. UErrorCode& status);
  75. /**
  76. * Destructor.
  77. */
  78. virtual ~CompoundTransliterator();
  79. /**
  80. * Copy constructor.
  81. */
  82. CompoundTransliterator(const CompoundTransliterator&);
  83. /**
  84. * Transliterator API.
  85. */
  86. virtual CompoundTransliterator* clone() const;
  87. /**
  88. * Returns the number of transliterators in this chain.
  89. * @return number of transliterators in this chain.
  90. */
  91. virtual int32_t getCount(void) const;
  92. /**
  93. * Returns the transliterator at the given index in this chain.
  94. * @param idx index into chain, from 0 to <code>getCount() - 1</code>
  95. * @return transliterator at the given index
  96. */
  97. virtual const Transliterator& getTransliterator(int32_t idx) const;
  98. /**
  99. * Sets the transliterators.
  100. */
  101. void setTransliterators(Transliterator* const transliterators[],
  102. int32_t count);
  103. /**
  104. * Adopts the transliterators.
  105. */
  106. void adoptTransliterators(Transliterator* adoptedTransliterators[],
  107. int32_t count);
  108. /**
  109. * Override Transliterator:
  110. * Create a rule string that can be passed to createFromRules()
  111. * to recreate this transliterator.
  112. * @param result the string to receive the rules. Previous
  113. * contents will be deleted.
  114. * @param escapeUnprintable if TRUE then convert unprintable
  115. * character to their hex escape representations, \uxxxx or
  116. * \Uxxxxxxxx. Unprintable characters are those other than
  117. * U+000A, U+0020..U+007E.
  118. */
  119. virtual UnicodeString& toRules(UnicodeString& result,
  120. UBool escapeUnprintable) const;
  121. protected:
  122. /**
  123. * Implement Transliterator framework
  124. */
  125. virtual void handleGetSourceSet(UnicodeSet& result) const;
  126. public:
  127. /**
  128. * Override Transliterator framework
  129. */
  130. virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
  131. protected:
  132. /**
  133. * Implements {@link Transliterator#handleTransliterate}.
  134. */
  135. virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
  136. UBool incremental) const;
  137. public:
  138. /**
  139. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  140. */
  141. virtual UClassID getDynamicClassID() const;
  142. /**
  143. * ICU "poor man's RTTI", returns a UClassID for this class.
  144. */
  145. static UClassID U_EXPORT2 getStaticClassID();
  146. /* @internal */
  147. static const UChar PASS_STRING[];
  148. private:
  149. friend class Transliterator;
  150. friend class TransliteratorAlias; // to access private ct
  151. /**
  152. * Assignment operator.
  153. */
  154. CompoundTransliterator& operator=(const CompoundTransliterator&);
  155. /**
  156. * Private constructor for Transliterator.
  157. */
  158. CompoundTransliterator(const UnicodeString& ID,
  159. UVector& list,
  160. UnicodeFilter* adoptedFilter,
  161. int32_t numAnonymousRBTs,
  162. UParseError& parseError,
  163. UErrorCode& status);
  164. CompoundTransliterator(UVector& list,
  165. UParseError& parseError,
  166. UErrorCode& status);
  167. CompoundTransliterator(UVector& list,
  168. int32_t anonymousRBTs,
  169. UParseError& parseError,
  170. UErrorCode& status);
  171. void init(const UnicodeString& id,
  172. UTransDirection direction,
  173. UBool fixReverseID,
  174. UErrorCode& status);
  175. void init(UVector& list,
  176. UTransDirection direction,
  177. UBool fixReverseID,
  178. UErrorCode& status);
  179. /**
  180. * Return the IDs of the given list of transliterators, concatenated
  181. * with ';' delimiting them. Equivalent to the perlish expression
  182. * join(';', map($_.getID(), transliterators).
  183. */
  184. UnicodeString joinIDs(Transliterator* const transliterators[],
  185. int32_t transCount);
  186. void freeTransliterators(void);
  187. void computeMaximumContextLength(void);
  188. };
  189. U_NAMESPACE_END
  190. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  191. #endif