unirepl.h 3.3 KB

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