]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/quant.cpp
2 **********************************************************************
3 * Copyright (C) 2001-2008, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 07/26/01 aliu Creation.
8 **********************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_TRANSLITERATION
16 #include "unicode/unistr.h"
21 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Quantifier
)
23 Quantifier::Quantifier(UnicodeFunctor
*adoptedMatcher
,
24 uint32_t _minCount
, uint32_t _maxCount
) {
25 // assert(adopted != 0);
26 // assert(minCount <= maxCount);
27 matcher
= adoptedMatcher
;
28 this->minCount
= _minCount
;
29 this->maxCount
= _maxCount
;
32 Quantifier::Quantifier(const Quantifier
& o
) :
35 matcher(o
.matcher
->clone()),
41 Quantifier::~Quantifier() {
46 * Implement UnicodeFunctor
48 UnicodeFunctor
* Quantifier::clone() const {
49 return new Quantifier(*this);
53 * UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
54 * and return the pointer.
56 UnicodeMatcher
* Quantifier::toMatcher() const {
57 return (UnicodeMatcher
*) this;
60 UMatchDegree
Quantifier::matches(const Replaceable
& text
,
64 int32_t start
= offset
;
66 while (count
< maxCount
) {
68 UMatchDegree m
= matcher
->toMatcher()->matches(text
, offset
, limit
, incremental
);
72 // If offset has not moved we have a zero-width match.
73 // Don't keep matching it infinitely.
76 } else if (incremental
&& m
== U_PARTIAL_MATCH
) {
77 return U_PARTIAL_MATCH
;
82 if (incremental
&& offset
== limit
) {
83 return U_PARTIAL_MATCH
;
85 if (count
>= minCount
) {
93 * Implement UnicodeMatcher
95 UnicodeString
& Quantifier::toPattern(UnicodeString
& result
,
96 UBool escapeUnprintable
) const {
98 matcher
->toMatcher()->toPattern(result
, escapeUnprintable
);
101 return result
.append((UChar
)63); /*?*/
102 } else if (maxCount
== MAX
) {
103 return result
.append((UChar
)42); /***/
106 } else if (minCount
== 1 && maxCount
== MAX
) {
107 return result
.append((UChar
)43); /*+*/
109 result
.append((UChar
)123); /*{*/
110 ICU_Utility::appendNumber(result
, minCount
);
111 result
.append((UChar
)44); /*,*/
112 if (maxCount
!= MAX
) {
113 ICU_Utility::appendNumber(result
, maxCount
);
115 result
.append((UChar
)125); /*}*/
120 * Implement UnicodeMatcher
122 UBool
Quantifier::matchesIndexValue(uint8_t v
) const {
123 return (minCount
== 0) || matcher
->toMatcher()->matchesIndexValue(v
);
127 * Implement UnicodeMatcher
129 void Quantifier::addMatchSetTo(UnicodeSet
& toUnionTo
) const {
131 matcher
->toMatcher()->addMatchSetTo(toUnionTo
);
136 * Implement UnicodeFunctor
138 void Quantifier::setData(const TransliterationRuleData
* d
) {
144 #endif /* #if !UCONFIG_NO_TRANSLITERATION */