ICU4C 79
Loading...
Searching...
No Matches
normlzr.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4 ********************************************************************
5 * COPYRIGHT:
6 * Copyright (c) 1996-2015, International Business Machines Corporation and
7 * others. All Rights Reserved.
8 ********************************************************************
9 */
10
11#ifndef NORMLZR_H
12#define NORMLZR_H
13
14#include "unicode/utypes.h"
15
16#if U_SHOW_CPLUSPLUS_API
17
22
23#if !UCONFIG_NO_NORMALIZATION
24
25#include "unicode/chariter.h"
26#include "unicode/normalizer2.h"
27#include "unicode/unistr.h"
28#include "unicode/unorm.h"
29#include "unicode/uobject.h"
30
31U_NAMESPACE_BEGIN
137public:
138#ifndef U_HIDE_DEPRECATED_API
144 enum {
145 DONE=0xffff
146 };
147
148 // Constructors
149
161
173 Normalizer(ConstChar16Ptr str U_LIFETIME_BOUND, int32_t length, UNormalizationMode mode);
174
186#endif /* U_HIDE_DEPRECATED_API */
187
188#ifndef U_FORCE_HIDE_DEPRECATED_API
194 Normalizer(const Normalizer& copy);
195
200 virtual ~Normalizer();
201#endif // U_FORCE_HIDE_DEPRECATED_API
202
203 //-------------------------------------------------------------------------
204 // Static utility methods
205 //-------------------------------------------------------------------------
206
207#ifndef U_HIDE_DEPRECATED_API
222 static void U_EXPORT2 normalize(const UnicodeString& source,
223 UNormalizationMode mode, int32_t options,
224 UnicodeString& result,
225 UErrorCode &status);
226
244 static void U_EXPORT2 compose(const UnicodeString& source,
245 UBool compat, int32_t options,
246 UnicodeString& result,
247 UErrorCode &status);
248
266 static void U_EXPORT2 decompose(const UnicodeString& source,
267 UBool compat, int32_t options,
268 UnicodeString& result,
269 UErrorCode &status);
270
291 static inline UNormalizationCheckResult
292 quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
293
308 quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
309
330 static inline UBool
331 isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
332
348 static UBool
349 isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
350
380 static UnicodeString& U_EXPORT2
382 const UnicodeString& right,
383 UnicodeString& result U_LIFETIME_BOUND,
385 int32_t options,
386 UErrorCode& errorCode);
387#endif /* U_HIDE_DEPRECATED_API */
388
453 static inline int32_t
454 compare(const UnicodeString &s1, const UnicodeString &s2,
455 uint32_t options,
456 UErrorCode &errorCode);
457
458#ifndef U_HIDE_DEPRECATED_API
459 //-------------------------------------------------------------------------
460 // Iteration API
461 //-------------------------------------------------------------------------
462
472
482
492
508
524
534 void setIndexOnly(int32_t index);
535
541 void reset();
542
557 int32_t getIndex() const;
558
567 int32_t startIndex() const;
568
579 int32_t endIndex() const;
580
589 bool operator==(const Normalizer& that) const;
590
599 inline bool operator!=(const Normalizer& that) const;
600
608
615 int32_t hashCode() const;
616
617 //-------------------------------------------------------------------------
618 // Property access methods
619 //-------------------------------------------------------------------------
620
637
649
666 void setOption(int32_t option,
667 UBool value);
668
679 UBool getOption(int32_t option) const;
680
689 void setText(const UnicodeString& newText,
690 UErrorCode &status);
691
700 void setText(const CharacterIterator& newText,
701 UErrorCode &status);
702
713 int32_t length,
714 UErrorCode &status);
721 void getText(UnicodeString& result);
722
728 static UClassID U_EXPORT2 getStaticClassID();
729#endif /* U_HIDE_DEPRECATED_API */
730
731#ifndef U_FORCE_HIDE_DEPRECATED_API
737 virtual UClassID getDynamicClassID() const override;
738#endif // U_FORCE_HIDE_DEPRECATED_API
739
740private:
741 //-------------------------------------------------------------------------
742 // Private functions
743 //-------------------------------------------------------------------------
744
745 Normalizer() = delete; // default constructor not implemented
746 Normalizer &operator=(const Normalizer &that) = delete; // assignment operator not implemented
747
748 // Private utility methods for iteration
749 // For documentation, see the source code
750 UBool nextNormalize();
751 UBool previousNormalize();
752
753 void init();
754 void clearBuffer();
755
756 //-------------------------------------------------------------------------
757 // Private data
758 //-------------------------------------------------------------------------
759
760 FilteredNormalizer2*fFilteredNorm2; // owned if not nullptr
761 const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
762 UNormalizationMode fUMode; // deprecated
763 int32_t fOptions;
764
765 // The input text and our position in it
766 CharacterIterator *text;
767
768 // The normalization buffer is the result of normalization
769 // of the source in [currentIndex..nextIndex[ .
770 int32_t currentIndex, nextIndex;
771
772 // A buffer for holding intermediate results
773 UnicodeString buffer;
774 int32_t bufferPos;
775};
776
777//-------------------------------------------------------------------------
778// Inline implementations
779//-------------------------------------------------------------------------
780
781#ifndef U_HIDE_DEPRECATED_API
782inline bool
783Normalizer::operator!= (const Normalizer& other) const
784{ return ! operator==(other); }
785
789 UErrorCode &status) {
790 return quickCheck(source, mode, 0, status);
791}
792
793inline UBool
796 UErrorCode &status) {
797 return isNormalized(source, mode, 0, status);
798}
799#endif /* U_HIDE_DEPRECATED_API */
800
801inline int32_t
803 uint32_t options,
804 UErrorCode &errorCode) {
805 // all argument checking is done in unorm_compare
806 return unorm_compare(toUCharPtr(s1.getBuffer()), s1.length(),
807 toUCharPtr(s2.getBuffer()), s2.length(),
808 options,
809 &errorCode);
810}
811
812U_NAMESPACE_END
813
814#endif /* #if !UCONFIG_NO_NORMALIZATION */
815
816#endif // NORMLZR_H
817
818#endif /* U_SHOW_CPLUSPLUS_API */
C++ API: Character Iterator.
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:363
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition char16ptr.h:156
Normalization filtered by a UnicodeSet.
Unicode normalization functionality for standard Unicode normalization or for using custom mapping ta...
Definition normalizer2.h:85
bool operator==(const Normalizer &that) const
Returns true when both iterators refer to the same character in the same input text.
UChar32 next()
Return the next character in the normalized text.
static void decompose(const UnicodeString &source, UBool compat, int32_t options, UnicodeString &result, UErrorCode &status)
Static method to decompose a UnicodeString.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
void setMode(UNormalizationMode newMode)
Set the normalization mode for this object.
virtual ~Normalizer()
Destructor.
void setText(const UnicodeString &newText, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
int32_t startIndex() const
Retrieve the index of the start of the input text.
int32_t getIndex() const
Retrieve the current iteration position in the input text that is being normalized.
UChar32 previous()
Return the previous character in the normalized text and decrement.
UNormalizationMode getUMode() const
Return the normalization mode for this object.
UBool getOption(int32_t option) const
Determine whether an option is turned on or off.
void setText(ConstChar16Ptr newText, int32_t length, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
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...
UChar32 last()
Return the last character in the normalized text.
static UBool isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode)
Test if a string is in a given normalization form.
Definition normlzr.h:794
Normalizer(const Normalizer &copy)
Copy constructor.
Normalizer(const UnicodeString &str, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of a given string.
void setText(const CharacterIterator &newText, UErrorCode &status)
Set the input text over which this Normalizer will iterate.
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...
Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of a given string.
void setOption(int32_t option, UBool value)
Set options that affect this Normalizer's operation.
UChar32 first()
Return the first character in the normalized text.
static void normalize(const UnicodeString &source, UNormalizationMode mode, int32_t options, UnicodeString &result, UErrorCode &status)
Normalizes a UnicodeString according to the specified normalization mode.
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.
Normalizer(const CharacterIterator &iter, UNormalizationMode mode)
Creates a new Normalizer object for iterating over the normalized form of the given text.
void reset()
Reset the index to the beginning of the text.
static UNormalizationCheckResult quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status)
Performing quick check on a string, to quickly determine if the string is in a particular normalizati...
Definition normlzr.h:787
int32_t endIndex() const
Retrieve the index of the end of the input text.
int32_t hashCode() const
Generates a hash code for this iterator.
void getText(UnicodeString &result)
Copies the input text into the UnicodeString argument.
static int32_t compare(const UnicodeString &s1, const UnicodeString &s2, uint32_t options, UErrorCode &errorCode)
Compare two strings for canonical equivalence.
Definition normlzr.h:802
void setIndexOnly(int32_t index)
Set the iteration position in the input text that is being normalized, without any immediate normaliz...
static void compose(const UnicodeString &source, UBool compat, int32_t options, UnicodeString &result, UErrorCode &status)
Compose a UnicodeString.
Normalizer * clone() const
Returns a pointer to a new Normalizer that is a clone of this one.
UChar32 current()
Return the current character in the normalized text.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
int32_t length() const
Return the length of the UnicodeString object.
Definition unistr.h:4269
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
C++ API: New API for Unicode Normalization.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:449
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
C++ API: Unicode String.
UNormalizationCheckResult
Result values for normalization quick check functions.
Definition unorm2.h:97
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.
C API: Unicode Normalization.
UNormalizationMode
Constants for normalization modes.
Definition unorm.h:140
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:315