ICU-199 UnicodeSet inherits from UnicodeFilter

X-SVN-Rev: 634
This commit is contained in:
Alan Liu 2000-01-18 20:00:56 +00:00
parent 8ab661d242
commit 7da50142ca
13 changed files with 71 additions and 54 deletions

View File

@ -19,7 +19,7 @@
* @param transliterators array of <code>Transliterator</code>
* objects
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/

View File

@ -204,7 +204,7 @@ bool_t TransliterationRule::masks(const TransliterationRule& r2) const {
* If greater than or equal to result.length(), represents offset start +
* cursor - result.length() into text.
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -231,7 +231,7 @@ bool_t TransliterationRule::matches(const UnicodeString& text,
* into text. This value must be between <code>start</code> and
* <code>limit</code>.
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -262,7 +262,7 @@ bool_t TransliterationRule::matches(const Replaceable& text,
* into text. This value must be between <code>start</code> and
* <code>limit</code>.
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return one of <code>MISMATCH</code>, <code>PARTIAL_MATCH</code>, or
@ -301,7 +301,7 @@ int32_t TransliterationRule::getMatchDegree(const Replaceable& text,
* @param data a dictionary of variables mapping <code>Character</code>
* to <code>UnicodeSet</code>
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return true if there is a match
@ -344,7 +344,7 @@ bool_t TransliterationRule::regionMatches(const UnicodeString& text,
* @param data a dictionary of variables mapping <code>Character</code>
* to <code>UnicodeSet</code>
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return true if there is a match
@ -384,7 +384,7 @@ bool_t TransliterationRule::regionMatches(const Replaceable& text,
* @param data a dictionary of variables mapping <code>Character</code>
* to <code>UnicodeSet</code>
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return -1 if there is a mismatch, 0 if the text is not long enough to
@ -420,7 +420,7 @@ int32_t TransliterationRule::getRegionMatchLength(const Replaceable& text,
* @param data a dictionary of variables mapping <code>Character</code>
* to <code>UnicodeSet</code>
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -428,7 +428,7 @@ bool_t TransliterationRule::charMatches(UChar keyChar, UChar textChar,
const TransliterationRuleData& data,
const UnicodeFilter* filter) const {
UnicodeSet* set = 0;
return (filter == 0 || filter->isIn(textChar)) &&
return (filter == 0 || filter->contains(textChar)) &&
(((set = data.lookupSet(keyChar)) == 0) ?
keyChar == textChar : set->contains(textChar));
}

View File

@ -204,7 +204,7 @@ void TransliterationRuleSet::freeze(const TransliterationRuleData& data,
* @param data a dictionary mapping variables to the sets they
* represent (maps <code>Character</code> to <code>UnicodeSet</code>)
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return the matching rule, or null if none found.
@ -243,7 +243,7 @@ TransliterationRuleSet::findMatch(const UnicodeString& text,
* @param data a dictionary mapping variables to the sets they
* represent (maps <code>Character</code> to <code>UnicodeSet</code>)
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return the matching rule, or null if none found.
@ -287,7 +287,7 @@ TransliterationRuleSet::findMatch(const Replaceable& text,
* @param partial output parameter. <code>partial[0]</code> is set to
* true if a partial match is returned.
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return the matching rule, or null if none found, or if the text buffer

View File

@ -104,7 +104,7 @@ const char* Transliterator::RB_RULE = "Rule";
* Default constructor.
* @param theID the string identifier for this transliterator
* @param theFilter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -837,7 +837,7 @@ UChar Transliterator::filteredCharAt(const Replaceable& text, int32_t i) const {
UChar c;
const UnicodeFilter* filter = getFilter();
return (filter == 0) ? text.charAt(i) :
(filter->isIn(c = text.charAt(i)) ? c : (UChar)0xFFFF);
(filter->contains(c = text.charAt(i)) ? c : (UChar)0xFFFF);
}
/**

View File

@ -32,7 +32,7 @@
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.3 $ $Date: 2000/01/18 18:27:27 $
* @version $RCSfile: cpdtrans.h,v $ $Revision: 1.4 $ $Date: 2000/01/18 20:00:41 $
*/
class U_I18N_API CompoundTransliterator : public Transliterator {
@ -50,7 +50,7 @@ public:
* @param transliterators array of <code>Transliterator</code>
* objects
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/

View File

@ -267,7 +267,7 @@ private:
/**
* This transliterator's filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -387,7 +387,7 @@ protected:
* Default constructor.
* @param ID the string identifier for this transliterator
* @param adoptedFilter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
*/
@ -455,7 +455,7 @@ public:
* @param limit the ending index, exclusive; <code>start <= limit
* <= text.length()</code>.
* @param filter the filter. Any character for which
* <tt>filter.isIn()</tt> returns <tt>false</tt> will not be
* <tt>filter.contains()</tt> returns <tt>false</tt> will not be
* altered by this transliterator. If <tt>filter</tt> is
* <tt>null</tt> then no filtering is applied.
* @return The new limit index. The text previously occupying <code>[start,

View File

@ -28,10 +28,10 @@ public:
/**
* Returns <tt>true</tt> for characters that are in the selected
* subset. In other words, if a character is <b>to be
* filtered</b>, then <tt>isIn()</tt> returns
* filtered</b>, then <tt>contains()</tt> returns
* <b><tt>false</tt></b>.
*/
virtual bool_t isIn(UChar c) const = 0;
virtual bool_t contains(UChar c) const = 0;
/**
* Returns a copy of this object. All UnicodeFilter objects have

View File

@ -34,8 +34,8 @@ public:
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit AND of the result of the two given filters. That is,
* if <tt>f.isIn()</tt> is <tt>false</tt>, then <tt>g.isIn()</tt>
* is not called, and <tt>isIn()</tt> returns <tt>false</tt>.
* 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>.
*
* <p>Either <tt>f</tt> or <tt>g</tt> must be non-null.
*/
@ -45,17 +45,17 @@ public:
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit AND of the result of the given filters. That is, if
* <tt>f[i].isIn()</tt> is <tt>false</tt>, then
* <tt>f[j].isIn()</tt> is not called, where <tt>j > i</tt>, and
* <tt>isIn()</tt> returns <tt>false</tt>.
* <tt>f[i].contains()</tt> is <tt>false</tt>, then
* <tt>f[j].contains()</tt> is not called, where <tt>j > i</tt>, and
* <tt>contains()</tt> returns <tt>false</tt>.
*/
// static UnicodeFilter* and(const UnicodeFilter** f);
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit OR of the result of the two given filters. That is, if
* <tt>f.isIn()</tt> is <tt>true</tt>, then <tt>g.isIn()</tt> is
* not called, and <tt>isIn()</tt> returns <tt>true</tt>.
* <tt>f.contains()</tt> is <tt>true</tt>, then <tt>g.contains()</tt> is
* not called, and <tt>contains()</tt> returns <tt>true</tt>.
*
* <p>Either <tt>f</tt> or <tt>g</tt> must be non-null.
*/
@ -65,9 +65,9 @@ public:
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit OR of the result of the given filters. That is, if
* <tt>f[i].isIn()</tt> is <tt>false</tt>, then
* <tt>f[j].isIn()</tt> is not called, where <tt>j > i</tt>, and
* <tt>isIn()</tt> returns <tt>true</tt>.
* <tt>f[i].contains()</tt> is <tt>false</tt>, then
* <tt>f[j].contains()</tt> is not called, where <tt>j > i</tt>, and
* <tt>contains()</tt> returns <tt>true</tt>.
*/
// static UnicodeFilter* or(const UnicodeFilter** f);

View File

@ -10,6 +10,7 @@
#ifndef UNICODESET_H
#define UNICODESET_H
#include "unicode/unifilt.h"
#include "unicode/utypes.h"
#include "unicode/unistr.h"
@ -244,7 +245,7 @@ class TransliterationRule;
*
* @author Alan Liu
*/
class U_I18N_API UnicodeSet {
class U_I18N_API UnicodeSet : public UnicodeFilter {
/**
* The internal representation is a UnicodeString of even length.
@ -363,6 +364,13 @@ public:
*/
bool_t operator!=(const UnicodeSet& o) const;
/**
* Returns a copy of this object. All UnicodeFilter objects have
* to support cloning in order to allow classes using
* UnicodeFilters, such as Transliterator, to implement cloning.
*/
virtual UnicodeFilter* clone() const;
/**
* Returns the hash code value for this set.
*

View File

@ -16,14 +16,14 @@ public:
UnicodeNotFilter(UnicodeFilter* adopted);
UnicodeNotFilter(const UnicodeNotFilter&);
virtual ~UnicodeNotFilter();
virtual bool_t isIn(UChar c) const;
virtual bool_t contains(UChar c) const;
virtual UnicodeFilter* clone() const;
};
UnicodeNotFilter::UnicodeNotFilter(UnicodeFilter* adopted) : filt(adopted) {}
UnicodeNotFilter::UnicodeNotFilter(const UnicodeNotFilter& f) : filt(f.filt->clone()) {}
UnicodeNotFilter::~UnicodeNotFilter() { delete filt; }
bool_t UnicodeNotFilter::isIn(UChar c) const { return !filt->isIn(c); }
bool_t UnicodeNotFilter::contains(UChar c) const { return !filt->contains(c); }
UnicodeFilter* UnicodeNotFilter::clone() const { return new UnicodeNotFilter(*this); }
/**
@ -41,7 +41,7 @@ public:
UnicodeAndFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
UnicodeAndFilter(const UnicodeAndFilter&);
virtual ~UnicodeAndFilter();
virtual bool_t isIn(UChar c) const;
virtual bool_t contains(UChar c) const;
virtual UnicodeFilter* clone() const;
};
@ -49,14 +49,14 @@ UnicodeAndFilter::UnicodeAndFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1
UnicodeAndFilter::UnicodeAndFilter(const UnicodeAndFilter& f) :
filt1(f.filt1->clone()), filt2(f.filt2->clone()) {}
UnicodeAndFilter::~UnicodeAndFilter() { delete filt1; delete filt2; }
bool_t UnicodeAndFilter::isIn(UChar c) const { return filt1->isIn(c) && filt2->isIn(c); }
bool_t UnicodeAndFilter::contains(UChar c) const { return filt1->contains(c) && filt2->contains(c); }
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,
* if <tt>f.isIn()</tt> is <tt>false</tt>, then <tt>g.isIn()</tt>
* is not called, and <tt>isIn()</tt> returns <tt>false</tt>.
* 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>.
*
* <p>Either <tt>f</tt> or <tt>g</tt> must be non-null.
*/
@ -68,15 +68,15 @@ UnicodeFilter* UnicodeFilterLogic::createAnd(const UnicodeFilter& f,
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit AND of the result of the given filters. That is, if
* <tt>f[i].isIn()</tt> is <tt>false</tt>, then
* <tt>f[j].isIn()</tt> is not called, where <tt>j > i</tt>, and
* <tt>isIn()</tt> returns <tt>false</tt>.
* <tt>f[i].contains()</tt> is <tt>false</tt>, then
* <tt>f[j].contains()</tt> is not called, where <tt>j > i</tt>, and
* <tt>contains()</tt> returns <tt>false</tt>.
*/
//!UnicodeFilter* UnicodeFilterLogic::and(const UnicodeFilter** f) {
//! return new UnicodeFilter() {
//! public bool_t isIn(UChar c) {
//! public bool_t contains(UChar c) {
//! for (int32_t i=0; i<f.length; ++i) {
//! if (!f[i].isIn(c)) {
//! if (!f[i].contains(c)) {
//! return FALSE;
//! }
//! }
@ -92,7 +92,7 @@ public:
UnicodeOrFilter(UnicodeFilter* adopted1, UnicodeFilter* adopted2);
UnicodeOrFilter(const UnicodeOrFilter&);
virtual ~UnicodeOrFilter();
virtual bool_t isIn(UChar c) const;
virtual bool_t contains(UChar c) const;
virtual UnicodeFilter* clone() const;
};
@ -100,14 +100,14 @@ UnicodeOrFilter::UnicodeOrFilter(UnicodeFilter* f1, UnicodeFilter* f2) : filt1(f
UnicodeOrFilter::UnicodeOrFilter(const UnicodeOrFilter& f) :
filt1(f.filt1->clone()), filt2(f.filt2->clone()) {}
UnicodeOrFilter::~UnicodeOrFilter() { delete filt1; delete filt2; }
bool_t UnicodeOrFilter::isIn(UChar c) const { return filt1->isIn(c) || filt2->isIn(c); }
bool_t UnicodeOrFilter::contains(UChar c) const { return filt1->contains(c) || filt2->contains(c); }
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
* <tt>f.isIn()</tt> is <tt>true</tt>, then <tt>g.isIn()</tt> is
* not called, and <tt>isIn()</tt> returns <tt>true</tt>.
* <tt>f.contains()</tt> is <tt>true</tt>, then <tt>g.contains()</tt> is
* not called, and <tt>contains()</tt> returns <tt>true</tt>.
*
* <p>Either <tt>f</tt> or <tt>g</tt> must be non-null.
*/
@ -119,15 +119,15 @@ UnicodeFilter* UnicodeFilterLogic::createOr(const UnicodeFilter& f,
/**
* Returns a <tt>UnicodeFilter</tt> that implements a short
* circuit OR of the result of the given filters. That is, if
* <tt>f[i].isIn()</tt> is <tt>false</tt>, then
* <tt>f[j].isIn()</tt> is not called, where <tt>j > i</tt>, and
* <tt>isIn()</tt> returns <tt>true</tt>.
* <tt>f[i].contains()</tt> is <tt>false</tt>, then
* <tt>f[j].contains()</tt> is not called, where <tt>j > i</tt>, and
* <tt>contains()</tt> returns <tt>true</tt>.
*/
//!UnicodeFilter* UnicodeFilterLogic::or(const UnicodeFilter** f) {
//! return new UnicodeFilter() {
//! public bool_t isIn(UChar c) {
//! public bool_t contains(UChar c) {
//! for (int32_t i=0; i<f.length; ++i) {
//! if (f[i].isIn(c)) {
//! if (f[i].contains(c)) {
//! return TRUE;
//! }
//! }

View File

@ -132,6 +132,15 @@ bool_t UnicodeSet::operator==(const UnicodeSet& o) const {
return pairs == o.pairs;
}
/**
* Returns a copy of this object. All UnicodeFilter objects have
* to support cloning in order to allow classes using
* UnicodeFilters, such as Transliterator, to implement cloning.
*/
UnicodeFilter* UnicodeSet::clone() const {
return new UnicodeSet(*this);
}
/**
* Returns the hash code value for this set.
*

View File

@ -130,7 +130,7 @@ void UnicodeToHexTransliterator::handleTransliterate(Replaceable& text,
while (cursor < limit) {
UChar c = text.charAt(cursor);
if (filter != 0 && !filter->isIn(c)) {
if (filter != 0 && !filter->contains(c)) {
++cursor;
continue;
}

View File

@ -420,7 +420,7 @@ class TestFilter : public UnicodeFilter {
virtual UnicodeFilter* clone() const {
return new TestFilter(*this);
}
virtual bool_t isIn(UChar c) const {
virtual bool_t contains(UChar c) const {
return c != (UChar)'c';
}
};