Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (c) 2001-2012, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Date Name Description |
michael@0 | 7 | * 07/18/01 aliu Creation. |
michael@0 | 8 | ********************************************************************** |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "unicode/unifilt.h" |
michael@0 | 12 | #include "unicode/rep.h" |
michael@0 | 13 | #include "unicode/utf16.h" |
michael@0 | 14 | |
michael@0 | 15 | U_NAMESPACE_BEGIN |
michael@0 | 16 | UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(UnicodeFilter) |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | /* Define this here due to the lack of another file. |
michael@0 | 20 | It can't be defined in the header */ |
michael@0 | 21 | UnicodeMatcher::~UnicodeMatcher() {} |
michael@0 | 22 | |
michael@0 | 23 | UnicodeFilter::~UnicodeFilter() {} |
michael@0 | 24 | |
michael@0 | 25 | /** |
michael@0 | 26 | * UnicodeFunctor API. |
michael@0 | 27 | * Note that UnicodeMatcher is a base class of UnicodeFilter. |
michael@0 | 28 | */ |
michael@0 | 29 | UnicodeMatcher* UnicodeFilter::toMatcher() const { |
michael@0 | 30 | return const_cast<UnicodeFilter *>(this); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | void UnicodeFilter::setData(const TransliterationRuleData*) {} |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Default implementation of UnicodeMatcher::matches() for Unicode |
michael@0 | 37 | * filters. Matches a single code point at offset (either one or |
michael@0 | 38 | * two 16-bit code units). |
michael@0 | 39 | */ |
michael@0 | 40 | UMatchDegree UnicodeFilter::matches(const Replaceable& text, |
michael@0 | 41 | int32_t& offset, |
michael@0 | 42 | int32_t limit, |
michael@0 | 43 | UBool incremental) { |
michael@0 | 44 | UChar32 c; |
michael@0 | 45 | if (offset < limit && |
michael@0 | 46 | contains(c = text.char32At(offset))) { |
michael@0 | 47 | offset += U16_LENGTH(c); |
michael@0 | 48 | return U_MATCH; |
michael@0 | 49 | } |
michael@0 | 50 | if (offset > limit && |
michael@0 | 51 | contains(c = text.char32At(offset))) { |
michael@0 | 52 | // Backup offset by 1, unless the preceding character is a |
michael@0 | 53 | // surrogate pair -- then backup by 2 (keep offset pointing at |
michael@0 | 54 | // the lead surrogate). |
michael@0 | 55 | --offset; |
michael@0 | 56 | if (offset >= 0) { |
michael@0 | 57 | offset -= U16_LENGTH(text.char32At(offset)) - 1; |
michael@0 | 58 | } |
michael@0 | 59 | return U_MATCH; |
michael@0 | 60 | } |
michael@0 | 61 | if (incremental && offset == limit) { |
michael@0 | 62 | return U_PARTIAL_MATCH; |
michael@0 | 63 | } |
michael@0 | 64 | return U_MISMATCH; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | U_NAMESPACE_END |
michael@0 | 68 | |
michael@0 | 69 | //eof |