]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unifilt.cpp
ICU-66108.tar.gz
[apple/icu.git] / icuSources / common / unifilt.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f 3/*
374ca955 4**********************************************************************
51004dcb 5* Copyright (c) 2001-2012, International Business Machines
374ca955 6* Corporation and others. All Rights Reserved.
b75a7d8f
A
7**********************************************************************
8* Date Name Description
9* 07/18/01 aliu Creation.
10**********************************************************************
11*/
12
13#include "unicode/unifilt.h"
14#include "unicode/rep.h"
4388f060 15#include "unicode/utf16.h"
b75a7d8f
A
16
17U_NAMESPACE_BEGIN
374ca955
A
18UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(UnicodeFilter)
19
b75a7d8f 20
374ca955
A
21/* Define this here due to the lack of another file.
22 It can't be defined in the header */
23UnicodeMatcher::~UnicodeMatcher() {}
24
25UnicodeFilter::~UnicodeFilter() {}
b75a7d8f
A
26
27/**
51004dcb
A
28 * UnicodeFunctor API.
29 * Note that UnicodeMatcher is a base class of UnicodeFilter.
b75a7d8f
A
30 */
31UnicodeMatcher* UnicodeFilter::toMatcher() const {
51004dcb 32 return const_cast<UnicodeFilter *>(this);
b75a7d8f
A
33}
34
374ca955
A
35void UnicodeFilter::setData(const TransliterationRuleData*) {}
36
b75a7d8f
A
37/**
38 * Default implementation of UnicodeMatcher::matches() for Unicode
39 * filters. Matches a single code point at offset (either one or
40 * two 16-bit code units).
41 */
42UMatchDegree UnicodeFilter::matches(const Replaceable& text,
43 int32_t& offset,
44 int32_t limit,
45 UBool incremental) {
46 UChar32 c;
47 if (offset < limit &&
48 contains(c = text.char32At(offset))) {
4388f060 49 offset += U16_LENGTH(c);
b75a7d8f
A
50 return U_MATCH;
51 }
52 if (offset > limit &&
53 contains(c = text.char32At(offset))) {
54 // Backup offset by 1, unless the preceding character is a
55 // surrogate pair -- then backup by 2 (keep offset pointing at
56 // the lead surrogate).
57 --offset;
58 if (offset >= 0) {
4388f060 59 offset -= U16_LENGTH(text.char32At(offset)) - 1;
b75a7d8f
A
60 }
61 return U_MATCH;
62 }
63 if (incremental && offset == limit) {
64 return U_PARTIAL_MATCH;
65 }
66 return U_MISMATCH;
67}
68
69U_NAMESPACE_END
70
71//eof