unirepl.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-2005, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. **********************************************************************
  8. * Date Name Description
  9. * 01/14/2002 aliu Creation.
  10. **********************************************************************
  11. */
  12. #ifndef UNIREPL_H
  13. #define UNIREPL_H
  14. #include "unicode/utypes.h"
  15. #if U_SHOW_CPLUSPLUS_API
  16. /**
  17. * \file
  18. * \brief C++ API: UnicodeReplacer
  19. */
  20. U_NAMESPACE_BEGIN
  21. class Replaceable;
  22. class UnicodeString;
  23. class UnicodeSet;
  24. /**
  25. * <code>UnicodeReplacer</code> defines a protocol for objects that
  26. * replace a range of characters in a Replaceable string with output
  27. * text. The replacement is done via the Replaceable API so as to
  28. * preserve out-of-band data.
  29. *
  30. * <p>This is a mixin class.
  31. * @author Alan Liu
  32. * @stable ICU 2.4
  33. */
  34. class U_I18N_API UnicodeReplacer /* not : public UObject because this is an interface/mixin class */ {
  35. public:
  36. /**
  37. * Destructor.
  38. * @stable ICU 2.4
  39. */
  40. virtual ~UnicodeReplacer();
  41. /**
  42. * Replace characters in 'text' from 'start' to 'limit' with the
  43. * output text of this object. Update the 'cursor' parameter to
  44. * give the cursor position and return the length of the
  45. * replacement text.
  46. *
  47. * @param text the text to be matched
  48. * @param start inclusive start index of text to be replaced
  49. * @param limit exclusive end index of text to be replaced;
  50. * must be greater than or equal to start
  51. * @param cursor output parameter for the cursor position.
  52. * Not all replacer objects will update this, but in a complete
  53. * tree of replacer objects, representing the entire output side
  54. * of a transliteration rule, at least one must update it.
  55. * @return the number of 16-bit code units in the text replacing
  56. * the characters at offsets start..(limit-1) in text
  57. * @stable ICU 2.4
  58. */
  59. virtual int32_t replace(Replaceable& text,
  60. int32_t start,
  61. int32_t limit,
  62. int32_t& cursor) = 0;
  63. /**
  64. * Returns a string representation of this replacer. If the
  65. * result of calling this function is passed to the appropriate
  66. * parser, typically TransliteratorParser, it will produce another
  67. * replacer that is equal to this one.
  68. * @param result the string to receive the pattern. Previous
  69. * contents will be deleted.
  70. * @param escapeUnprintable if true then convert unprintable
  71. * character to their hex escape representations, \\uxxxx or
  72. * \\Uxxxxxxxx. Unprintable characters are defined by
  73. * Utility.isUnprintable().
  74. * @return a reference to 'result'.
  75. * @stable ICU 2.4
  76. */
  77. virtual UnicodeString& toReplacerPattern(UnicodeString& result,
  78. UBool escapeUnprintable) const = 0;
  79. /**
  80. * Union the set of all characters that may output by this object
  81. * into the given set.
  82. * @param toUnionTo the set into which to union the output characters
  83. * @stable ICU 2.4
  84. */
  85. virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const = 0;
  86. };
  87. U_NAMESPACE_END
  88. #endif /* U_SHOW_CPLUSPLUS_API */
  89. #endif