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