2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2002-02-07 01:07:55 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (c) 2002-2011, International Business Machines Corporation
|
|
|
|
* and others. All Rights Reserved.
|
2002-02-07 01:07:55 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 01/21/2002 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STRREPL_H
|
|
|
|
#define STRREPL_H
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
#include "unicode/unifunct.h"
|
|
|
|
#include "unicode/unirepl.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class TransliterationRuleData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A replacer that produces static text as its output. The text may
|
|
|
|
* contain transliterator stand-in characters that represent nested
|
|
|
|
* UnicodeReplacer objects, making it possible to encode a tree of
|
|
|
|
* replacers in a StringReplacer. A StringReplacer that contains such
|
|
|
|
* stand-ins is called a <em>complex</em> StringReplacer. A complex
|
|
|
|
* StringReplacer has a slower processing loop than a non-complex one.
|
|
|
|
* @author Alan Liu
|
|
|
|
*/
|
|
|
|
class StringReplacer : public UnicodeFunctor, public UnicodeReplacer {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output text, possibly containing stand-in characters that
|
|
|
|
* represent nested UnicodeReplacers.
|
|
|
|
*/
|
|
|
|
UnicodeString output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cursor position. Value is ignored if hasCursor is false.
|
|
|
|
*/
|
|
|
|
int32_t cursorPos;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if this object outputs a cursor position.
|
|
|
|
*/
|
|
|
|
UBool hasCursor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A complex object contains nested replacers and requires more
|
|
|
|
* complex processing. StringReplacers are initially assumed to
|
|
|
|
* be complex. If no nested replacers are seen during processing,
|
|
|
|
* then isComplex is set to false, and future replacements are
|
|
|
|
* short circuited for better performance.
|
|
|
|
*/
|
|
|
|
UBool isComplex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object that translates stand-in characters in 'output' to
|
|
|
|
* UnicodeReplacer objects.
|
|
|
|
*/
|
|
|
|
const TransliterationRuleData* data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a StringReplacer that sets the emits the given output
|
|
|
|
* text and sets the cursor to the given position.
|
|
|
|
* @param theOutput text that will replace input text when the
|
|
|
|
* replace() method is called. May contain stand-in characters
|
|
|
|
* that represent nested replacers.
|
|
|
|
* @param theCursorPos cursor position that will be returned by
|
|
|
|
* the replace() method
|
|
|
|
* @param theData transliterator context object that translates
|
|
|
|
* stand-in characters to UnicodeReplacer objects
|
|
|
|
*/
|
|
|
|
StringReplacer(const UnicodeString& theOutput,
|
|
|
|
int32_t theCursorPos,
|
|
|
|
const TransliterationRuleData* theData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a StringReplacer that sets the emits the given output
|
|
|
|
* text and does not modify the cursor.
|
|
|
|
* @param theOutput text that will replace input text when the
|
|
|
|
* replace() method is called. May contain stand-in characters
|
|
|
|
* that represent nested replacers.
|
|
|
|
* @param theData transliterator context object that translates
|
|
|
|
* stand-in characters to UnicodeReplacer objects
|
|
|
|
*/
|
|
|
|
StringReplacer(const UnicodeString& theOutput,
|
|
|
|
const TransliterationRuleData* theData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
StringReplacer(const StringReplacer& other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
virtual ~StringReplacer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement UnicodeFunctor
|
|
|
|
*/
|
2019-08-22 00:13:18 +00:00
|
|
|
virtual StringReplacer* clone() const;
|
2002-02-07 01:07:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
|
|
|
|
* and return the pointer.
|
|
|
|
*/
|
|
|
|
virtual UnicodeReplacer* toReplacer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UnicodeReplacer API
|
|
|
|
*/
|
|
|
|
virtual int32_t replace(Replaceable& text,
|
|
|
|
int32_t start,
|
|
|
|
int32_t limit,
|
|
|
|
int32_t& cursor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UnicodeReplacer API
|
|
|
|
*/
|
|
|
|
virtual UnicodeString& toReplacerPattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable) const;
|
2002-03-20 00:42:02 +00:00
|
|
|
|
2002-06-28 21:13:54 +00:00
|
|
|
/**
|
|
|
|
* Implement UnicodeReplacer
|
|
|
|
*/
|
|
|
|
virtual void addReplacementSetTo(UnicodeSet& toUnionTo) const;
|
|
|
|
|
2002-03-20 00:42:02 +00:00
|
|
|
/**
|
|
|
|
* UnicodeFunctor API
|
|
|
|
*/
|
|
|
|
virtual void setData(const TransliterationRuleData*);
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
2003-08-29 20:11:40 +00:00
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2004-08-24 17:38:33 +00:00
|
|
|
static UClassID U_EXPORT2 getStaticClassID();
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
2003-08-29 20:11:40 +00:00
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
2002-06-29 00:04:16 +00:00
|
|
|
*/
|
2003-08-29 20:11:40 +00:00
|
|
|
virtual UClassID getDynamicClassID() const;
|
2002-02-07 01:07:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//eof
|