sl@0: /*
sl@0: * Copyright (C) 2001-2005, International Business Machines Corporation and others. All Rights Reserved.
sl@0: **********************************************************************
sl@0: * Date Name Description
sl@0: * 07/18/01 aliu Creation.
sl@0: **********************************************************************
sl@0: */
sl@0: #ifndef UNIMATCH_H
sl@0: #define UNIMATCH_H
sl@0:
sl@0: #include "unicode/utypes.h"
sl@0:
sl@0: /**
sl@0: * \file
sl@0: * \brief C++ API: Unicode Matcher
sl@0: */
sl@0:
sl@0:
sl@0: U_NAMESPACE_BEGIN
sl@0:
sl@0: class Replaceable;
sl@0: class UnicodeString;
sl@0: class UnicodeSet;
sl@0:
sl@0: /**
sl@0: * Constants returned by UnicodeMatcher::matches()
sl@0: * indicating the degree of match.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: enum UMatchDegree {
sl@0: /**
sl@0: * Constant returned by matches()
indicating a
sl@0: * mismatch between the text and this matcher. The text contains
sl@0: * a character which does not match, or the text does not contain
sl@0: * all desired characters for a non-incremental match.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: U_MISMATCH,
sl@0:
sl@0: /**
sl@0: * Constant returned by matches()
indicating a
sl@0: * partial match between the text and this matcher. This value is
sl@0: * only returned for incremental match operations. All characters
sl@0: * of the text match, but more characters are required for a
sl@0: * complete match. Alternatively, for variable-length matchers,
sl@0: * all characters of the text match, and if more characters were
sl@0: * supplied at limit, they might also match.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: U_PARTIAL_MATCH,
sl@0:
sl@0: /**
sl@0: * Constant returned by matches()
indicating a
sl@0: * complete match between the text and this matcher. For an
sl@0: * incremental variable-length match, this value is returned if
sl@0: * the given text matches, and it is known that additional
sl@0: * characters would not alter the extent of the match.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: U_MATCH
sl@0: };
sl@0:
sl@0: /**
sl@0: * UnicodeMatcher
defines a protocol for objects that can
sl@0: * match a range of characters in a Replaceable string.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: class U_COMMON_API UnicodeMatcher /* not : public UObject because this is an interface/mixin class */ {
sl@0:
sl@0: public:
sl@0: /**
sl@0: * Destructor.
sl@0: * @stable ICU 2.4
sl@0: */
sl@0: virtual ~UnicodeMatcher();
sl@0:
sl@0: /**
sl@0: * Return a UMatchDegree value indicating the degree of match for
sl@0: * the given text at the given offset. Zero, one, or more
sl@0: * characters may be matched.
sl@0: *
sl@0: * Matching in the forward direction is indicated by limit >
sl@0: * offset. Characters from offset forwards to limit-1 will be
sl@0: * considered for matching.
sl@0: *
sl@0: * Matching in the reverse direction is indicated by limit <
sl@0: * offset. Characters from offset backwards to limit+1 will be
sl@0: * considered for matching.
sl@0: *
sl@0: * If limit == offset then the only match possible is a zero
sl@0: * character match (which subclasses may implement if desired).
sl@0: *
sl@0: * As a side effect, advance the offset parameter to the limit of
sl@0: * the matched substring. In the forward direction, this will be
sl@0: * the index of the last matched character plus one. In the
sl@0: * reverse direction, this will be the index of the last matched
sl@0: * character minus one.
sl@0: *
sl@0: *
Note: This method is not const because some classes may sl@0: * modify their state as the result of a match. sl@0: * sl@0: * @param text the text to be matched sl@0: * @param offset on input, the index into text at which to begin sl@0: * matching. On output, the limit of the matched text. The sl@0: * number of matched characters is the output value of offset sl@0: * minus the input value. Offset should always point to the sl@0: * HIGH SURROGATE (leading code unit) of a pair of surrogates, sl@0: * both on entry and upon return. sl@0: * @param limit the limit index of text to be matched. Greater sl@0: * than offset for a forward direction match, less than offset for sl@0: * a backward direction match. The last character to be sl@0: * considered for matching will be text.charAt(limit-1) in the sl@0: * forward direction or text.charAt(limit+1) in the backward sl@0: * direction. sl@0: * @param incremental if TRUE, then assume further characters may sl@0: * be inserted at limit and check for partial matching. Otherwise sl@0: * assume the text as given is complete. sl@0: * @return a match degree value indicating a full match, a partial sl@0: * match, or a mismatch. If incremental is FALSE then sl@0: * U_PARTIAL_MATCH should never be returned. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UMatchDegree matches(const Replaceable& text, sl@0: int32_t& offset, sl@0: int32_t limit, sl@0: UBool incremental) = 0; sl@0: sl@0: /** sl@0: * Returns a string representation of this matcher. If the result of sl@0: * calling this function is passed to the appropriate parser, it sl@0: * will produce another matcher that is equal to this one. sl@0: * @param result the string to receive the pattern. Previous sl@0: * contents will be deleted. sl@0: * @param escapeUnprintable if TRUE then convert unprintable sl@0: * character to their hex escape representations, \\uxxxx or sl@0: * \\Uxxxxxxxx. Unprintable characters are those other than sl@0: * U+000A, U+0020..U+007E. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UnicodeString& toPattern(UnicodeString& result, sl@0: UBool escapeUnprintable = FALSE) const = 0; sl@0: sl@0: /** sl@0: * Returns TRUE if this matcher will match a character c, where c sl@0: * & 0xFF == v, at offset, in the forward direction (with limit > sl@0: * offset). This is used by RuleBasedTransliterator for sl@0: * indexing. sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual UBool matchesIndexValue(uint8_t v) const = 0; sl@0: sl@0: /** sl@0: * Union the set of all characters that may be matched by this object sl@0: * into the given set. sl@0: * @param toUnionTo the set into which to union the source characters sl@0: * @stable ICU 2.4 sl@0: */ sl@0: virtual void addMatchSetTo(UnicodeSet& toUnionTo) const = 0; sl@0: }; sl@0: sl@0: U_NAMESPACE_END sl@0: sl@0: #endif