1999-11-20 00:40:50 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
* Copyright (C) 1999-2001, International Business Machines
|
1999-11-20 00:40:50 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 11/17/99 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unifltlg.h"
|
|
|
|
#include "unicode/unifilt.h"
|
1999-11-20 00:40:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2000-02-05 00:24:24 +00:00
|
|
|
/**
|
|
|
|
* A NullFilter always returns a fixed value, either TRUE or FALSE.
|
|
|
|
* A filter value of 0 (that is, a UnicodeFilter* f, where f == 0)
|
|
|
|
* is equivalent to a NullFilter(TRUE).
|
|
|
|
*/
|
|
|
|
class NullFilter : public UnicodeFilter {
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool result;
|
2000-02-05 00:24:24 +00:00
|
|
|
public:
|
2000-05-18 22:08:39 +00:00
|
|
|
NullFilter(UBool r) { result = r; }
|
2001-03-06 20:12:26 +00:00
|
|
|
NullFilter(const NullFilter& f) : UnicodeFilter(f) { result = f.result; }
|
2000-02-05 00:24:24 +00:00
|
|
|
virtual ~NullFilter() {}
|
2001-07-25 19:11:02 +00:00
|
|
|
virtual UBool contains(UChar32 /*c*/) const { return result; }
|
2001-07-27 00:18:53 +00:00
|
|
|
virtual UnicodeMatcher* clone() const { return new NullFilter(*this); }
|
2000-02-05 00:24:24 +00:00
|
|
|
};
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
class UnicodeNotFilter : public UnicodeFilter {
|
|
|
|
UnicodeFilter* filt;
|
|
|
|
public:
|
|
|
|
UnicodeNotFilter(UnicodeFilter* adopted);
|
|
|
|
UnicodeNotFilter(const UnicodeNotFilter&);
|
|
|
|
virtual ~UnicodeNotFilter();
|
2001-07-25 19:11:02 +00:00
|
|
|
virtual UBool contains(UChar32 c) const;
|
2001-07-27 00:18:53 +00:00
|
|
|
virtual UnicodeMatcher* clone() const;
|
1999-11-20 00:40:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeNotFilter::UnicodeNotFilter(UnicodeFilter* adopted) : filt(adopted) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeNotFilter::UnicodeNotFilter(const UnicodeNotFilter& f)
|
2001-07-27 00:18:53 +00:00
|
|
|
: UnicodeFilter(f), filt((UnicodeFilter*) f.filt->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeNotFilter::~UnicodeNotFilter() { delete filt; }
|
2001-07-25 19:11:02 +00:00
|
|
|
UBool UnicodeNotFilter::contains(UChar32 c) const { return !filt->contains(c); }
|
2001-07-27 00:18:53 +00:00
|
|
|
UnicodeMatcher* UnicodeNotFilter::clone() const { return new UnicodeNotFilter(*this); }
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a <tt>UnicodeFilter</tt> that implements the inverse of
|
|
|
|
* the given filter.
|
|
|
|
*/
|
2000-02-05 00:24:24 +00:00
|
|
|
UnicodeFilter* UnicodeFilterLogic::createNot(const UnicodeFilter* f) {
|
|
|
|
if (f == 0) {
|
|
|
|
return new NullFilter(FALSE);
|
|
|
|
} else {
|
2001-07-27 00:18:53 +00:00
|
|
|
return new UnicodeNotFilter((UnicodeFilter*)f->clone());
|
2000-02-05 00:24:24 +00:00
|
|
|
}
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class UnicodeAndFilter : public UnicodeFilter {
|
|
|
|
UnicodeFilter* filt1;
|
|
|
|
UnicodeFilter* filt2;
|
|
|
|
public:
|
|
|
|
UnicodeAndFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
|
|
|
|
UnicodeAndFilter(const UnicodeAndFilter&);
|
|
|
|
virtual ~UnicodeAndFilter();
|
2001-07-25 19:11:02 +00:00
|
|
|
virtual UBool contains(UChar32 c) const;
|
2001-07-27 00:18:53 +00:00
|
|
|
virtual UnicodeMatcher* clone() const;
|
1999-11-20 00:40:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeAndFilter::UnicodeAndFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeAndFilter::UnicodeAndFilter(const UnicodeAndFilter& f)
|
2001-07-27 00:18:53 +00:00
|
|
|
: UnicodeFilter(f), filt1((UnicodeFilter*)f.filt1->clone()), filt2((UnicodeFilter*)f.filt2->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeAndFilter::~UnicodeAndFilter() { delete filt1; delete filt2; }
|
2001-07-25 19:11:02 +00:00
|
|
|
UBool UnicodeAndFilter::contains(UChar32 c) const { return filt1->contains(c) && filt2->contains(c); }
|
2001-07-27 00:18:53 +00:00
|
|
|
UnicodeMatcher* UnicodeAndFilter::clone() const { return new UnicodeAndFilter(*this); }
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a <tt>UnicodeFilter</tt> that implements a short
|
|
|
|
* circuit AND of the result of the two given filters. That is,
|
2000-01-18 20:00:56 +00:00
|
|
|
* if <tt>f.contains()</tt> is <tt>false</tt>, then <tt>g.contains()</tt>
|
|
|
|
* is not called, and <tt>contains()</tt> returns <tt>false</tt>.
|
1999-11-20 00:40:50 +00:00
|
|
|
*/
|
2000-02-05 00:24:24 +00:00
|
|
|
UnicodeFilter* UnicodeFilterLogic::createAnd(const UnicodeFilter* f,
|
|
|
|
const UnicodeFilter* g) {
|
|
|
|
if (f == 0) {
|
|
|
|
if (g == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
return (UnicodeFilter*)g->clone();
|
2000-02-05 00:24:24 +00:00
|
|
|
}
|
|
|
|
if (g == 0) {
|
2001-07-27 00:18:53 +00:00
|
|
|
return (UnicodeFilter*)f->clone();
|
2000-02-05 00:24:24 +00:00
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
return new UnicodeAndFilter((UnicodeFilter*)f->clone(), (UnicodeFilter*)g->clone());
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2001-10-24 13:34:11 +00:00
|
|
|
/**
|
|
|
|
* Returns a <tt>UnicodeFilter</tt> that implements a short
|
|
|
|
* circuit AND of the result of the two given filters. That is,
|
|
|
|
* if <tt>f.contains()</tt> is <tt>false</tt>, then <tt>g.contains()</tt>
|
|
|
|
* is not called, and <tt>contains()</tt> returns <tt>false</tt>.
|
|
|
|
*
|
|
|
|
* ADOPTS both arguments.
|
|
|
|
*/
|
|
|
|
UnicodeFilter* UnicodeFilterLogic::createAdoptingAnd(UnicodeFilter* f,
|
|
|
|
UnicodeFilter* g) {
|
|
|
|
if (f == 0) {
|
|
|
|
if (g == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
if (g == 0) {
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
return new UnicodeAndFilter(f, g);
|
|
|
|
}
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
class UnicodeOrFilter : public UnicodeFilter {
|
|
|
|
UnicodeFilter* filt1;
|
|
|
|
UnicodeFilter* filt2;
|
|
|
|
public:
|
|
|
|
UnicodeOrFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
|
|
|
|
UnicodeOrFilter(const UnicodeOrFilter&);
|
|
|
|
virtual ~UnicodeOrFilter();
|
2001-07-25 19:11:02 +00:00
|
|
|
virtual UBool contains(UChar32 c) const;
|
2001-07-27 00:18:53 +00:00
|
|
|
virtual UnicodeMatcher* clone() const;
|
1999-11-20 00:40:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeOrFilter::UnicodeOrFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeOrFilter::UnicodeOrFilter(const UnicodeOrFilter& f)
|
2001-07-27 00:18:53 +00:00
|
|
|
: UnicodeFilter(f), filt1((UnicodeFilter*)f.filt1->clone()), filt2((UnicodeFilter*)f.filt2->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeOrFilter::~UnicodeOrFilter() { delete filt1; delete filt2; }
|
2001-07-25 19:11:02 +00:00
|
|
|
UBool UnicodeOrFilter::contains(UChar32 c) const { return filt1->contains(c) || filt2->contains(c); }
|
2001-07-27 00:18:53 +00:00
|
|
|
UnicodeMatcher* UnicodeOrFilter::clone() const { return new UnicodeOrFilter(*this); }
|
1999-11-20 00:40:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a <tt>UnicodeFilter</tt> that implements a short
|
|
|
|
* circuit OR of the result of the two given filters. That is, if
|
2000-01-18 20:00:56 +00:00
|
|
|
* <tt>f.contains()</tt> is <tt>true</tt>, then <tt>g.contains()</tt> is
|
|
|
|
* not called, and <tt>contains()</tt> returns <tt>true</tt>.
|
1999-11-20 00:40:50 +00:00
|
|
|
*/
|
2000-02-05 00:24:24 +00:00
|
|
|
UnicodeFilter* UnicodeFilterLogic::createOr(const UnicodeFilter* f,
|
|
|
|
const UnicodeFilter* g) {
|
|
|
|
if (f == 0) {
|
|
|
|
if (g == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
return (UnicodeFilter*)g->clone();
|
2000-02-05 00:24:24 +00:00
|
|
|
}
|
|
|
|
if (g == 0) {
|
2001-07-27 00:18:53 +00:00
|
|
|
return (UnicodeFilter*)f->clone();
|
2000-02-05 00:24:24 +00:00
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
return new UnicodeOrFilter((UnicodeFilter*)f->clone(), (UnicodeFilter*)g->clone());
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|