]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/quant.cpp
2 * Copyright (C) 2001-2003, International Business Machines Corporation and others. All Rights Reserved.
3 **********************************************************************
4 * Date Name Description
5 * 07/26/01 aliu Creation.
6 **********************************************************************
9 #include "unicode/utypes.h"
11 #if !UCONFIG_NO_TRANSLITERATION
14 #include "unicode/unistr.h"
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Quantifier
)
21 Quantifier::Quantifier(UnicodeFunctor
*adoptedMatcher
,
22 uint32_t _minCount
, uint32_t _maxCount
) {
23 // assert(adopted != 0);
24 // assert(minCount <= maxCount);
25 matcher
= adoptedMatcher
;
26 this->minCount
= _minCount
;
27 this->maxCount
= _maxCount
;
30 Quantifier::Quantifier(const Quantifier
& o
) :
33 matcher(o
.matcher
->clone()),
39 Quantifier::~Quantifier() {
44 * Implement UnicodeFunctor
46 UnicodeFunctor
* Quantifier::clone() const {
47 return new Quantifier(*this);
51 * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
52 * and return the pointer.
54 UnicodeMatcher
* Quantifier::toMatcher() const {
55 return (UnicodeMatcher
*) this;
58 UMatchDegree
Quantifier::matches(const Replaceable
& text
,
62 int32_t start
= offset
;
64 while (count
< maxCount
) {
66 UMatchDegree m
= matcher
->toMatcher()->matches(text
, offset
, limit
, incremental
);
70 // If offset has not moved we have a zero-width match.
71 // Don't keep matching it infinitely.
74 } else if (incremental
&& m
== U_PARTIAL_MATCH
) {
75 return U_PARTIAL_MATCH
;
80 if (incremental
&& offset
== limit
) {
81 return U_PARTIAL_MATCH
;
83 if (count
>= minCount
) {
91 * Implement UnicodeMatcher
93 UnicodeString
& Quantifier::toPattern(UnicodeString
& result
,
94 UBool escapeUnprintable
) const {
96 matcher
->toMatcher()->toPattern(result
, escapeUnprintable
);
99 return result
.append((UChar
)63); /*?*/
100 } else if (maxCount
== MAX
) {
101 return result
.append((UChar
)42); /***/
104 } else if (minCount
== 1 && maxCount
== MAX
) {
105 return result
.append((UChar
)43); /*+*/
107 result
.append((UChar
)123); /*{*/
108 ICU_Utility::appendNumber(result
, minCount
);
109 result
.append((UChar
)44); /*,*/
110 if (maxCount
!= MAX
) {
111 ICU_Utility::appendNumber(result
, maxCount
);
113 result
.append((UChar
)125); /*}*/
118 * Implement UnicodeMatcher
120 UBool
Quantifier::matchesIndexValue(uint8_t v
) const {
121 return (minCount
== 0) || matcher
->toMatcher()->matchesIndexValue(v
);
125 * Implement UnicodeMatcher
127 void Quantifier::addMatchSetTo(UnicodeSet
& toUnionTo
) const {
129 matcher
->toMatcher()->addMatchSetTo(toUnionTo
);
134 * Implement UnicodeFunctor
136 void Quantifier::setData(const TransliterationRuleData
* d
) {
142 #endif /* #if !UCONFIG_NO_TRANSLITERATION */