jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************* jpayne@69: * Copyright (C) 1996-2014, International Business Machines Corporation and jpayne@69: * others. All Rights Reserved. jpayne@69: ******************************************************************************* jpayne@69: */ jpayne@69: jpayne@69: #ifndef CANITER_H jpayne@69: #define CANITER_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if !UCONFIG_NO_NORMALIZATION jpayne@69: jpayne@69: #include "unicode/uobject.h" jpayne@69: #include "unicode/unistr.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Canonical Iterator jpayne@69: */ jpayne@69: jpayne@69: /** Should permutation skip characters with combining class zero jpayne@69: * Should be either TRUE or FALSE. This is a compile time option jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: #ifndef CANITER_SKIP_ZEROES jpayne@69: #define CANITER_SKIP_ZEROES TRUE jpayne@69: #endif jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class Hashtable; jpayne@69: class Normalizer2; jpayne@69: class Normalizer2Impl; jpayne@69: jpayne@69: /** jpayne@69: * This class allows one to iterate through all the strings that are canonically equivalent to a given jpayne@69: * string. For example, here are some sample results: jpayne@69: Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 1: \\u0041\\u030A\\u0064\\u0307\\u0327 jpayne@69: = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 2: \\u0041\\u030A\\u0064\\u0327\\u0307 jpayne@69: = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} jpayne@69: 3: \\u0041\\u030A\\u1E0B\\u0327 jpayne@69: = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 4: \\u0041\\u030A\\u1E11\\u0307 jpayne@69: = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} jpayne@69: 5: \\u00C5\\u0064\\u0307\\u0327 jpayne@69: = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 6: \\u00C5\\u0064\\u0327\\u0307 jpayne@69: = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} jpayne@69: 7: \\u00C5\\u1E0B\\u0327 jpayne@69: = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 8: \\u00C5\\u1E11\\u0307 jpayne@69: = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} jpayne@69: 9: \\u212B\\u0064\\u0307\\u0327 jpayne@69: = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 10: \\u212B\\u0064\\u0327\\u0307 jpayne@69: = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE} jpayne@69: 11: \\u212B\\u1E0B\\u0327 jpayne@69: = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA} jpayne@69: 12: \\u212B\\u1E11\\u0307 jpayne@69: = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE} jpayne@69: *
Note: the code is intended for use with small strings, and is not suitable for larger ones, jpayne@69: * since it has not been optimized for that situation. jpayne@69: * Note, CanonicalIterator is not intended to be subclassed. jpayne@69: * @author M. Davis jpayne@69: * @author C++ port by V. Weinstein jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: class U_COMMON_API CanonicalIterator U_FINAL : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Construct a CanonicalIterator object jpayne@69: * @param source string to get results for jpayne@69: * @param status Fill-in parameter which receives the status of this operation. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: CanonicalIterator(const UnicodeString &source, UErrorCode &status); jpayne@69: jpayne@69: /** Destructor jpayne@69: * Cleans pieces jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: virtual ~CanonicalIterator(); jpayne@69: jpayne@69: /** jpayne@69: * Gets the NFD form of the current source we are iterating over. jpayne@69: * @return gets the source: NOTE: it is the NFD form of source jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: UnicodeString getSource(); jpayne@69: jpayne@69: /** jpayne@69: * Resets the iterator so that one can start again from the beginning. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: void reset(); jpayne@69: jpayne@69: /** jpayne@69: * Get the next canonically equivalent string. jpayne@69: *
Warning: The strings are not guaranteed to be in any particular order. jpayne@69: * @return the next string that is canonically equivalent. A bogus string is returned when jpayne@69: * the iteration is done. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: UnicodeString next(); jpayne@69: jpayne@69: /** jpayne@69: * Set a new source for this iterator. Allows object reuse. jpayne@69: * @param newSource the source string to iterate against. This allows the same iterator to be used jpayne@69: * while changing the source string, saving object creation. jpayne@69: * @param status Fill-in parameter which receives the status of this operation. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: void setSource(const UnicodeString &newSource, UErrorCode &status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Dumb recursive implementation of permutation. jpayne@69: * TODO: optimize jpayne@69: * @param source the string to find permutations for jpayne@69: * @param skipZeros determine if skip zeros jpayne@69: * @param result the results in a set. jpayne@69: * @param status Fill-in parameter which receives the status of this operation. jpayne@69: * @internal jpayne@69: */ jpayne@69: static void U_EXPORT2 permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(); jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: private: jpayne@69: // ===================== PRIVATES ============================== jpayne@69: // private default constructor jpayne@69: CanonicalIterator(); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. Private for now. jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: CanonicalIterator(const CanonicalIterator& other); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. Private for now. jpayne@69: * @internal (private) jpayne@69: */ jpayne@69: CanonicalIterator& operator=(const CanonicalIterator& other); jpayne@69: jpayne@69: // fields jpayne@69: UnicodeString source; jpayne@69: UBool done; jpayne@69: jpayne@69: // 2 dimensional array holds the pieces of the string with jpayne@69: // their different canonically equivalent representations jpayne@69: UnicodeString **pieces; jpayne@69: int32_t pieces_length; jpayne@69: int32_t *pieces_lengths; jpayne@69: jpayne@69: // current is used in iterating to combine pieces jpayne@69: int32_t *current; jpayne@69: int32_t current_length; jpayne@69: jpayne@69: // transient fields jpayne@69: UnicodeString buffer; jpayne@69: jpayne@69: const Normalizer2 &nfd; jpayne@69: const Normalizer2Impl &nfcImpl; jpayne@69: jpayne@69: // we have a segment, in NFD. Find all the strings that are canonically equivalent to it. jpayne@69: UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment) jpayne@69: jpayne@69: //Set getEquivalents2(String segment); jpayne@69: Hashtable *getEquivalents2(Hashtable *fillinResult, const char16_t *segment, int32_t segLen, UErrorCode &status); jpayne@69: //Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status); jpayne@69: jpayne@69: /** jpayne@69: * See if the decomposition of cp2 is at segment starting at segmentPos jpayne@69: * (with canonical rearrangment!) jpayne@69: * If so, take the remainder, and return the equivalents jpayne@69: */ jpayne@69: //Set extract(int comp, String segment, int segmentPos, StringBuffer buffer); jpayne@69: Hashtable *extract(Hashtable *fillinResult, UChar32 comp, const char16_t *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status); jpayne@69: //Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status); jpayne@69: jpayne@69: void cleanPieces(); jpayne@69: jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_NORMALIZATION */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif