ICU-1781 add isNormalized()

X-SVN-Rev: 8852
This commit is contained in:
Markus Scherer 2002-06-12 03:29:09 +00:00
parent 26242a8f3e
commit 38fff182a4
3 changed files with 79 additions and 14 deletions

View file

@ -191,18 +191,6 @@ Normalizer::normalize(const UnicodeString& source,
}
}
UNormalizationCheckResult
Normalizer::quickCheck(const UnicodeString& source,
UNormalizationMode mode,
UErrorCode &status) {
if(U_FAILURE(status)) {
return UNORM_MAYBE;
}
return unorm_quickCheck(source.getBuffer(), source.length(),
mode, &status);
}
void
Normalizer::compose(const UnicodeString& source,
UBool compat, int32_t options,

View file

@ -265,13 +265,38 @@ public:
* results.
* @param source string for determining if it is in a normalized format
* @paran mode normalization format
* @param status A pointer to a UErrorCode to receive any errors
* @param status A reference to a UErrorCode to receive any errors
* @return UNORM_YES, UNORM_NO or UNORM_MAYBE
*
* @see isNormalized
* @draft ICU 2.0
*/
static UNormalizationCheckResult
static inline UNormalizationCheckResult
quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
/**
* Test if a string is in a given normalization form.
* This is semantically equivalent to source.equals(normalize(source, mode)) .
*
* Unlike unorm_quickCheck(), this function returns a definitive result,
* never a "maybe".
* For NFD, NFKD, and FCD, both functions work exactly the same.
* For NFC and NFKC where quickCheck may return "maybe", this function will
* perform further tests to arrive at a TRUE/FALSE result.
*
* @param src String that is to be tested if it is in a normalization format.
* @paran mode Which normalization form to test for.
* @param errorCode ICU error code in/out parameter.
* Must fulfill U_SUCCESS before the function call.
* @return Boolean value indicating whether the source string is in the
* "mode" normalization form.
*
* @see quickCheck
* @draft ICU 2.2
*/
static inline UBool
isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
/*
* Concatenate normalized strings, making sure that the result is normalized as well.
*
@ -1044,6 +1069,30 @@ Normalizer::quickCheck(const UnicodeString& source,
return quickCheck(source, getUNormalizationMode(mode, status), status);
}
inline UNormalizationCheckResult
Normalizer::quickCheck(const UnicodeString& source,
UNormalizationMode mode,
UErrorCode &status) {
if(U_FAILURE(status)) {
return UNORM_MAYBE;
}
return unorm_quickCheck(source.getBuffer(), source.length(),
mode, &status);
}
inline UBool
Normalizer::isNormalized(const UnicodeString& source,
UNormalizationMode mode,
UErrorCode &status) {
if(U_FAILURE(status)) {
return FALSE;
}
return unorm_isNormalized(source.getBuffer(), source.length(),
mode, &status);
}
inline int32_t
Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
uint32_t options,

View file

@ -254,6 +254,8 @@ typedef enum UNormalizationCheckResult {
* @paran mode which normalization form to test for
* @param status a pointer to a UErrorCode to receive any errors
* @return UNORM_YES, UNORM_NO or UNORM_MAYBE
*
* @see unorm_isNormalized
* @stable
*/
U_CAPI UNormalizationCheckResult U_EXPORT2
@ -261,6 +263,32 @@ unorm_quickCheck(const UChar *source, int32_t sourcelength,
UNormalizationMode mode,
UErrorCode *status);
/**
* Test if a string is in a given normalization form.
* This is semantically equivalent to source.equals(normalize(source, mode)) .
*
* Unlike unorm_quickCheck(), this function returns a definitive result,
* never a "maybe".
* For NFD, NFKD, and FCD, both functions work exactly the same.
* For NFC and NFKC where quickCheck may return "maybe", this function will
* perform further tests to arrive at a TRUE/FALSE result.
*
* @param src String that is to be tested if it is in a normalization format.
* @param srcLength Length of source to test, or -1 if NUL-terminated.
* @paran mode Which normalization form to test for.
* @param pErrorCode ICU error code in/out parameter.
* Must fulfill U_SUCCESS before the function call.
* @return Boolean value indicating whether the source string is in the
* "mode" normalization form.
*
* @see unorm_quickCheck
* @draft ICU 2.2
*/
U_CAPI UBool U_EXPORT2
unorm_isNormalized(const UChar *src, int32_t srcLength,
UNormalizationMode mode,
UErrorCode *pErrorCode);
/**
* Iterative normalization forward.
* This function (together with unorm_previous) is somewhat