Coverage Report

Created: 2023-02-22 06:51

/src/icu/source/common/unifilt.cpp
Line
Count
Source (jump to first uncovered line)
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
**********************************************************************
5
* Copyright (c) 2001-2012, International Business Machines
6
* Corporation and others.  All Rights Reserved.
7
**********************************************************************
8
*   Date        Name        Description
9
*   07/18/01    aliu        Creation.
10
**********************************************************************
11
*/
12
13
#include "unicode/unifilt.h"
14
#include "unicode/rep.h"
15
#include "unicode/utf16.h"
16
17
U_NAMESPACE_BEGIN
18
UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(UnicodeFilter)
19
20
21
/* Define this here due to the lack of another file.
22
   It can't be defined in the header */
23
0
UnicodeMatcher::~UnicodeMatcher() {}
24
25
0
UnicodeFilter::~UnicodeFilter() {}
26
27
/**
28
 * UnicodeFunctor API.
29
 *   Note that UnicodeMatcher is a base class of UnicodeFilter.
30
 */
31
0
UnicodeMatcher* UnicodeFilter::toMatcher() const {
32
0
  return const_cast<UnicodeFilter *>(this);
33
0
}
34
35
0
void UnicodeFilter::setData(const TransliterationRuleData*) {}
36
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
 */
42
UMatchDegree UnicodeFilter::matches(const Replaceable& text,
43
                                    int32_t& offset,
44
                                    int32_t limit,
45
0
                                    UBool incremental) {
46
0
    UChar32 c;
47
0
    if (offset < limit &&
48
0
        contains(c = text.char32At(offset))) {
49
0
        offset += U16_LENGTH(c);
50
0
        return U_MATCH;
51
0
    }
52
0
    if (offset > limit &&
53
0
        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
0
        --offset;
58
0
        if (offset >= 0) {
59
0
            offset -= U16_LENGTH(text.char32At(offset)) - 1;
60
0
        }
61
0
        return U_MATCH;
62
0
    }
63
0
    if (incremental && offset == limit) {
64
0
        return U_PARTIAL_MATCH;
65
0
    }
66
0
    return U_MISMATCH;
67
0
}
68
69
U_NAMESPACE_END
70
71
//eof