2001-07-27 00:18:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001, International Business Machines Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 07/26/01 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef QUANT_H
|
|
|
|
#define QUANT_H
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
#include "unicode/unifunct.h"
|
2001-07-27 00:18:53 +00:00
|
|
|
#include "unicode/unimatch.h"
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
class Quantifier : public UnicodeFunctor, public UnicodeMatcher {
|
2001-07-27 00:18:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2001-07-30 23:23:16 +00:00
|
|
|
enum { MAX = 0x7FFFFFFF };
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
Quantifier(UnicodeFunctor *adoptedMatcher,
|
2001-07-27 00:18:53 +00:00
|
|
|
uint32_t minCount, uint32_t maxCount);
|
|
|
|
|
|
|
|
Quantifier(const Quantifier& o);
|
|
|
|
|
|
|
|
virtual ~Quantifier();
|
|
|
|
|
|
|
|
/**
|
2002-02-07 01:07:55 +00:00
|
|
|
* UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
|
|
|
|
* and return the pointer.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the UnicodeMatcher pointer.
|
2002-02-07 01:07:55 +00:00
|
|
|
*/
|
|
|
|
virtual UnicodeMatcher* toMatcher() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement UnicodeFunctor
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return a copy of the object.
|
2001-07-27 00:18:53 +00:00
|
|
|
*/
|
2002-02-07 01:07:55 +00:00
|
|
|
virtual UnicodeFunctor* clone() const;
|
2001-07-27 00:18:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement UnicodeMatcher
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param text the text to be matched
|
|
|
|
* @param offset on input, the index into text at which to begin
|
|
|
|
* matching. On output, the limit of the matched text. The
|
|
|
|
* number of matched characters is the output value of offset
|
|
|
|
* minus the input value. Offset should always point to the
|
|
|
|
* HIGH SURROGATE (leading code unit) of a pair of surrogates,
|
|
|
|
* both on entry and upon return.
|
|
|
|
* @param limit the limit index of text to be matched. Greater
|
|
|
|
* than offset for a forward direction match, less than offset for
|
|
|
|
* a backward direction match. The last character to be
|
|
|
|
* considered for matching will be text.charAt(limit-1) in the
|
|
|
|
* forward direction or text.charAt(limit+1) in the backward
|
|
|
|
* direction.
|
|
|
|
* @param incremental if TRUE, then assume further characters may
|
|
|
|
* be inserted at limit and check for partial matching. Otherwise
|
|
|
|
* assume the text as given is complete.
|
|
|
|
* @return a match degree value indicating a full match, a partial
|
|
|
|
* match, or a mismatch. If incremental is FALSE then
|
|
|
|
* U_PARTIAL_MATCH should never be returned.
|
2001-07-27 00:18:53 +00:00
|
|
|
*/
|
|
|
|
virtual UMatchDegree matches(const Replaceable& text,
|
|
|
|
int32_t& offset,
|
|
|
|
int32_t limit,
|
2001-10-30 23:55:09 +00:00
|
|
|
UBool incremental);
|
2001-07-27 00:18:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement UnicodeMatcher
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param result Output param to receive the pattern.
|
|
|
|
* @param escapeUnprintable if True then escape the unprintable characters.
|
|
|
|
* @return A reference to 'result'.
|
2001-07-27 00:18:53 +00:00
|
|
|
*/
|
|
|
|
virtual UnicodeString& toPattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable = FALSE) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement UnicodeMatcher
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param v the given index value.
|
|
|
|
* @return true if this rule matches the given index value.
|
2001-07-27 00:18:53 +00:00
|
|
|
*/
|
|
|
|
virtual UBool matchesIndexValue(uint8_t v) const;
|
|
|
|
|
2002-06-28 21:13:54 +00:00
|
|
|
/**
|
|
|
|
* Implement UnicodeMatcher
|
|
|
|
*/
|
|
|
|
virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
|
|
|
|
|
2002-03-20 00:42:02 +00:00
|
|
|
/**
|
|
|
|
* UnicodeFunctor API
|
|
|
|
*/
|
|
|
|
virtual void setData(const TransliterationRuleData*);
|
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
private:
|
|
|
|
|
2001-07-30 23:23:16 +00:00
|
|
|
static void appendNumber(UnicodeString& result, int32_t n);
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
UnicodeFunctor* matcher; // owned
|
2001-07-27 00:18:53 +00:00
|
|
|
|
|
|
|
uint32_t minCount;
|
|
|
|
|
|
|
|
uint32_t maxCount;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The address of this static class variable serves as this class's ID
|
|
|
|
* for ICU "poor man's RTTI".
|
|
|
|
*/
|
|
|
|
static const char fgClassID;
|
2001-07-27 00:18:53 +00:00
|
|
|
};
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
#endif
|