~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/i18n/unifilt.cpp

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (C) 2001, International Business Machines Corporation and others. All Rights Reserved.
 
3
**********************************************************************
 
4
*   Date        Name        Description
 
5
*   07/18/01    aliu        Creation.
 
6
**********************************************************************
 
7
*/
 
8
 
 
9
#include "unicode/unifilt.h"
 
10
#include "unicode/rep.h"
 
11
#include "rbt_rule.h"
 
12
 
 
13
U_NAMESPACE_BEGIN
 
14
 
 
15
/**
 
16
 * UnicodeFunctor API.  Cast 'this' to a UnicodeMatcher* pointer
 
17
 * and return the pointer.
 
18
 */
 
19
UnicodeMatcher* UnicodeFilter::toMatcher() const {
 
20
    return (UnicodeMatcher*) this;
 
21
}
 
22
 
 
23
/**
 
24
 * Default implementation of UnicodeMatcher::matches() for Unicode
 
25
 * filters.  Matches a single code point at offset (either one or
 
26
 * two 16-bit code units).
 
27
 */
 
28
UMatchDegree UnicodeFilter::matches(const Replaceable& text,
 
29
                                    int32_t& offset,
 
30
                                    int32_t limit,
 
31
                                    UBool incremental) {
 
32
    UChar32 c;
 
33
    if (offset < limit &&
 
34
        contains(c = text.char32At(offset))) {
 
35
        offset += UTF_CHAR_LENGTH(c);
 
36
        return U_MATCH;
 
37
    }
 
38
    if (offset > limit &&
 
39
        contains(c = text.char32At(offset))) {
 
40
        // Backup offset by 1, unless the preceding character is a
 
41
        // surrogate pair -- then backup by 2 (keep offset pointing at
 
42
        // the lead surrogate).
 
43
        --offset;
 
44
        if (offset >= 0) {
 
45
            offset -= UTF_CHAR_LENGTH(text.char32At(offset)) - 1;
 
46
        }
 
47
        return U_MATCH;
 
48
    }
 
49
    if (incremental && offset == limit) {
 
50
        return U_PARTIAL_MATCH;
 
51
    }
 
52
    return U_MISMATCH;
 
53
}
 
54
 
 
55
// Stub this out for filters that do not implement a pattern
 
56
UnicodeString& UnicodeFilter::toPattern(UnicodeString& result,
 
57
                                        UBool escapeUnprintable) const {
 
58
    return result;
 
59
}
 
60
 
 
61
// Stub this out for filters that do not implement indexing
 
62
UBool UnicodeFilter::matchesIndexValue(uint8_t v) const {
 
63
    return FALSE;
 
64
}
 
65
 
 
66
U_NAMESPACE_END
 
67
 
 
68
//eof