normalizer2.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
* Copyright (C) 2009-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: normalizer2.h
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2009nov22
* created by: Markus W. Scherer
*/
#ifndef __NORMALIZER2_H__
#define __NORMALIZER2_H__
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_NORMALIZATION
#include "unicode/stringpiece.h"
#include "unicode/uniset.h"
#include "unicode/unistr.h"
#include "unicode/unorm2.h"
U_NAMESPACE_BEGIN
class ByteSink;
class U_COMMON_API Normalizer2 : public UObject {
public:
~Normalizer2();
static const Normalizer2 *
getNFCInstance(UErrorCode &errorCode);
static const Normalizer2 *
getNFDInstance(UErrorCode &errorCode);
static const Normalizer2 *
getNFKCInstance(UErrorCode &errorCode);
static const Normalizer2 *
getNFKDInstance(UErrorCode &errorCode);
static const Normalizer2 *
getNFKCCasefoldInstance(UErrorCode &errorCode);
static const Normalizer2 *
getNFKCSimpleCasefoldInstance(UErrorCode &errorCode);
static const Normalizer2 *
getInstance(const char *packageName,
const char *name,
UNormalization2Mode mode,
UErrorCode &errorCode);
UnicodeString
normalize(const UnicodeString &src, UErrorCode &errorCode) const {
UnicodeString result;
normalize(src, result, errorCode);
return result;
}
virtual UnicodeString &
normalize(const UnicodeString &src,
UnicodeString &dest,
UErrorCode &errorCode) const = 0;
virtual void
normalizeUTF8(uint32_t options, StringPiece src, ByteSink &sink,
Edits *edits, UErrorCode &errorCode) const;
virtual UnicodeString &
normalizeSecondAndAppend(UnicodeString &first,
const UnicodeString &second,
UErrorCode &errorCode) const = 0;
virtual UnicodeString &
append(UnicodeString &first,
const UnicodeString &second,
UErrorCode &errorCode) const = 0;
virtual UBool
getDecomposition(UChar32 c, UnicodeString &decomposition) const = 0;
virtual UBool
getRawDecomposition(UChar32 c, UnicodeString &decomposition) const;
virtual UChar32
composePair(UChar32 a, UChar32 b) const;
virtual uint8_t
getCombiningClass(UChar32 c) const;
virtual UBool
isNormalized(const UnicodeString &s, UErrorCode &errorCode) const = 0;
virtual UBool
isNormalizedUTF8(StringPiece s, UErrorCode &errorCode) const;
virtual UNormalizationCheckResult
quickCheck(const UnicodeString &s, UErrorCode &errorCode) const = 0;
virtual int32_t
spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const = 0;
virtual UBool hasBoundaryBefore(UChar32 c) const = 0;
virtual UBool hasBoundaryAfter(UChar32 c) const = 0;
virtual UBool isInert(UChar32 c) const = 0;
};
class U_COMMON_API FilteredNormalizer2 : public Normalizer2 {
public:
FilteredNormalizer2(const Normalizer2 &n2, const UnicodeSet &filterSet) :
norm2(n2), set(filterSet) {}
~FilteredNormalizer2();
virtual UnicodeString &
normalize(const UnicodeString &src,
UnicodeString &dest,
UErrorCode &errorCode) const override;
virtual void
normalizeUTF8(uint32_t options, StringPiece src, ByteSink &sink,
Edits *edits, UErrorCode &errorCode) const override;
virtual UnicodeString &
normalizeSecondAndAppend(UnicodeString &first,
const UnicodeString &second,
UErrorCode &errorCode) const override;
virtual UnicodeString &
append(UnicodeString &first,
const UnicodeString &second,
UErrorCode &errorCode) const override;
virtual UBool
getDecomposition(UChar32 c, UnicodeString &decomposition) const override;
virtual UBool
getRawDecomposition(UChar32 c, UnicodeString &decomposition) const override;
virtual UChar32
composePair(UChar32 a, UChar32 b) const override;
virtual uint8_t
getCombiningClass(UChar32 c) const override;
virtual UBool
isNormalized(const UnicodeString &s, UErrorCode &errorCode) const override;
virtual UBool
isNormalizedUTF8(StringPiece s, UErrorCode &errorCode) const override;
virtual UNormalizationCheckResult
quickCheck(const UnicodeString &s, UErrorCode &errorCode) const override;
virtual int32_t
spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const override;
virtual UBool hasBoundaryBefore(UChar32 c) const override;
virtual UBool hasBoundaryAfter(UChar32 c) const override;
virtual UBool isInert(UChar32 c) const override;
private:
UnicodeString &
normalize(const UnicodeString &src,
UnicodeString &dest,
USetSpanCondition spanCondition,
UErrorCode &errorCode) const;
void
normalizeUTF8(uint32_t options, const char *src, int32_t length,
ByteSink &sink, Edits *edits,
USetSpanCondition spanCondition,
UErrorCode &errorCode) const;
UnicodeString &
normalizeSecondAndAppend(UnicodeString &first,
const UnicodeString &second,
UBool doNormalize,
UErrorCode &errorCode) const;
const Normalizer2 &norm2;
const UnicodeSet &set;
};
U_NAMESPACE_END
#endif // !UCONFIG_NO_NORMALIZATION
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // __NORMALIZER2_H__
icu::ByteSink
A ByteSink can be filled with bytes.
Definition bytestream.h:53
icu::Edits
Records lengths of string edits but not replacement text.
Definition edits.h:80
icu::FilteredNormalizer2
Normalization filtered by a UnicodeSet.
Definition normalizer2.h:519
icu::FilteredNormalizer2::isNormalizedUTF8
virtual UBool isNormalizedUTF8(StringPiece s, UErrorCode &errorCode) const override
Tests if the UTF-8 string is normalized.
icu::FilteredNormalizer2::~FilteredNormalizer2
~FilteredNormalizer2()
Destructor.
icu::FilteredNormalizer2::quickCheck
virtual UNormalizationCheckResult quickCheck(const UnicodeString &s, UErrorCode &errorCode) const override
Tests if the string is normalized.
icu::FilteredNormalizer2::isInert
virtual UBool isInert(UChar32 c) const override
Tests if the character is normalization-inert.
icu::FilteredNormalizer2::composePair
virtual UChar32 composePair(UChar32 a, UChar32 b) const override
Performs pairwise composition of a & b and returns the composite if there is one.
icu::FilteredNormalizer2::getDecomposition
virtual UBool getDecomposition(UChar32 c, UnicodeString &decomposition) const override
Gets the decomposition mapping of c.
icu::FilteredNormalizer2::normalizeSecondAndAppend
virtual UnicodeString & normalizeSecondAndAppend(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const override
Appends the normalized form of the second string to the first string (merging them at the boundary) a...
icu::FilteredNormalizer2::isNormalized
virtual UBool isNormalized(const UnicodeString &s, UErrorCode &errorCode) const override
Tests if the string is normalized.
icu::FilteredNormalizer2::getRawDecomposition
virtual UBool getRawDecomposition(UChar32 c, UnicodeString &decomposition) const override
Gets the raw decomposition mapping of c.
icu::FilteredNormalizer2::getCombiningClass
virtual uint8_t getCombiningClass(UChar32 c) const override
Gets the combining class of c.
icu::FilteredNormalizer2::normalize
virtual UnicodeString & normalize(const UnicodeString &src, UnicodeString &dest, UErrorCode &errorCode) const override
Writes the normalized form of the source string to the destination string (replacing its contents) an...
icu::FilteredNormalizer2::normalizeUTF8
virtual void normalizeUTF8(uint32_t options, StringPiece src, ByteSink &sink, Edits *edits, UErrorCode &errorCode) const override
Normalizes a UTF-8 string and optionally records how source substrings relate to changed and unchange...
icu::FilteredNormalizer2::append
virtual UnicodeString & append(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const override
Appends the second string to the first string (merging them at the boundary) and returns the first st...
icu::FilteredNormalizer2::hasBoundaryBefore
virtual UBool hasBoundaryBefore(UChar32 c) const override
Tests if the character always has a normalization boundary before it, regardless of context.
icu::FilteredNormalizer2::FilteredNormalizer2
FilteredNormalizer2(const Normalizer2 &n2, const UnicodeSet &filterSet)
Constructs a filtered normalizer wrapping any Normalizer2 instance and a filter set.
Definition normalizer2.h:531
icu::FilteredNormalizer2::hasBoundaryAfter
virtual UBool hasBoundaryAfter(UChar32 c) const override
Tests if the character always has a normalization boundary after it, regardless of context.
icu::FilteredNormalizer2::spanQuickCheckYes
virtual int32_t spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const override
Returns the end of the normalized substring of the input string.
icu::LocalPointerBase
"Smart pointer" base class; do not use directly: use LocalPointer etc.
Definition localpointer.h:68
icu::Normalizer2
Unicode normalization functionality for standard Unicode normalization or for using custom mapping ta...
Definition normalizer2.h:85
icu::Normalizer2::getNFDInstance
static const Normalizer2 * getNFDInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for Unicode NFD normalization.
icu::Normalizer2::getDecomposition
virtual UBool getDecomposition(UChar32 c, UnicodeString &decomposition) const =0
Gets the decomposition mapping of c.
icu::Normalizer2::spanQuickCheckYes
virtual int32_t spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const =0
Returns the end of the normalized substring of the input string.
icu::Normalizer2::isNormalized
virtual UBool isNormalized(const UnicodeString &s, UErrorCode &errorCode) const =0
Tests if the string is normalized.
icu::Normalizer2::hasBoundaryBefore
virtual UBool hasBoundaryBefore(UChar32 c) const =0
Tests if the character always has a normalization boundary before it, regardless of context.
icu::Normalizer2::~Normalizer2
~Normalizer2()
Destructor.
icu::Normalizer2::composePair
virtual UChar32 composePair(UChar32 a, UChar32 b) const
Performs pairwise composition of a & b and returns the composite if there is one.
icu::Normalizer2::getInstance
static const Normalizer2 * getInstance(const char *packageName, const char *name, UNormalization2Mode mode, UErrorCode &errorCode)
Returns a Normalizer2 instance which uses the specified data file (packageName/name similar to ucnv_o...
icu::Normalizer2::append
virtual UnicodeString & append(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const =0
Appends the second string to the first string (merging them at the boundary) and returns the first st...
icu::Normalizer2::getNFKDInstance
static const Normalizer2 * getNFKDInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for Unicode NFKD normalization.
icu::Normalizer2::normalize
virtual UnicodeString & normalize(const UnicodeString &src, UnicodeString &dest, UErrorCode &errorCode) const =0
Writes the normalized form of the source string to the destination string (replacing its contents) an...
icu::Normalizer2::getNFKCCasefoldInstance
static const Normalizer2 * getNFKCCasefoldInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for Unicode toNFKC_Casefold() normalization which is equivalent to app...
icu::Normalizer2::normalize
UnicodeString normalize(const UnicodeString &src, UErrorCode &errorCode) const
Returns the normalized form of the source string.
Definition normalizer2.h:221
icu::Normalizer2::quickCheck
virtual UNormalizationCheckResult quickCheck(const UnicodeString &s, UErrorCode &errorCode) const =0
Tests if the string is normalized.
icu::Normalizer2::getNFCInstance
static const Normalizer2 * getNFCInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for Unicode NFC normalization.
icu::Normalizer2::hasBoundaryAfter
virtual UBool hasBoundaryAfter(UChar32 c) const =0
Tests if the character always has a normalization boundary after it, regardless of context.
icu::Normalizer2::getCombiningClass
virtual uint8_t getCombiningClass(UChar32 c) const
Gets the combining class of c.
icu::Normalizer2::isInert
virtual UBool isInert(UChar32 c) const =0
Tests if the character is normalization-inert.
icu::Normalizer2::getNFKCInstance
static const Normalizer2 * getNFKCInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for Unicode NFKC normalization.
icu::Normalizer2::normalizeUTF8
virtual void normalizeUTF8(uint32_t options, StringPiece src, ByteSink &sink, Edits *edits, UErrorCode &errorCode) const
Normalizes a UTF-8 string and optionally records how source substrings relate to changed and unchange...
icu::Normalizer2::isNormalizedUTF8
virtual UBool isNormalizedUTF8(StringPiece s, UErrorCode &errorCode) const
Tests if the UTF-8 string is normalized.
icu::Normalizer2::getRawDecomposition
virtual UBool getRawDecomposition(UChar32 c, UnicodeString &decomposition) const
Gets the raw decomposition mapping of c.
icu::Normalizer2::getNFKCSimpleCasefoldInstance
static const Normalizer2 * getNFKCSimpleCasefoldInstance(UErrorCode &errorCode)
Returns a Normalizer2 instance for a variant of Unicode toNFKC_Casefold() normalization which is equi...
icu::Normalizer2::normalizeSecondAndAppend
virtual UnicodeString & normalizeSecondAndAppend(UnicodeString &first, const UnicodeString &second, UErrorCode &errorCode) const =0
Appends the normalized form of the second string to the first string (merging them at the boundary) a...
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:61
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition uniset.h:285
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:427
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
uniset.h
C++ API: Unicode Set.
unistr.h
C++ API: Unicode String.
unorm2.h
C API: New API for Unicode Normalization.
UNormalizationCheckResult
UNormalizationCheckResult
Result values for normalization quick check functions.
Definition unorm2.h:97
UNormalization2Mode
UNormalization2Mode
Constants for normalization modes.
Definition unorm2.h:48
USetSpanCondition
USetSpanCondition
Argument values for whether span() and similar functions continue while the current character is cont...
Definition uset.h:185
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315