normlzr.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:
* Copyright (c) 1996-2015, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*/
#ifndef NORMLZR_H
#define NORMLZR_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_NORMALIZATION
#include "unicode/chariter.h"
#include "unicode/normalizer2.h"
#include "unicode/unistr.h"
#include "unicode/unorm.h"
#include "unicode/uobject.h"
U_NAMESPACE_BEGIN
class U_COMMON_API Normalizer : public UObject {
public:
#ifndef U_HIDE_DEPRECATED_API
enum {
DONE=0xffff
};
// Constructors
Normalizer(const UnicodeString& str, UNormalizationMode mode);
Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode);
Normalizer(const CharacterIterator& iter, UNormalizationMode mode);
#endif /* U_HIDE_DEPRECATED_API */
#ifndef U_FORCE_HIDE_DEPRECATED_API
Normalizer(const Normalizer& copy);
virtual ~Normalizer();
#endif // U_FORCE_HIDE_DEPRECATED_API
//-------------------------------------------------------------------------
// Static utility methods
//-------------------------------------------------------------------------
#ifndef U_HIDE_DEPRECATED_API
static void U_EXPORT2 normalize(const UnicodeString& source,
UNormalizationMode mode, int32_t options,
UnicodeString& result,
UErrorCode &status);
static void U_EXPORT2 compose(const UnicodeString& source,
UBool compat, int32_t options,
UnicodeString& result,
UErrorCode &status);
static void U_EXPORT2 decompose(const UnicodeString& source,
UBool compat, int32_t options,
UnicodeString& result,
UErrorCode &status);
static inline UNormalizationCheckResult
quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
static UNormalizationCheckResult
quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
static inline UBool
isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
static UBool
isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
static UnicodeString &
U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right,
UnicodeString &result,
UNormalizationMode mode, int32_t options,
UErrorCode &errorCode);
#endif /* U_HIDE_DEPRECATED_API */
static inline int32_t
compare(const UnicodeString &s1, const UnicodeString &s2,
uint32_t options,
UErrorCode &errorCode);
#ifndef U_HIDE_DEPRECATED_API
//-------------------------------------------------------------------------
// Iteration API
//-------------------------------------------------------------------------
UChar32 current();
UChar32 first();
UChar32 last();
UChar32 next();
UChar32 previous();
void setIndexOnly(int32_t index);
void reset();
int32_t getIndex() const;
int32_t startIndex() const;
int32_t endIndex() const;
bool operator==(const Normalizer& that) const;
inline bool operator!=(const Normalizer& that) const;
Normalizer* clone() const;
int32_t hashCode() const;
//-------------------------------------------------------------------------
// Property access methods
//-------------------------------------------------------------------------
void setMode(UNormalizationMode newMode);
UNormalizationMode getUMode() const;
void setOption(int32_t option,
UBool value);
UBool getOption(int32_t option) const;
void setText(const UnicodeString& newText,
UErrorCode &status);
void setText(const CharacterIterator& newText,
UErrorCode &status);
void setText(ConstChar16Ptr newText,
int32_t length,
UErrorCode &status);
void getText(UnicodeString& result);
static UClassID U_EXPORT2 getStaticClassID();
#endif /* U_HIDE_DEPRECATED_API */
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual UClassID getDynamicClassID() const override;
#endif // U_FORCE_HIDE_DEPRECATED_API
private:
//-------------------------------------------------------------------------
// Private functions
//-------------------------------------------------------------------------
Normalizer() = delete; // default constructor not implemented
Normalizer &operator=(const Normalizer &that) = delete; // assignment operator not implemented
// Private utility methods for iteration
// For documentation, see the source code
UBool nextNormalize();
UBool previousNormalize();
void init();
void clearBuffer();
//-------------------------------------------------------------------------
// Private data
//-------------------------------------------------------------------------
FilteredNormalizer2*fFilteredNorm2; // owned if not nullptr
const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
UNormalizationMode fUMode; // deprecated
int32_t fOptions;
// The input text and our position in it
CharacterIterator *text;
// The normalization buffer is the result of normalization
// of the source in [currentIndex..nextIndex[ .
int32_t currentIndex, nextIndex;
// A buffer for holding intermediate results
UnicodeString buffer;
int32_t bufferPos;
};
//-------------------------------------------------------------------------
// Inline implementations
//-------------------------------------------------------------------------
#ifndef U_HIDE_DEPRECATED_API
inline bool
Normalizer::operator!= (const Normalizer& other) const
{ return ! operator==(other); }
inline UNormalizationCheckResult
Normalizer::quickCheck(const UnicodeString& source,
UNormalizationMode mode,
UErrorCode &status) {
return quickCheck(source, mode, 0, status);
}
inline UBool
Normalizer::isNormalized(const UnicodeString& source,
UNormalizationMode mode,
UErrorCode &status) {
return isNormalized(source, mode, 0, status);
}
#endif /* U_HIDE_DEPRECATED_API */
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(toUCharPtr(s1.getBuffer()), s1.length(),
toUCharPtr(s2.getBuffer()), s2.length(),
options,
&errorCode);
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_NORMALIZATION */
#endif // NORMLZR_H
#endif /* U_SHOW_CPLUSPLUS_API */
chariter.h
C++ API: Character Iterator.
icu::CharacterIterator
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:361
icu::ConstChar16Ptr
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:149
icu::FilteredNormalizer2
Normalization filtered by a UnicodeSet.
Definition: normalizer2.h:521
icu::Normalizer2
Unicode normalization functionality for standard Unicode normalization or for using custom mapping ta...
Definition: normalizer2.h:85
icu::Normalizer
Old Unicode normalization API.
Definition: normlzr.h:136
icu::Normalizer::operator==
bool operator==(const Normalizer &that) const
Returns true when both iterators refer to the same character in the same input text.
icu::Normalizer::next
UChar32 next()
Return the next character in the normalized text.
icu::Normalizer::decompose
static void decompose(const UnicodeString &source, UBool compat, int32_t options, UnicodeString &result, UErrorCode &status)
Static method to decompose a UnicodeString.
icu::Normalizer::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::Normalizer::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::Normalizer::setMode
void setMode(UNormalizationMode newMode)
Set the normalization mode for this object.
icu::Normalizer::~Normalizer
virtual ~Normalizer()
Destructor.
icu::Normalizer::setText
void setText(const UnicodeString &newText, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
icu::Normalizer::startIndex
int32_t startIndex() const
Retrieve the index of the start of the input text.
icu::Normalizer::getIndex
int32_t getIndex() const
Retrieve the current iteration position in the input text that is being normalized.
icu::Normalizer::previous
UChar32 previous()
Return the previous character in the normalized text and decrement.
icu::Normalizer::getUMode
UNormalizationMode getUMode() const
Return the normalization mode for this object.
icu::Normalizer::getOption
UBool getOption(int32_t option) const
Determine whether an option is turned on or off.
icu::Normalizer::setText
void setText(ConstChar16Ptr newText, int32_t length, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
icu::Normalizer::isNormalized
static UBool isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode)
Test if a string is in a given normalization form; same as the other version of isNormalized but take...
icu::Normalizer::last
UChar32 last()
Return the last character in the normalized text.
icu::Normalizer::Normalizer
Normalizer(const Normalizer &copy)
Copy constructor.
icu::Normalizer::Normalizer
Normalizer(const UnicodeString &str, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of a given string.
icu::Normalizer::setText
void setText(const CharacterIterator &newText, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
icu::Normalizer::quickCheck
static UNormalizationCheckResult quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status)
Performing quick check on a string; same as the other version of quickCheck but takes an extra option...
icu::Normalizer::Normalizer
Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of a given string.
icu::Normalizer::setOption
void setOption(int32_t option, UBool value)
Set options that affect this Normalizer's operation.
icu::Normalizer::first
UChar32 first()
Return the first character in the normalized text.
icu::Normalizer::normalize
static void normalize(const UnicodeString &source, UNormalizationMode mode, int32_t options, UnicodeString &result, UErrorCode &status)
Normalizes a UnicodeString according to the specified normalization mode.
icu::Normalizer::Normalizer
Normalizer(const CharacterIterator &iter, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of the given text.
icu::Normalizer::reset
void reset()
Reset the index to the beginning of the text.
icu::Normalizer::clone
Normalizer * clone() const
Returns a pointer to a new Normalizer that is a clone of this one.
icu::Normalizer::endIndex
int32_t endIndex() const
Retrieve the index of the end of the input text.
icu::Normalizer::hashCode
int32_t hashCode() const
Generates a hash code for this iterator.
icu::Normalizer::concatenate
static UnicodeString & concatenate(const UnicodeString &left, const UnicodeString &right, UnicodeString &result, UNormalizationMode mode, int32_t options, UErrorCode &errorCode)
Concatenate normalized strings, making sure that the result is normalized as well.
icu::Normalizer::getText
void getText(UnicodeString &result)
Copies the input text into the UnicodeString argument.
icu::Normalizer::setIndexOnly
void setIndexOnly(int32_t index)
Set the iteration position in the input text that is being normalized, without any immediate normaliz...
icu::Normalizer::compose
static void compose(const UnicodeString &source, UBool compat, int32_t options, UnicodeString &result, UErrorCode &status)
Compose a UnicodeString.
icu::Normalizer::current
UChar32 current()
Return the current character in the normalized text.
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::UnicodeString::length
int32_t length() const
Return the length of the UnicodeString object.
Definition: unistr.h:3901
icu::UnicodeString::getBuffer
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
icu::toUCharPtr
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition: char16ptr.h:260
normalizer2.h
C++ API: New API for Unicode Normalization.
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
unistr.h
C++ API: Unicode String.
UNormalizationCheckResult
UNormalizationCheckResult
Result values for normalization quick check functions.
Definition: unorm2.h:97
unorm_compare
U_CAPI int32_t unorm_compare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, uint32_t options, UErrorCode *pErrorCode)
Compares two strings for canonical equivalence.
unorm.h
C API: Unicode Normalization.
UNormalizationMode
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:140
uobject.h
C++ API: Common ICU base class UObject.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
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:415
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:300