]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/funcrepl.cpp
2 **********************************************************************
3 * Copyright (c) 2002-2011, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 02/04/2002 aliu Creation.
8 **********************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_TRANSLITERATION
15 #include "unicode/translit.h"
16 #include "unicode/uniset.h"
19 static const UChar AMPERSAND
= 38; // '&'
20 static const UChar OPEN
[] = {40,32,0}; // "( "
21 static const UChar CLOSE
[] = {32,41,0}; // " )"
25 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FunctionReplacer
)
28 * Construct a replacer that takes the output of the given
29 * replacer, passes it through the given transliterator, and emits
30 * the result as output.
32 FunctionReplacer::FunctionReplacer(Transliterator
* adoptedTranslit
,
33 UnicodeFunctor
* adoptedReplacer
) {
34 translit
= adoptedTranslit
;
35 replacer
= adoptedReplacer
;
41 FunctionReplacer::FunctionReplacer(const FunctionReplacer
& other
) :
42 UnicodeFunctor(other
),
43 UnicodeReplacer(other
)
45 translit
= other
.translit
->clone();
46 replacer
= other
.replacer
->clone();
52 FunctionReplacer::~FunctionReplacer() {
58 * Implement UnicodeFunctor
60 UnicodeFunctor
* FunctionReplacer::clone() const {
61 return new FunctionReplacer(*this);
65 * UnicodeFunctor API. Cast 'this' to a UnicodeReplacer* pointer
66 * and return the pointer.
68 UnicodeReplacer
* FunctionReplacer::toReplacer() const {
69 return (UnicodeReplacer
*) this;
75 int32_t FunctionReplacer::replace(Replaceable
& text
,
81 // First delegate to subordinate replacer
82 int32_t len
= replacer
->toReplacer()->replace(text
, start
, limit
, cursor
);
86 limit
= translit
->transliterate(text
, start
, limit
);
94 UnicodeString
& FunctionReplacer::toReplacerPattern(UnicodeString
& rule
,
95 UBool escapeUnprintable
) const {
98 rule
.append(AMPERSAND
);
99 rule
.append(translit
->getID());
100 rule
.append(OPEN
, 2);
101 rule
.append(replacer
->toReplacer()->toReplacerPattern(str
, escapeUnprintable
));
102 rule
.append(CLOSE
, 2);
107 * Implement UnicodeReplacer
109 void FunctionReplacer::addReplacementSetTo(UnicodeSet
& toUnionTo
) const {
111 toUnionTo
.addAll(translit
->getTargetSet(set
));
117 void FunctionReplacer::setData(const TransliterationRuleData
* d
) {
118 replacer
->setData(d
);
123 #endif /* #if !UCONFIG_NO_TRANSLITERATION */