2001-07-25 18:50:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001, International Business Machines Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 07/18/01 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/unifilt.h"
|
|
|
|
#include "unicode/rep.h"
|
|
|
|
#include "rbt_rule.h"
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
/**
|
|
|
|
* UnicodeFunctor API. Cast 'this' to a UnicodeMatcher* pointer
|
|
|
|
* and return the pointer.
|
|
|
|
*/
|
|
|
|
UnicodeMatcher* UnicodeFilter::toMatcher() const {
|
|
|
|
return (UnicodeMatcher*) this;
|
|
|
|
}
|
|
|
|
|
2001-07-25 18:50:09 +00:00
|
|
|
/**
|
|
|
|
* Default implementation of UnicodeMatcher::matches() for Unicode
|
2001-11-20 00:41:01 +00:00
|
|
|
* filters. Matches a single code point at offset (either one or
|
|
|
|
* two 16-bit code units).
|
2001-07-25 18:50:09 +00:00
|
|
|
*/
|
|
|
|
UMatchDegree UnicodeFilter::matches(const Replaceable& text,
|
|
|
|
int32_t& offset,
|
|
|
|
int32_t limit,
|
2001-10-30 23:55:09 +00:00
|
|
|
UBool incremental) {
|
2001-07-25 18:50:09 +00:00
|
|
|
UChar32 c;
|
|
|
|
if (offset < limit &&
|
|
|
|
contains(c = text.char32At(offset))) {
|
|
|
|
offset += UTF_CHAR_LENGTH(c);
|
|
|
|
return U_MATCH;
|
|
|
|
}
|
|
|
|
if (offset > limit &&
|
2001-07-25 21:15:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-07-25 18:50:09 +00:00
|
|
|
return U_MATCH;
|
|
|
|
}
|
|
|
|
if (incremental && offset == limit) {
|
|
|
|
return U_PARTIAL_MATCH;
|
|
|
|
}
|
|
|
|
return U_MISMATCH;
|
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
|
|
|
|
// Stub this out for filters that do not implement a pattern
|
|
|
|
UnicodeString& UnicodeFilter::toPattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable) const {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stub this out for filters that do not implement indexing
|
|
|
|
UBool UnicodeFilter::matchesIndexValue(uint8_t v) const {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
//eof
|