~ubuntu-branches/ubuntu/vivid/mozjs24/vivid

« back to all changes in this revision

Viewing changes to intl/icu/source/common/unifilt.cpp

  • Committer: Package Import Robot
  • Author(s): Tim Lunn
  • Date: 2014-02-11 21:55:34 UTC
  • Revision ID: package-import@ubuntu.com-20140211215534-m1zyq5aj59md3y07
Tags: upstream-24.2.0
ImportĀ upstreamĀ versionĀ 24.2.0

Show diffs side-by-side

added added

removed removed

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