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
|
|
|
|
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() {}
|
2000-08-15 18:25:20 +00:00
|
|
|
virtual UBool contains(UChar /*c*/) const { return result; }
|
2000-02-05 00:24:24 +00:00
|
|
|
virtual UnicodeFilter* clone() const { return new NullFilter(*this); }
|
|
|
|
};
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
class UnicodeNotFilter : public UnicodeFilter {
|
|
|
|
UnicodeFilter* filt;
|
|
|
|
public:
|
|
|
|
UnicodeNotFilter(UnicodeFilter* adopted);
|
|
|
|
UnicodeNotFilter(const UnicodeNotFilter&);
|
|
|
|
virtual ~UnicodeNotFilter();
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool contains(UChar c) const;
|
1999-11-20 00:40:50 +00:00
|
|
|
virtual UnicodeFilter* clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeNotFilter::UnicodeNotFilter(UnicodeFilter* adopted) : filt(adopted) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeNotFilter::UnicodeNotFilter(const UnicodeNotFilter& f)
|
|
|
|
: UnicodeFilter(f), filt(f.filt->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeNotFilter::~UnicodeNotFilter() { delete filt; }
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeNotFilter::contains(UChar c) const { return !filt->contains(c); }
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeFilter* UnicodeNotFilter::clone() const { return new UnicodeNotFilter(*this); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
return new UnicodeNotFilter(f->clone());
|
|
|
|
}
|
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();
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool contains(UChar c) const;
|
1999-11-20 00:40:50 +00:00
|
|
|
virtual UnicodeFilter* clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeAndFilter::UnicodeAndFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeAndFilter::UnicodeAndFilter(const UnicodeAndFilter& f)
|
|
|
|
: UnicodeFilter(f), filt1(f.filt1->clone()), filt2(f.filt2->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeAndFilter::~UnicodeAndFilter() { delete filt1; delete filt2; }
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeAndFilter::contains(UChar c) const { return filt1->contains(c) && filt2->contains(c); }
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeFilter* UnicodeAndFilter::clone() const { return new UnicodeAndFilter(*this); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
return g->clone();
|
|
|
|
}
|
|
|
|
if (g == 0) {
|
|
|
|
return f->clone();
|
|
|
|
}
|
|
|
|
return new UnicodeAndFilter(f->clone(), g->clone());
|
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();
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool contains(UChar c) const;
|
1999-11-20 00:40:50 +00:00
|
|
|
virtual UnicodeFilter* clone() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeOrFilter::UnicodeOrFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f1), filt2(f2) {}
|
2001-03-06 20:12:26 +00:00
|
|
|
UnicodeOrFilter::UnicodeOrFilter(const UnicodeOrFilter& f)
|
|
|
|
: UnicodeFilter(f), filt1(f.filt1->clone()), filt2(f.filt2->clone()) {}
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeOrFilter::~UnicodeOrFilter() { delete filt1; delete filt2; }
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool UnicodeOrFilter::contains(UChar c) const { return filt1->contains(c) || filt2->contains(c); }
|
1999-11-20 00:40:50 +00:00
|
|
|
UnicodeFilter* UnicodeOrFilter::clone() const { return new UnicodeOrFilter(*this); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
return g->clone();
|
|
|
|
}
|
|
|
|
if (g == 0) {
|
|
|
|
return f->clone();
|
|
|
|
}
|
|
|
|
return new UnicodeOrFilter(f->clone(), g->clone());
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|