jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (c) 2002-2005, International Business Machines Corporation jpayne@69: * and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * Date Name Description jpayne@69: * 01/14/2002 aliu Creation. jpayne@69: ********************************************************************** jpayne@69: */ jpayne@69: #ifndef UNIREPL_H jpayne@69: #define UNIREPL_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: UnicodeReplacer jpayne@69: */ jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class Replaceable; jpayne@69: class UnicodeString; jpayne@69: class UnicodeSet; jpayne@69: jpayne@69: /** jpayne@69: * UnicodeReplacer defines a protocol for objects that jpayne@69: * replace a range of characters in a Replaceable string with output jpayne@69: * text. The replacement is done via the Replaceable API so as to jpayne@69: * preserve out-of-band data. jpayne@69: * jpayne@69: *

This is a mixin class. jpayne@69: * @author Alan Liu jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: class U_I18N_API UnicodeReplacer /* not : public UObject because this is an interface/mixin class */ { jpayne@69: jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual ~UnicodeReplacer(); jpayne@69: jpayne@69: /** jpayne@69: * Replace characters in 'text' from 'start' to 'limit' with the jpayne@69: * output text of this object. Update the 'cursor' parameter to jpayne@69: * give the cursor position and return the length of the jpayne@69: * replacement text. jpayne@69: * jpayne@69: * @param text the text to be matched jpayne@69: * @param start inclusive start index of text to be replaced jpayne@69: * @param limit exclusive end index of text to be replaced; jpayne@69: * must be greater than or equal to start jpayne@69: * @param cursor output parameter for the cursor position. jpayne@69: * Not all replacer objects will update this, but in a complete jpayne@69: * tree of replacer objects, representing the entire output side jpayne@69: * of a transliteration rule, at least one must update it. jpayne@69: * @return the number of 16-bit code units in the text replacing jpayne@69: * the characters at offsets start..(limit-1) in text jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual int32_t replace(Replaceable& text, jpayne@69: int32_t start, jpayne@69: int32_t limit, jpayne@69: int32_t& cursor) = 0; jpayne@69: jpayne@69: /** jpayne@69: * Returns a string representation of this replacer. If the jpayne@69: * result of calling this function is passed to the appropriate jpayne@69: * parser, typically TransliteratorParser, it will produce another jpayne@69: * replacer that is equal to this one. jpayne@69: * @param result the string to receive the pattern. Previous jpayne@69: * contents will be deleted. jpayne@69: * @param escapeUnprintable if TRUE then convert unprintable jpayne@69: * character to their hex escape representations, \\uxxxx or jpayne@69: * \\Uxxxxxxxx. Unprintable characters are defined by jpayne@69: * Utility.isUnprintable(). jpayne@69: * @return a reference to 'result'. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual UnicodeString& toReplacerPattern(UnicodeString& result, jpayne@69: UBool escapeUnprintable) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Union the set of all characters that may output by this object jpayne@69: * into the given set. jpayne@69: * @param toUnionTo the set into which to union the output characters jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const = 0; jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif