Logo Search packages:      
Sourcecode: icu version File versions  Download package

UMatchDegree UnicodeFilter::matches ( const Replaceable text,
int32_t &  offset,
int32_t  limit,
UBool  incremental 
) [virtual]

Implement UnicodeMatcher API. ICU 2.4

Default implementation of UnicodeMatcher::matches() for Unicode filters. Matches a single code point at offset (either one or two 16-bit code units).

Implements UnicodeMatcher.

Reimplemented in UnicodeSet.

Definition at line 39 of file unifilt.cpp.

References Replaceable::char32At(), contains(), U_MATCH, U_MISMATCH, U_PARTIAL_MATCH, and UTF_CHAR_LENGTH.

Referenced by UnicodeSet::matches().

                                                       {
    UChar32 c;
    if (offset < limit &&
        contains(c = text.char32At(offset))) {
        offset += UTF_CHAR_LENGTH(c);
        return U_MATCH;
    }
    if (offset > limit &&
        contains(c = text.char32At(offset))) {
        // Backup offset by 1, unless the preceding character is a
        // surrogate pair -- then backup by 2 (keep offset pointing at
        // the lead surrogate).
        --offset;
        if (offset >= 0) {
            offset -= UTF_CHAR_LENGTH(text.char32At(offset)) - 1;
        }
        return U_MATCH;
    }
    if (incremental && offset == limit) {
        return U_PARTIAL_MATCH;
    }
    return U_MISMATCH;
}


Generated by  Doxygen 1.6.0   Back to index