1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unifilt.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +/* 1.5 +********************************************************************** 1.6 +* Copyright (c) 2001-2012, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +********************************************************************** 1.9 +* Date Name Description 1.10 +* 07/18/01 aliu Creation. 1.11 +********************************************************************** 1.12 +*/ 1.13 + 1.14 +#include "unicode/unifilt.h" 1.15 +#include "unicode/rep.h" 1.16 +#include "unicode/utf16.h" 1.17 + 1.18 +U_NAMESPACE_BEGIN 1.19 +UOBJECT_DEFINE_ABSTRACT_RTTI_IMPLEMENTATION(UnicodeFilter) 1.20 + 1.21 + 1.22 +/* Define this here due to the lack of another file. 1.23 + It can't be defined in the header */ 1.24 +UnicodeMatcher::~UnicodeMatcher() {} 1.25 + 1.26 +UnicodeFilter::~UnicodeFilter() {} 1.27 + 1.28 +/** 1.29 + * UnicodeFunctor API. 1.30 + * Note that UnicodeMatcher is a base class of UnicodeFilter. 1.31 + */ 1.32 +UnicodeMatcher* UnicodeFilter::toMatcher() const { 1.33 + return const_cast<UnicodeFilter *>(this); 1.34 +} 1.35 + 1.36 +void UnicodeFilter::setData(const TransliterationRuleData*) {} 1.37 + 1.38 +/** 1.39 + * Default implementation of UnicodeMatcher::matches() for Unicode 1.40 + * filters. Matches a single code point at offset (either one or 1.41 + * two 16-bit code units). 1.42 + */ 1.43 +UMatchDegree UnicodeFilter::matches(const Replaceable& text, 1.44 + int32_t& offset, 1.45 + int32_t limit, 1.46 + UBool incremental) { 1.47 + UChar32 c; 1.48 + if (offset < limit && 1.49 + contains(c = text.char32At(offset))) { 1.50 + offset += U16_LENGTH(c); 1.51 + return U_MATCH; 1.52 + } 1.53 + if (offset > limit && 1.54 + contains(c = text.char32At(offset))) { 1.55 + // Backup offset by 1, unless the preceding character is a 1.56 + // surrogate pair -- then backup by 2 (keep offset pointing at 1.57 + // the lead surrogate). 1.58 + --offset; 1.59 + if (offset >= 0) { 1.60 + offset -= U16_LENGTH(text.char32At(offset)) - 1; 1.61 + } 1.62 + return U_MATCH; 1.63 + } 1.64 + if (incremental && offset == limit) { 1.65 + return U_PARTIAL_MATCH; 1.66 + } 1.67 + return U_MISMATCH; 1.68 +} 1.69 + 1.70 +U_NAMESPACE_END 1.71 + 1.72 +//eof