ICU 50.1.2  50.1.2
normlzr.h
Go to the documentation of this file.
1 /*
2  ********************************************************************
3  * COPYRIGHT:
4  * Copyright (c) 1996-2011, International Business Machines Corporation and
5  * others. All Rights Reserved.
6  ********************************************************************
7  */
8 
9 #ifndef NORMLZR_H
10 #define NORMLZR_H
11 
12 #include "unicode/utypes.h"
13 
19 #if !UCONFIG_NO_NORMALIZATION
20 
21 #include "unicode/chariter.h"
22 #include "unicode/normalizer2.h"
23 #include "unicode/unistr.h"
24 #include "unicode/unorm.h"
25 #include "unicode/uobject.h"
26 
131 public:
137  enum {
138  DONE=0xffff
139  };
140 
141  // Constructors
142 
153  Normalizer(const UnicodeString& str, UNormalizationMode mode);
154 
166  Normalizer(const UChar* str, int32_t length, UNormalizationMode mode);
167 
179 
185  Normalizer(const Normalizer& copy);
186 
191  virtual ~Normalizer();
192 
193 
194  //-------------------------------------------------------------------------
195  // Static utility methods
196  //-------------------------------------------------------------------------
197 
212  static void U_EXPORT2 normalize(const UnicodeString& source,
213  UNormalizationMode mode, int32_t options,
214  UnicodeString& result,
215  UErrorCode &status);
216 
234  static void U_EXPORT2 compose(const UnicodeString& source,
235  UBool compat, int32_t options,
236  UnicodeString& result,
237  UErrorCode &status);
238 
256  static void U_EXPORT2 decompose(const UnicodeString& source,
257  UBool compat, int32_t options,
258  UnicodeString& result,
259  UErrorCode &status);
260 
281  static inline UNormalizationCheckResult
282  quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
283 
298  quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
299 
320  static inline UBool
321  isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
322 
338  static UBool
339  isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
340 
370  static UnicodeString &
371  U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right,
372  UnicodeString &result,
373  UNormalizationMode mode, int32_t options,
374  UErrorCode &errorCode);
375 
440  static inline int32_t
441  compare(const UnicodeString &s1, const UnicodeString &s2,
442  uint32_t options,
443  UErrorCode &errorCode);
444 
445  //-------------------------------------------------------------------------
446  // Iteration API
447  //-------------------------------------------------------------------------
448 
457  UChar32 current(void);
458 
467  UChar32 first(void);
468 
477  UChar32 last(void);
478 
493  UChar32 next(void);
494 
509  UChar32 previous(void);
510 
520  void setIndexOnly(int32_t index);
521 
527  void reset(void);
528 
543  int32_t getIndex(void) const;
544 
553  int32_t startIndex(void) const;
554 
565  int32_t endIndex(void) const;
566 
575  UBool operator==(const Normalizer& that) const;
576 
585  inline UBool operator!=(const Normalizer& that) const;
586 
593  Normalizer* clone(void) const;
594 
601  int32_t hashCode(void) const;
602 
603  //-------------------------------------------------------------------------
604  // Property access methods
605  //-------------------------------------------------------------------------
606 
622  void setMode(UNormalizationMode newMode);
623 
634  UNormalizationMode getUMode(void) const;
635 
652  void setOption(int32_t option,
653  UBool value);
654 
665  UBool getOption(int32_t option) const;
666 
675  void setText(const UnicodeString& newText,
676  UErrorCode &status);
677 
686  void setText(const CharacterIterator& newText,
687  UErrorCode &status);
688 
698  void setText(const UChar* newText,
699  int32_t length,
700  UErrorCode &status);
707  void getText(UnicodeString& result);
708 
714  static UClassID U_EXPORT2 getStaticClassID();
715 
721  virtual UClassID getDynamicClassID() const;
722 
723 private:
724  //-------------------------------------------------------------------------
725  // Private functions
726  //-------------------------------------------------------------------------
727 
728  Normalizer(); // default constructor not implemented
729  Normalizer &operator=(const Normalizer &that); // assignment operator not implemented
730 
731  // Private utility methods for iteration
732  // For documentation, see the source code
733  UBool nextNormalize();
734  UBool previousNormalize();
735 
736  void init();
737  void clearBuffer(void);
738 
739  //-------------------------------------------------------------------------
740  // Private data
741  //-------------------------------------------------------------------------
742 
743  FilteredNormalizer2*fFilteredNorm2; // owned if not NULL
744  const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
745  UNormalizationMode fUMode;
746  int32_t fOptions;
747 
748  // The input text and our position in it
749  CharacterIterator *text;
750 
751  // The normalization buffer is the result of normalization
752  // of the source in [currentIndex..nextIndex[ .
753  int32_t currentIndex, nextIndex;
754 
755  // A buffer for holding intermediate results
756  UnicodeString buffer;
757  int32_t bufferPos;
758 };
759 
760 //-------------------------------------------------------------------------
761 // Inline implementations
762 //-------------------------------------------------------------------------
763 
764 inline UBool
766 { return ! operator==(other); }
767 
769 Normalizer::quickCheck(const UnicodeString& source,
770  UNormalizationMode mode,
771  UErrorCode &status) {
772  return quickCheck(source, mode, 0, status);
773 }
774 
775 inline UBool
776 Normalizer::isNormalized(const UnicodeString& source,
777  UNormalizationMode mode,
778  UErrorCode &status) {
779  return isNormalized(source, mode, 0, status);
780 }
781 
782 inline int32_t
783 Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
784  uint32_t options,
785  UErrorCode &errorCode) {
786  // all argument checking is done in unorm_compare
787  return unorm_compare(s1.getBuffer(), s1.length(),
788  s2.getBuffer(), s2.length(),
789  options,
790  &errorCode);
791 }
792 
794 
795 #endif /* #if !UCONFIG_NO_NORMALIZATION */
796 
797 #endif // NORMLZR_H
UNormalizationMode
Constants for normalization modes.
Definition: unorm.h:133
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
C++ API: Unicode String.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
C++ API: New API for Unicode Normalization.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
UChar * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
Unicode normalization functionality for standard Unicode normalization or for using custom mapping ta...
Definition: normalizer2.h:78
Abstract class that defines an API for iteration on text objects.
Definition: chariter.h:356
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
C API: Unicode Normalization.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:298
The Normalizer class supports the standard normalization forms described in Unicode Standard Annex #1...
Definition: normlzr.h:130
int32_t unorm_compare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, uint32_t options, UErrorCode *pErrorCode)
Compare two strings for canonical equivalence.
C++ API: Common ICU base class UObject.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:357
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:246
C++ API: Character Iterator.
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:229
Normalization filtered by a UnicodeSet.
Definition: normalizer2.h:449
UNormalizationCheckResult
Result values for normalization quick check functions.
Definition: unorm2.h:91
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3610
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200