michael@0: /*
michael@0: **********************************************************************
michael@0: * Copyright (c) 2002-2005, International Business Machines Corporation
michael@0: * and others. All Rights Reserved.
michael@0: **********************************************************************
michael@0: * Date Name Description
michael@0: * 01/14/2002 aliu Creation.
michael@0: **********************************************************************
michael@0: */
michael@0: #ifndef UNIREPL_H
michael@0: #define UNIREPL_H
michael@0:
michael@0: #include "unicode/utypes.h"
michael@0:
michael@0: /**
michael@0: * \file
michael@0: * \brief C++ API: UnicodeReplacer
michael@0: */
michael@0:
michael@0: U_NAMESPACE_BEGIN
michael@0:
michael@0: class Replaceable;
michael@0: class UnicodeString;
michael@0: class UnicodeSet;
michael@0:
michael@0: /**
michael@0: * UnicodeReplacer
defines a protocol for objects that
michael@0: * replace a range of characters in a Replaceable string with output
michael@0: * text. The replacement is done via the Replaceable API so as to
michael@0: * preserve out-of-band data.
michael@0: *
michael@0: *
This is a mixin class. michael@0: * @author Alan Liu michael@0: * @stable ICU 2.4 michael@0: */ michael@0: class U_I18N_API UnicodeReplacer /* not : public UObject because this is an interface/mixin class */ { michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual ~UnicodeReplacer(); michael@0: michael@0: /** michael@0: * Replace characters in 'text' from 'start' to 'limit' with the michael@0: * output text of this object. Update the 'cursor' parameter to michael@0: * give the cursor position and return the length of the michael@0: * replacement text. michael@0: * michael@0: * @param text the text to be matched michael@0: * @param start inclusive start index of text to be replaced michael@0: * @param limit exclusive end index of text to be replaced; michael@0: * must be greater than or equal to start michael@0: * @param cursor output parameter for the cursor position. michael@0: * Not all replacer objects will update this, but in a complete michael@0: * tree of replacer objects, representing the entire output side michael@0: * of a transliteration rule, at least one must update it. michael@0: * @return the number of 16-bit code units in the text replacing michael@0: * the characters at offsets start..(limit-1) in text michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t replace(Replaceable& text, michael@0: int32_t start, michael@0: int32_t limit, michael@0: int32_t& cursor) = 0; michael@0: michael@0: /** michael@0: * Returns a string representation of this replacer. If the michael@0: * result of calling this function is passed to the appropriate michael@0: * parser, typically TransliteratorParser, it will produce another michael@0: * replacer that is equal to this one. michael@0: * @param result the string to receive the pattern. Previous michael@0: * contents will be deleted. michael@0: * @param escapeUnprintable if TRUE then convert unprintable michael@0: * character to their hex escape representations, \\uxxxx or michael@0: * \\Uxxxxxxxx. Unprintable characters are defined by michael@0: * Utility.isUnprintable(). michael@0: * @return a reference to 'result'. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UnicodeString& toReplacerPattern(UnicodeString& result, michael@0: UBool escapeUnprintable) const = 0; michael@0: michael@0: /** michael@0: * Union the set of all characters that may output by this object michael@0: * into the given set. michael@0: * @param toUnionTo the set into which to union the output characters michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const = 0; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif