|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ******************************************************************** 00005 * COPYRIGHT: 00006 * Copyright (c) 1996-2015, International Business Machines Corporation and 00007 * others. All Rights Reserved. 00008 ******************************************************************** 00009 */ 00010 00011 #ifndef NORMLZR_H 00012 #define NORMLZR_H 00013 00014 #include "unicode/utypes.h" 00015 00016 #if U_SHOW_CPLUSPLUS_API 00017 00023 #if !UCONFIG_NO_NORMALIZATION 00024 00025 #include "unicode/chariter.h" 00026 #include "unicode/normalizer2.h" 00027 #include "unicode/unistr.h" 00028 #include "unicode/unorm.h" 00029 #include "unicode/uobject.h" 00030 00031 U_NAMESPACE_BEGIN 00136 class U_COMMON_API Normalizer : public UObject { 00137 public: 00138 #ifndef U_HIDE_DEPRECATED_API 00139 00144 enum { 00145 DONE=0xffff 00146 }; 00147 00148 // Constructors 00149 00160 Normalizer(const UnicodeString& str, UNormalizationMode mode); 00161 00173 Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode); 00174 00185 Normalizer(const CharacterIterator& iter, UNormalizationMode mode); 00186 #endif /* U_HIDE_DEPRECATED_API */ 00187 00188 #ifndef U_FORCE_HIDE_DEPRECATED_API 00189 00194 Normalizer(const Normalizer& copy); 00195 00200 virtual ~Normalizer(); 00201 #endif // U_FORCE_HIDE_DEPRECATED_API 00202 00203 //------------------------------------------------------------------------- 00204 // Static utility methods 00205 //------------------------------------------------------------------------- 00206 00207 #ifndef U_HIDE_DEPRECATED_API 00208 00222 static void U_EXPORT2 normalize(const UnicodeString& source, 00223 UNormalizationMode mode, int32_t options, 00224 UnicodeString& result, 00225 UErrorCode &status); 00226 00244 static void U_EXPORT2 compose(const UnicodeString& source, 00245 UBool compat, int32_t options, 00246 UnicodeString& result, 00247 UErrorCode &status); 00248 00266 static void U_EXPORT2 decompose(const UnicodeString& source, 00267 UBool compat, int32_t options, 00268 UnicodeString& result, 00269 UErrorCode &status); 00270 00291 static inline UNormalizationCheckResult 00292 quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status); 00293 00307 static UNormalizationCheckResult 00308 quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status); 00309 00330 static inline UBool 00331 isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode); 00332 00348 static UBool 00349 isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode); 00350 00380 static UnicodeString & 00381 U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right, 00382 UnicodeString &result, 00383 UNormalizationMode mode, int32_t options, 00384 UErrorCode &errorCode); 00385 #endif /* U_HIDE_DEPRECATED_API */ 00386 00451 static inline int32_t 00452 compare(const UnicodeString &s1, const UnicodeString &s2, 00453 uint32_t options, 00454 UErrorCode &errorCode); 00455 00456 #ifndef U_HIDE_DEPRECATED_API 00457 //------------------------------------------------------------------------- 00458 // Iteration API 00459 //------------------------------------------------------------------------- 00460 00469 UChar32 current(void); 00470 00479 UChar32 first(void); 00480 00489 UChar32 last(void); 00490 00505 UChar32 next(void); 00506 00521 UChar32 previous(void); 00522 00532 void setIndexOnly(int32_t index); 00533 00539 void reset(void); 00540 00555 int32_t getIndex(void) const; 00556 00565 int32_t startIndex(void) const; 00566 00577 int32_t endIndex(void) const; 00578 00587 bool operator==(const Normalizer& that) const; 00588 00597 inline bool operator!=(const Normalizer& that) const; 00598 00605 Normalizer* clone() const; 00606 00613 int32_t hashCode(void) const; 00614 00615 //------------------------------------------------------------------------- 00616 // Property access methods 00617 //------------------------------------------------------------------------- 00618 00634 void setMode(UNormalizationMode newMode); 00635 00646 UNormalizationMode getUMode(void) const; 00647 00664 void setOption(int32_t option, 00665 UBool value); 00666 00677 UBool getOption(int32_t option) const; 00678 00687 void setText(const UnicodeString& newText, 00688 UErrorCode &status); 00689 00698 void setText(const CharacterIterator& newText, 00699 UErrorCode &status); 00700 00710 void setText(ConstChar16Ptr newText, 00711 int32_t length, 00712 UErrorCode &status); 00719 void getText(UnicodeString& result); 00720 00726 static UClassID U_EXPORT2 getStaticClassID(); 00727 #endif /* U_HIDE_DEPRECATED_API */ 00728 00729 #ifndef U_FORCE_HIDE_DEPRECATED_API 00730 00735 virtual UClassID getDynamicClassID() const override; 00736 #endif // U_FORCE_HIDE_DEPRECATED_API 00737 00738 private: 00739 //------------------------------------------------------------------------- 00740 // Private functions 00741 //------------------------------------------------------------------------- 00742 00743 Normalizer() = delete; // default constructor not implemented 00744 Normalizer &operator=(const Normalizer &that) = delete; // assignment operator not implemented 00745 00746 // Private utility methods for iteration 00747 // For documentation, see the source code 00748 UBool nextNormalize(); 00749 UBool previousNormalize(); 00750 00751 void init(); 00752 void clearBuffer(void); 00753 00754 //------------------------------------------------------------------------- 00755 // Private data 00756 //------------------------------------------------------------------------- 00757 00758 FilteredNormalizer2*fFilteredNorm2; // owned if not nullptr 00759 const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2 00760 UNormalizationMode fUMode; // deprecated 00761 int32_t fOptions; 00762 00763 // The input text and our position in it 00764 CharacterIterator *text; 00765 00766 // The normalization buffer is the result of normalization 00767 // of the source in [currentIndex..nextIndex[ . 00768 int32_t currentIndex, nextIndex; 00769 00770 // A buffer for holding intermediate results 00771 UnicodeString buffer; 00772 int32_t bufferPos; 00773 }; 00774 00775 //------------------------------------------------------------------------- 00776 // Inline implementations 00777 //------------------------------------------------------------------------- 00778 00779 #ifndef U_HIDE_DEPRECATED_API 00780 inline bool 00781 Normalizer::operator!= (const Normalizer& other) const 00782 { return ! operator==(other); } 00783 00784 inline UNormalizationCheckResult 00785 Normalizer::quickCheck(const UnicodeString& source, 00786 UNormalizationMode mode, 00787 UErrorCode &status) { 00788 return quickCheck(source, mode, 0, status); 00789 } 00790 00791 inline UBool 00792 Normalizer::isNormalized(const UnicodeString& source, 00793 UNormalizationMode mode, 00794 UErrorCode &status) { 00795 return isNormalized(source, mode, 0, status); 00796 } 00797 #endif /* U_HIDE_DEPRECATED_API */ 00798 00799 inline int32_t 00800 Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2, 00801 uint32_t options, 00802 UErrorCode &errorCode) { 00803 // all argument checking is done in unorm_compare 00804 return unorm_compare(toUCharPtr(s1.getBuffer()), s1.length(), 00805 toUCharPtr(s2.getBuffer()), s2.length(), 00806 options, 00807 &errorCode); 00808 } 00809 00810 U_NAMESPACE_END 00811 00812 #endif /* #if !UCONFIG_NO_NORMALIZATION */ 00813 00814 #endif // NORMLZR_H 00815 00816 #endif /* U_SHOW_CPLUSPLUS_API */
1.7.6.1