]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unifltlg.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / i18n / unifltlg.cpp
1 /*
2 **********************************************************************
3 * Copyright (C) 1999-2001, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 11/17/99 aliu Creation.
8 **********************************************************************
9 */
10
11 //////////////////////////////////////////////////////////////
12 //
13 // NOTICE - Do not use
14 //
15 // This entire file has been deprecated as of ICU 2.4.
16 //
17 //////////////////////////////////////////////////////////////
18
19 #include "unicode/utypes.h"
20
21 #if !UCONFIG_NO_TRANSLITERATION
22
23 #include "unicode/unifltlg.h"
24 #include "unicode/unifilt.h"
25
26 U_NAMESPACE_BEGIN
27
28 /**
29 * This class stubs out UnicodeMatcher API that we don't implement.
30 */
31 class _UF: public UnicodeFilter {
32
33 // Stubs
34 virtual UnicodeString& toPattern(UnicodeString& result,
35 UBool escapeUnprintable) const {
36 return result;
37 }
38 virtual UBool matchesIndexValue(uint8_t v) const {
39 return FALSE;
40 }
41 virtual void addMatchSetTo(UnicodeSet& toUnionTo) const {}
42 };
43
44 /**
45 * A NullFilter always returns a fixed value, either TRUE or FALSE.
46 * A filter value of 0 (that is, a UnicodeFilter* f, where f == 0)
47 * is equivalent to a NullFilter(TRUE).
48 */
49 static const char gNullFilterClassID = 0;
50 class NullFilter : public _UF {
51 UBool result;
52 public:
53 virtual UClassID getDynamicClassID() const { return getStaticClassID(); }
54 static inline UClassID getStaticClassID() { return (UClassID)&gNullFilterClassID; }
55 NullFilter(UBool r) { result = r; }
56 NullFilter(const NullFilter& f) : _UF(f) { result = f.result; }
57 virtual ~NullFilter() {}
58 virtual UBool contains(UChar32 /*c*/) const { return result; }
59 virtual UnicodeFunctor* clone() const { return new NullFilter(*this); }
60 };
61
62 static const char gUnicodeNotFilterClassID = 0;
63 class UnicodeNotFilter : public _UF {
64 UnicodeFilter* filt;
65 public:
66 virtual UClassID getDynamicClassID() const { return getStaticClassID(); }
67 static inline UClassID getStaticClassID() { return (UClassID)&gUnicodeNotFilterClassID; }
68 UnicodeNotFilter(UnicodeFilter* adopted);
69 UnicodeNotFilter(const UnicodeNotFilter&);
70 virtual ~UnicodeNotFilter();
71 virtual UBool contains(UChar32 c) const;
72 virtual UnicodeFunctor* clone() const;
73 };
74
75 UnicodeNotFilter::UnicodeNotFilter(UnicodeFilter* adopted) : filt(adopted) {}
76 UnicodeNotFilter::UnicodeNotFilter(const UnicodeNotFilter& f)
77 : _UF(f), filt((UnicodeFilter*) f.filt->clone()) {}
78 UnicodeNotFilter::~UnicodeNotFilter() { delete filt; }
79 UBool UnicodeNotFilter::contains(UChar32 c) const { return !filt->contains(c); }
80 UnicodeFunctor* UnicodeNotFilter::clone() const { return new UnicodeNotFilter(*this); }
81
82 /**
83 * Returns a <tt>UnicodeFilter</tt> that implements the inverse of
84 * the given filter.
85 */
86 UnicodeFilter* UnicodeFilterLogic::createNot(const UnicodeFilter* f) {
87 if (f == 0) {
88 return new NullFilter(FALSE);
89 } else {
90 return new UnicodeNotFilter((UnicodeFilter*)f->clone());
91 }
92 }
93
94 static const char gUnicodeAndFilterClassID = 0;
95 class UnicodeAndFilter : public _UF {
96 UnicodeFilter* filt1;
97 UnicodeFilter* filt2;
98 public:
99 virtual UClassID getDynamicClassID() const { return getStaticClassID(); }
100 static inline UClassID getStaticClassID() { return (UClassID)&gUnicodeAndFilterClassID; }
101 UnicodeAndFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
102 UnicodeAndFilter(const UnicodeAndFilter&);
103 virtual ~UnicodeAndFilter();
104 virtual UBool contains(UChar32 c) const;
105 virtual UnicodeFunctor* clone() const;
106 };
107
108 UnicodeAndFilter::UnicodeAndFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
109 UnicodeAndFilter::UnicodeAndFilter(const UnicodeAndFilter& f)
110 : _UF(f), filt1((UnicodeFilter*)f.filt1->clone()), filt2((UnicodeFilter*)f.filt2->clone()) {}
111 UnicodeAndFilter::~UnicodeAndFilter() { delete filt1; delete filt2; }
112 UBool UnicodeAndFilter::contains(UChar32 c) const { return filt1->contains(c) && filt2->contains(c); }
113 UnicodeFunctor* UnicodeAndFilter::clone() const { return new UnicodeAndFilter(*this); }
114
115 /**
116 * Returns a <tt>UnicodeFilter</tt> that implements a short
117 * circuit AND of the result of the two given filters. That is,
118 * if <tt>f.contains()</tt> is <tt>false</tt>, then <tt>g.contains()</tt>
119 * is not called, and <tt>contains()</tt> returns <tt>false</tt>.
120 */
121 UnicodeFilter* UnicodeFilterLogic::createAnd(const UnicodeFilter* f,
122 const UnicodeFilter* g) {
123 if (f == 0) {
124 if (g == 0) {
125 return NULL;
126 }
127 return (UnicodeFilter*)g->clone();
128 }
129 if (g == 0) {
130 return (UnicodeFilter*)f->clone();
131 }
132 return new UnicodeAndFilter((UnicodeFilter*)f->clone(), (UnicodeFilter*)g->clone());
133 }
134
135 /**
136 * Returns a <tt>UnicodeFilter</tt> that implements a short
137 * circuit AND of the result of the two given filters. That is,
138 * if <tt>f.contains()</tt> is <tt>false</tt>, then <tt>g.contains()</tt>
139 * is not called, and <tt>contains()</tt> returns <tt>false</tt>.
140 *
141 * ADOPTS both arguments.
142 */
143 UnicodeFilter* UnicodeFilterLogic::createAdoptingAnd(UnicodeFilter* f,
144 UnicodeFilter* g) {
145 if (f == 0) {
146 if (g == 0) {
147 return NULL;
148 }
149 return g;
150 }
151 if (g == 0) {
152 return f;
153 }
154 return new UnicodeAndFilter(f, g);
155 }
156
157 static const char gUnicodeOrFilterClassID = 0;
158 class UnicodeOrFilter : public _UF {
159 UnicodeFilter* filt1;
160 UnicodeFilter* filt2;
161 public:
162 virtual UClassID getDynamicClassID() const { return getStaticClassID(); }
163 static inline UClassID getStaticClassID() { return (UClassID)&gUnicodeOrFilterClassID; }
164 UnicodeOrFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
165 UnicodeOrFilter(const UnicodeOrFilter&);
166 virtual ~UnicodeOrFilter();
167 virtual UBool contains(UChar32 c) const;
168 virtual UnicodeFunctor* clone() const;
169 };
170
171 UnicodeOrFilter::UnicodeOrFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
172 UnicodeOrFilter::UnicodeOrFilter(const UnicodeOrFilter& f)
173 : _UF(f), filt1((UnicodeFilter*)f.filt1->clone()), filt2((UnicodeFilter*)f.filt2->clone()) {}
174 UnicodeOrFilter::~UnicodeOrFilter() { delete filt1; delete filt2; }
175 UBool UnicodeOrFilter::contains(UChar32 c) const { return filt1->contains(c) || filt2->contains(c); }
176 UnicodeFunctor* UnicodeOrFilter::clone() const { return new UnicodeOrFilter(*this); }
177
178 /**
179 * Returns a <tt>UnicodeFilter</tt> that implements a short
180 * circuit OR of the result of the two given filters. That is, if
181 * <tt>f.contains()</tt> is <tt>true</tt>, then <tt>g.contains()</tt> is
182 * not called, and <tt>contains()</tt> returns <tt>true</tt>.
183 */
184 UnicodeFilter* UnicodeFilterLogic::createOr(const UnicodeFilter* f,
185 const UnicodeFilter* g) {
186 if (f == 0) {
187 if (g == 0) {
188 return NULL;
189 }
190 return (UnicodeFilter*)g->clone();
191 }
192 if (g == 0) {
193 return (UnicodeFilter*)f->clone();
194 }
195 return new UnicodeOrFilter((UnicodeFilter*)f->clone(), (UnicodeFilter*)g->clone());
196 }
197
198 U_NAMESPACE_END
199
200 #endif /* #if !UCONFIG_NO_TRANSLITERATION */