os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/caniter.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/caniter.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,201 @@
     1.4 +/*
     1.5 + *******************************************************************************
     1.6 + * Copyright (C) 1996-2005, International Business Machines Corporation and    *
     1.7 + * others. All Rights Reserved.                                                *
     1.8 + *******************************************************************************
     1.9 + */
    1.10 +
    1.11 +#ifndef CANITER_H
    1.12 +#define CANITER_H
    1.13 +
    1.14 +#include "unicode/utypes.h"
    1.15 +
    1.16 +#if !UCONFIG_NO_NORMALIZATION
    1.17 +
    1.18 +#include "unicode/uobject.h"
    1.19 +#include "unicode/unistr.h"
    1.20 +
    1.21 +/**
    1.22 + * \file
    1.23 + * \brief C++ API: Canonical Iterator
    1.24 + */
    1.25 + 
    1.26 +/** Should permutation skip characters with combining class zero
    1.27 + *  Should be either TRUE or FALSE. This is a compile time option
    1.28 + *  @stable ICU 2.4
    1.29 + */
    1.30 +#ifndef CANITER_SKIP_ZEROES
    1.31 +#define CANITER_SKIP_ZEROES TRUE
    1.32 +#endif
    1.33 +
    1.34 +U_NAMESPACE_BEGIN
    1.35 +
    1.36 +class Hashtable;
    1.37 +
    1.38 +/**
    1.39 + * This class allows one to iterate through all the strings that are canonically equivalent to a given
    1.40 + * string. For example, here are some sample results:
    1.41 +Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
    1.42 +1: \\u0041\\u030A\\u0064\\u0307\\u0327
    1.43 + = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
    1.44 +2: \\u0041\\u030A\\u0064\\u0327\\u0307
    1.45 + = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
    1.46 +3: \\u0041\\u030A\\u1E0B\\u0327
    1.47 + = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
    1.48 +4: \\u0041\\u030A\\u1E11\\u0307
    1.49 + = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
    1.50 +5: \\u00C5\\u0064\\u0307\\u0327
    1.51 + = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
    1.52 +6: \\u00C5\\u0064\\u0327\\u0307
    1.53 + = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
    1.54 +7: \\u00C5\\u1E0B\\u0327
    1.55 + = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
    1.56 +8: \\u00C5\\u1E11\\u0307
    1.57 + = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
    1.58 +9: \\u212B\\u0064\\u0307\\u0327
    1.59 + = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
    1.60 +10: \\u212B\\u0064\\u0327\\u0307
    1.61 + = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
    1.62 +11: \\u212B\\u1E0B\\u0327
    1.63 + = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
    1.64 +12: \\u212B\\u1E11\\u0307
    1.65 + = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
    1.66 + *<br>Note: the code is intended for use with small strings, and is not suitable for larger ones,
    1.67 + * since it has not been optimized for that situation.
    1.68 + * Note, CanonicalIterator is not intended to be subclassed.
    1.69 + * @author M. Davis
    1.70 + * @author C++ port by V. Weinstein
    1.71 + * @stable ICU 2.4
    1.72 + */
    1.73 +class U_COMMON_API CanonicalIterator : public UObject {
    1.74 +public:
    1.75 +    /**
    1.76 +     * Construct a CanonicalIterator object
    1.77 +     * @param source    string to get results for
    1.78 +     * @param status    Fill-in parameter which receives the status of this operation.
    1.79 +     * @stable ICU 2.4
    1.80 +     */
    1.81 +    CanonicalIterator(const UnicodeString &source, UErrorCode &status);
    1.82 +
    1.83 +    /** Destructor
    1.84 +     *  Cleans pieces
    1.85 +     * @stable ICU 2.4
    1.86 +     */
    1.87 +    virtual ~CanonicalIterator();
    1.88 +
    1.89 +    /**
    1.90 +     * Gets the NFD form of the current source we are iterating over.
    1.91 +     * @return gets the source: NOTE: it is the NFD form of source
    1.92 +     * @stable ICU 2.4
    1.93 +     */
    1.94 +    UnicodeString getSource();
    1.95 +
    1.96 +    /**
    1.97 +     * Resets the iterator so that one can start again from the beginning.
    1.98 +     * @stable ICU 2.4
    1.99 +     */
   1.100 +    void reset();
   1.101 +
   1.102 +    /**
   1.103 +     * Get the next canonically equivalent string.
   1.104 +     * <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
   1.105 +     * @return the next string that is canonically equivalent. A bogus string is returned when
   1.106 +     * the iteration is done.
   1.107 +     * @stable ICU 2.4
   1.108 +     */
   1.109 +    UnicodeString next();
   1.110 +
   1.111 +    /**
   1.112 +     * Set a new source for this iterator. Allows object reuse.
   1.113 +     * @param newSource     the source string to iterate against. This allows the same iterator to be used
   1.114 +     *                     while changing the source string, saving object creation.
   1.115 +     * @param status        Fill-in parameter which receives the status of this operation.
   1.116 +     * @stable ICU 2.4
   1.117 +     */
   1.118 +    void setSource(const UnicodeString &newSource, UErrorCode &status);
   1.119 +
   1.120 +    /**
   1.121 +     * Dumb recursive implementation of permutation.
   1.122 +     * TODO: optimize
   1.123 +     * @param source     the string to find permutations for
   1.124 +     * @param skipZeros  determine if skip zeros
   1.125 +     * @param result     the results in a set.
   1.126 +     * @param status       Fill-in parameter which receives the status of this operation.
   1.127 +     * @internal
   1.128 +     */
   1.129 +    static void U_EXPORT2 permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status);
   1.130 +
   1.131 +    /**
   1.132 +     * ICU "poor man's RTTI", returns a UClassID for this class.
   1.133 +     *
   1.134 +     * @stable ICU 2.2
   1.135 +     */
   1.136 +    static UClassID U_EXPORT2 getStaticClassID();
   1.137 +
   1.138 +    /**
   1.139 +     * ICU "poor man's RTTI", returns a UClassID for the actual class.
   1.140 +     *
   1.141 +     * @stable ICU 2.2
   1.142 +     */
   1.143 +    virtual UClassID getDynamicClassID() const;
   1.144 +
   1.145 +private:
   1.146 +    // ===================== PRIVATES ==============================
   1.147 +    // private default constructor
   1.148 +    CanonicalIterator();
   1.149 +
   1.150 +
   1.151 +    /**
   1.152 +     * Copy constructor. Private for now.
   1.153 +     * @internal
   1.154 +     */
   1.155 +    CanonicalIterator(const CanonicalIterator& other);
   1.156 +
   1.157 +    /**
   1.158 +     * Assignment operator. Private for now.
   1.159 +     * @internal
   1.160 +     */
   1.161 +    CanonicalIterator& operator=(const CanonicalIterator& other);
   1.162 +
   1.163 +    // fields
   1.164 +    UnicodeString source;
   1.165 +    UBool done;
   1.166 +
   1.167 +    // 2 dimensional array holds the pieces of the string with
   1.168 +    // their different canonically equivalent representations
   1.169 +    UnicodeString **pieces;
   1.170 +    int32_t pieces_length;
   1.171 +    int32_t *pieces_lengths;
   1.172 +
   1.173 +    // current is used in iterating to combine pieces
   1.174 +    int32_t *current;
   1.175 +    int32_t current_length;
   1.176 +
   1.177 +    // transient fields
   1.178 +    UnicodeString buffer;
   1.179 +
   1.180 +    // we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
   1.181 +    UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment)
   1.182 +
   1.183 +    //Set getEquivalents2(String segment);
   1.184 +    Hashtable *getEquivalents2(const UChar *segment, int32_t segLen, UErrorCode &status);
   1.185 +    //Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status);
   1.186 +
   1.187 +    /**
   1.188 +     * See if the decomposition of cp2 is at segment starting at segmentPos
   1.189 +     * (with canonical rearrangment!)
   1.190 +     * If so, take the remainder, and return the equivalents
   1.191 +     */
   1.192 +    //Set extract(int comp, String segment, int segmentPos, StringBuffer buffer);
   1.193 +    Hashtable *extract(UChar32 comp, const UChar *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
   1.194 +    //Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
   1.195 +
   1.196 +    void cleanPieces();
   1.197 +
   1.198 +};
   1.199 +
   1.200 +U_NAMESPACE_END
   1.201 +
   1.202 +#endif /* #if !UCONFIG_NO_NORMALIZATION */
   1.203 +
   1.204 +#endif