ICU-1438 add Normalizer::compare
X-SVN-Rev: 8699
This commit is contained in:
parent
24cbc1c0cf
commit
730faa0879
@ -307,6 +307,70 @@ public:
|
||||
UNormalizationMode mode, int32_t options,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
/**
|
||||
* Compare two strings for canonical equivalence.
|
||||
* Further options include case-insensitive comparison and
|
||||
* code point order (as opposed to code unit order).
|
||||
*
|
||||
* Canonical equivalence between two strings is defined as their normalized
|
||||
* forms (NFD or NFC) being identical.
|
||||
* This function compares strings incrementally instead of normalizing
|
||||
* (and optionally case-folding) both strings entirely,
|
||||
* improving performance significantly.
|
||||
*
|
||||
* Bulk normalization is only necessary if the strings do not fulfill the FCD
|
||||
* conditions. Only in this case, and only if the strings are relatively long,
|
||||
* is memory allocated temporarily.
|
||||
* For FCD strings and short non-FCD strings there is no memory allocation.
|
||||
*
|
||||
* Semantically, this is equivalent to
|
||||
* strcmp[CodePointOrder](foldCase(NFD(s1)), foldCase(NFD(s2)))
|
||||
* where code point order and foldCase are all optional.
|
||||
*
|
||||
* @param s1 First source string.
|
||||
* @param s2 Second source string.
|
||||
*
|
||||
* @param options A bit set of options:
|
||||
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
|
||||
* Case-sensitive comparison in code unit order, and the input strings
|
||||
* are quick-checked for FCD.
|
||||
*
|
||||
* - UNORM_INPUT_IS_FCD
|
||||
* Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
|
||||
* If not set, the function will quickCheck for FCD
|
||||
* and normalize if necessary.
|
||||
*
|
||||
* - U_COMPARE_CODE_POINT_ORDER
|
||||
* Set to choose code point order instead of code unit order
|
||||
* (see u_strCompare for details).
|
||||
*
|
||||
* - U_COMPARE_IGNORE_CASE
|
||||
* Set to compare strings case-insensitively using case folding,
|
||||
* instead of case-sensitively.
|
||||
* If set, then the following case folding options are used.
|
||||
*
|
||||
* - Options as used with case-insensitive comparisons, currently:
|
||||
*
|
||||
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
|
||||
* (see u_strCaseCompare for details)
|
||||
*
|
||||
* @param errorCode ICU error code in/out parameter.
|
||||
* Must fulfill U_SUCCESS before the function call.
|
||||
* @return <0 or 0 or >0 as usual for string comparisons
|
||||
*
|
||||
* @see unorm_compare
|
||||
* @see normalize
|
||||
* @see UNORM_FCD
|
||||
* @see u_strCompare
|
||||
* @see u_strCaseCompare
|
||||
*
|
||||
* @draft ICU 2.2
|
||||
*/
|
||||
static inline int32_t
|
||||
compare(const UnicodeString &s1, const UnicodeString &s2,
|
||||
uint32_t options,
|
||||
UErrorCode &errorCode);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Iteration API
|
||||
//-------------------------------------------------------------------------
|
||||
@ -977,6 +1041,17 @@ Normalizer::quickCheck(const UnicodeString& source,
|
||||
return quickCheck(source, getUNormalizationMode(mode, status), status);
|
||||
}
|
||||
|
||||
inline int32_t
|
||||
Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
|
||||
uint32_t options,
|
||||
UErrorCode &errorCode) {
|
||||
// all argument checking is done in unorm_compare
|
||||
return unorm_compare(s1.getBuffer(), s1.length(),
|
||||
s2.getBuffer(), s2.length(),
|
||||
options,
|
||||
&errorCode);
|
||||
}
|
||||
|
||||
inline void
|
||||
Normalizer::setMode(EMode newMode) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user