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