funcrepl.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (c) 2002-2011, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. **********************************************************************
  8. * Date Name Description
  9. * 02/04/2002 aliu Creation.
  10. **********************************************************************
  11. */
  12. #ifndef FUNCREPL_H
  13. #define FUNCREPL_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/unifunct.h"
  17. #include "unicode/unirepl.h"
  18. U_NAMESPACE_BEGIN
  19. class Transliterator;
  20. /**
  21. * A replacer that calls a transliterator to generate its output text.
  22. * The input text to the transliterator is the output of another
  23. * UnicodeReplacer object. That is, this replacer wraps another
  24. * replacer with a transliterator.
  25. *
  26. * @author Alan Liu
  27. */
  28. class FunctionReplacer : public UnicodeFunctor, public UnicodeReplacer {
  29. private:
  30. /**
  31. * The transliterator. Must not be null. OWNED.
  32. */
  33. Transliterator* translit;
  34. /**
  35. * The replacer object. This generates text that is then
  36. * processed by 'translit'. Must not be null. OWNED.
  37. */
  38. UnicodeFunctor* replacer;
  39. public:
  40. /**
  41. * Construct a replacer that takes the output of the given
  42. * replacer, passes it through the given transliterator, and emits
  43. * the result as output.
  44. */
  45. FunctionReplacer(Transliterator* adoptedTranslit,
  46. UnicodeFunctor* adoptedReplacer);
  47. /**
  48. * Copy constructor.
  49. */
  50. FunctionReplacer(const FunctionReplacer& other);
  51. /**
  52. * Destructor
  53. */
  54. virtual ~FunctionReplacer();
  55. /**
  56. * Implement UnicodeFunctor
  57. */
  58. virtual FunctionReplacer* clone() const;
  59. /**
  60. * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
  61. * and return the pointer.
  62. */
  63. virtual UnicodeReplacer* toReplacer() const;
  64. /**
  65. * UnicodeReplacer API
  66. */
  67. virtual int32_t replace(Replaceable& text,
  68. int32_t start,
  69. int32_t limit,
  70. int32_t& cursor);
  71. /**
  72. * UnicodeReplacer API
  73. */
  74. virtual UnicodeString& toReplacerPattern(UnicodeString& rule,
  75. UBool escapeUnprintable) const;
  76. /**
  77. * Implement UnicodeReplacer
  78. */
  79. virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
  80. /**
  81. * UnicodeFunctor API
  82. */
  83. virtual void setData(const TransliterationRuleData*);
  84. /**
  85. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  86. */
  87. virtual UClassID getDynamicClassID() const;
  88. /**
  89. * ICU "poor man's RTTI", returns a UClassID for this class.
  90. */
  91. static UClassID U_EXPORT2 getStaticClassID();
  92. };
  93. U_NAMESPACE_END
  94. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  95. #endif
  96. //eof