ICU-1052 redesign of engine to support supplemental characters
X-SVN-Rev: 5340
This commit is contained in:
parent
ebe3b45ff8
commit
d7c3eebf46
@ -559,7 +559,7 @@ public:
|
||||
* @draft
|
||||
*/
|
||||
virtual void transliterate(Replaceable& text, UTransPosition& index,
|
||||
UChar insertion,
|
||||
UChar32 insertion,
|
||||
UErrorCode& status) const;
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@
|
||||
#ifndef UNIFILT_H
|
||||
#define UNIFILT_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/unimatch.h"
|
||||
|
||||
/**
|
||||
* <code>UnicodeFilter</code> defines a protocol for selecting a
|
||||
@ -20,7 +20,7 @@
|
||||
* @see UnicodeFilterLogic
|
||||
* @draft
|
||||
*/
|
||||
class U_I18N_API UnicodeFilter {
|
||||
class U_I18N_API UnicodeFilter : public UnicodeMatcher {
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -35,7 +35,7 @@ public:
|
||||
* <b><tt>false</tt></b>.
|
||||
* @draft
|
||||
*/
|
||||
virtual UBool contains(UChar c) const = 0;
|
||||
virtual UBool contains(UChar32 c) const = 0;
|
||||
|
||||
/**
|
||||
* Returns a copy of this object. All UnicodeFilter objects have
|
||||
@ -45,6 +45,14 @@ public:
|
||||
*/
|
||||
virtual UnicodeFilter* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Implement UnicodeMatcher API.
|
||||
*/
|
||||
virtual UMatchDegree matches(const Replaceable& text,
|
||||
int32_t& offset,
|
||||
int32_t limit,
|
||||
UBool incremental) const;
|
||||
|
||||
protected:
|
||||
|
||||
UnicodeFilter();
|
||||
|
115
icu4c/source/i18n/unicode/unimatch.h
Normal file
115
icu4c/source/i18n/unicode/unimatch.h
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2001, International Business Machines Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Date Name Description
|
||||
* 07/18/01 aliu Creation.
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef UNIMATCH_H
|
||||
#define UNIMATCH_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
class Replaceable;
|
||||
|
||||
/**
|
||||
* Constants returned by <code>UnicodeMatcher::matches()</code>
|
||||
* indicating the degree of match.
|
||||
*/
|
||||
enum UMatchDegree {
|
||||
/**
|
||||
* Constant returned by <code>matches()</code> indicating a
|
||||
* mismatch between the text and this matcher. The text contains
|
||||
* a character which does not match, or the text does not contain
|
||||
* all desired characters for a non-incremental match.
|
||||
*/
|
||||
U_MISMATCH,
|
||||
|
||||
/**
|
||||
* Constant returned by <code>matches()</code> indicating a
|
||||
* partial match between the text and this matcher. This value is
|
||||
* only returned for incremental match operations. All characters
|
||||
* of the text match, but more characters are required for a
|
||||
* complete match. Alternatively, for variable-length matchers,
|
||||
* all characters of the text match, and if more characters were
|
||||
* supplied at limit, they might also match.
|
||||
*/
|
||||
U_PARTIAL_MATCH,
|
||||
|
||||
/**
|
||||
* Constant returned by <code>matches()</code> indicating a
|
||||
* complete match between the text and this matcher. For an
|
||||
* incremental variable-length match, this value is returned if
|
||||
* the given text matches, and it is known that additional
|
||||
* characters would not alter the extent of the match.
|
||||
*/
|
||||
U_MATCH
|
||||
};
|
||||
|
||||
/**
|
||||
* <code>UnicodeMatcher</code> defines a protocol for objects that can
|
||||
* match a range of characters in a Replaceable string.
|
||||
*/
|
||||
class U_I18N_API UnicodeMatcher {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~UnicodeMatcher();
|
||||
|
||||
/**
|
||||
* Return a UMatchDegree value indicating the degree of match for
|
||||
* the given text at the given offset. Zero, one, or more
|
||||
* characters may be matched.
|
||||
*
|
||||
* Matching in the forward direction is indicated by limit >
|
||||
* offset. Characters from offset forwards to limit-1 will be
|
||||
* considered for matching.
|
||||
*
|
||||
* Matching in the reverse direction is indicated by limit <
|
||||
* offset. Characters from offset backwards to limit+1 will be
|
||||
* considered for matching.
|
||||
*
|
||||
* If limit == offset then the only match possible is a zero
|
||||
* character match (which subclasses may implement if desired).
|
||||
*
|
||||
* As a side effect, advance the offset parameter to the limit of
|
||||
* the matched substring. In the forward direction, this will be
|
||||
* the index of the last matched character plus one. In the
|
||||
* reverse direction, this will be the index of the last matched
|
||||
* character minus one.
|
||||
*
|
||||
* @param text the text to be matched
|
||||
* @param offset on input, the index into text at which to begin
|
||||
* matching. On output, the limit of the matched text. The
|
||||
* number of matched characters is the output value of offset
|
||||
* minus the input value.
|
||||
* @param limit the limit index of text to be matched. Greater
|
||||
* than offset for a forward direction match, less than offset for
|
||||
* a backward direction match. The last character to be
|
||||
* considered for matching will be text.charAt(limit-1) in the
|
||||
* forward direction or text.charAt(limit+1) in the backward
|
||||
* direction.
|
||||
* @param incremental if TRUE, then assume further characters may
|
||||
* be inserted at limit and check for partial matching. Otherwise
|
||||
* assume the text as given is complete.
|
||||
* @return a match degree value indicating a full match, a partial
|
||||
* match, or a mismatch. If incremental is FALSE then
|
||||
* U_PARTIAL_MATCH should never be returned.
|
||||
*/
|
||||
virtual UMatchDegree matches(const Replaceable& text,
|
||||
int32_t& offset,
|
||||
int32_t limit,
|
||||
UBool incremental) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
UnicodeMatcher();
|
||||
};
|
||||
|
||||
inline UnicodeMatcher::UnicodeMatcher() {}
|
||||
inline UnicodeMatcher::~UnicodeMatcher() {}
|
||||
|
||||
#endif
|
@ -458,14 +458,13 @@ public:
|
||||
virtual UBool contains(UChar32 c) const;
|
||||
|
||||
/**
|
||||
* Implement UnicodeFilter:
|
||||
* Returns <tt>true</tt> if this set contains the specified char.
|
||||
*
|
||||
* @return <tt>true</tt> if this set contains the specified char.
|
||||
* @draft
|
||||
* Implement UnicodeMatcher::matches()
|
||||
*/
|
||||
virtual UBool contains(UChar c) const;
|
||||
|
||||
UMatchDegree matches(const Replaceable& text,
|
||||
int32_t& offset,
|
||||
int32_t limit,
|
||||
UBool incremental) const;
|
||||
|
||||
/**
|
||||
* Adds the specified range to this set if it is not already
|
||||
* present. If this set already contains the specified range,
|
||||
@ -761,12 +760,6 @@ private:
|
||||
// Implementation: Utility methods
|
||||
//----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the character after the given position, or '\uFFFE' if
|
||||
* there is none.
|
||||
*/
|
||||
static UChar charAfter(const UnicodeString& str, int32_t i);
|
||||
|
||||
void ensureCapacity(int32_t newLen);
|
||||
|
||||
void ensureBufferCapacity(int32_t newLen);
|
||||
|
36
icu4c/source/i18n/unifilt.cpp
Normal file
36
icu4c/source/i18n/unifilt.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/**
|
||||
* Default implementation of UnicodeMatcher::matches() for Unicode
|
||||
* filters. Matches a single 16-bit code unit at offset.
|
||||
*/
|
||||
UMatchDegree UnicodeFilter::matches(const Replaceable& text,
|
||||
int32_t& offset,
|
||||
int32_t limit,
|
||||
UBool incremental) const {
|
||||
UChar32 c;
|
||||
if (offset < limit &&
|
||||
contains(c = text.char32At(offset))) {
|
||||
offset += UTF_CHAR_LENGTH(c);
|
||||
return U_MATCH;
|
||||
}
|
||||
if (offset > limit &&
|
||||
contains(c = text.charAt(offset))) {
|
||||
offset -= UTF_CHAR_LENGTH(c);
|
||||
return U_MATCH;
|
||||
}
|
||||
if (incremental && offset == limit) {
|
||||
return U_PARTIAL_MATCH;
|
||||
}
|
||||
return U_MISMATCH;
|
||||
}
|
Loading…
Reference in New Issue
Block a user