annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/caniter.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // © 2016 and later: Unicode, Inc. and others.
jpayne@69 2 // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69 3 /*
jpayne@69 4 *******************************************************************************
jpayne@69 5 * Copyright (C) 1996-2014, International Business Machines Corporation and
jpayne@69 6 * others. All Rights Reserved.
jpayne@69 7 *******************************************************************************
jpayne@69 8 */
jpayne@69 9
jpayne@69 10 #ifndef CANITER_H
jpayne@69 11 #define CANITER_H
jpayne@69 12
jpayne@69 13 #include "unicode/utypes.h"
jpayne@69 14
jpayne@69 15 #if U_SHOW_CPLUSPLUS_API
jpayne@69 16
jpayne@69 17 #if !UCONFIG_NO_NORMALIZATION
jpayne@69 18
jpayne@69 19 #include "unicode/uobject.h"
jpayne@69 20 #include "unicode/unistr.h"
jpayne@69 21
jpayne@69 22 /**
jpayne@69 23 * \file
jpayne@69 24 * \brief C++ API: Canonical Iterator
jpayne@69 25 */
jpayne@69 26
jpayne@69 27 /** Should permutation skip characters with combining class zero
jpayne@69 28 * Should be either TRUE or FALSE. This is a compile time option
jpayne@69 29 * @stable ICU 2.4
jpayne@69 30 */
jpayne@69 31 #ifndef CANITER_SKIP_ZEROES
jpayne@69 32 #define CANITER_SKIP_ZEROES TRUE
jpayne@69 33 #endif
jpayne@69 34
jpayne@69 35 U_NAMESPACE_BEGIN
jpayne@69 36
jpayne@69 37 class Hashtable;
jpayne@69 38 class Normalizer2;
jpayne@69 39 class Normalizer2Impl;
jpayne@69 40
jpayne@69 41 /**
jpayne@69 42 * This class allows one to iterate through all the strings that are canonically equivalent to a given
jpayne@69 43 * string. For example, here are some sample results:
jpayne@69 44 Results for: {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 45 1: \\u0041\\u030A\\u0064\\u0307\\u0327
jpayne@69 46 = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 47 2: \\u0041\\u030A\\u0064\\u0327\\u0307
jpayne@69 48 = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 49 3: \\u0041\\u030A\\u1E0B\\u0327
jpayne@69 50 = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 51 4: \\u0041\\u030A\\u1E11\\u0307
jpayne@69 52 = {LATIN CAPITAL LETTER A}{COMBINING RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 53 5: \\u00C5\\u0064\\u0307\\u0327
jpayne@69 54 = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 55 6: \\u00C5\\u0064\\u0327\\u0307
jpayne@69 56 = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 57 7: \\u00C5\\u1E0B\\u0327
jpayne@69 58 = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 59 8: \\u00C5\\u1E11\\u0307
jpayne@69 60 = {LATIN CAPITAL LETTER A WITH RING ABOVE}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 61 9: \\u212B\\u0064\\u0307\\u0327
jpayne@69 62 = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 63 10: \\u212B\\u0064\\u0327\\u0307
jpayne@69 64 = {ANGSTROM SIGN}{LATIN SMALL LETTER D}{COMBINING CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 65 11: \\u212B\\u1E0B\\u0327
jpayne@69 66 = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH DOT ABOVE}{COMBINING CEDILLA}
jpayne@69 67 12: \\u212B\\u1E11\\u0307
jpayne@69 68 = {ANGSTROM SIGN}{LATIN SMALL LETTER D WITH CEDILLA}{COMBINING DOT ABOVE}
jpayne@69 69 *<br>Note: the code is intended for use with small strings, and is not suitable for larger ones,
jpayne@69 70 * since it has not been optimized for that situation.
jpayne@69 71 * Note, CanonicalIterator is not intended to be subclassed.
jpayne@69 72 * @author M. Davis
jpayne@69 73 * @author C++ port by V. Weinstein
jpayne@69 74 * @stable ICU 2.4
jpayne@69 75 */
jpayne@69 76 class U_COMMON_API CanonicalIterator U_FINAL : public UObject {
jpayne@69 77 public:
jpayne@69 78 /**
jpayne@69 79 * Construct a CanonicalIterator object
jpayne@69 80 * @param source string to get results for
jpayne@69 81 * @param status Fill-in parameter which receives the status of this operation.
jpayne@69 82 * @stable ICU 2.4
jpayne@69 83 */
jpayne@69 84 CanonicalIterator(const UnicodeString &source, UErrorCode &status);
jpayne@69 85
jpayne@69 86 /** Destructor
jpayne@69 87 * Cleans pieces
jpayne@69 88 * @stable ICU 2.4
jpayne@69 89 */
jpayne@69 90 virtual ~CanonicalIterator();
jpayne@69 91
jpayne@69 92 /**
jpayne@69 93 * Gets the NFD form of the current source we are iterating over.
jpayne@69 94 * @return gets the source: NOTE: it is the NFD form of source
jpayne@69 95 * @stable ICU 2.4
jpayne@69 96 */
jpayne@69 97 UnicodeString getSource();
jpayne@69 98
jpayne@69 99 /**
jpayne@69 100 * Resets the iterator so that one can start again from the beginning.
jpayne@69 101 * @stable ICU 2.4
jpayne@69 102 */
jpayne@69 103 void reset();
jpayne@69 104
jpayne@69 105 /**
jpayne@69 106 * Get the next canonically equivalent string.
jpayne@69 107 * <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
jpayne@69 108 * @return the next string that is canonically equivalent. A bogus string is returned when
jpayne@69 109 * the iteration is done.
jpayne@69 110 * @stable ICU 2.4
jpayne@69 111 */
jpayne@69 112 UnicodeString next();
jpayne@69 113
jpayne@69 114 /**
jpayne@69 115 * Set a new source for this iterator. Allows object reuse.
jpayne@69 116 * @param newSource the source string to iterate against. This allows the same iterator to be used
jpayne@69 117 * while changing the source string, saving object creation.
jpayne@69 118 * @param status Fill-in parameter which receives the status of this operation.
jpayne@69 119 * @stable ICU 2.4
jpayne@69 120 */
jpayne@69 121 void setSource(const UnicodeString &newSource, UErrorCode &status);
jpayne@69 122
jpayne@69 123 #ifndef U_HIDE_INTERNAL_API
jpayne@69 124 /**
jpayne@69 125 * Dumb recursive implementation of permutation.
jpayne@69 126 * TODO: optimize
jpayne@69 127 * @param source the string to find permutations for
jpayne@69 128 * @param skipZeros determine if skip zeros
jpayne@69 129 * @param result the results in a set.
jpayne@69 130 * @param status Fill-in parameter which receives the status of this operation.
jpayne@69 131 * @internal
jpayne@69 132 */
jpayne@69 133 static void U_EXPORT2 permute(UnicodeString &source, UBool skipZeros, Hashtable *result, UErrorCode &status);
jpayne@69 134 #endif /* U_HIDE_INTERNAL_API */
jpayne@69 135
jpayne@69 136 /**
jpayne@69 137 * ICU "poor man's RTTI", returns a UClassID for this class.
jpayne@69 138 *
jpayne@69 139 * @stable ICU 2.2
jpayne@69 140 */
jpayne@69 141 static UClassID U_EXPORT2 getStaticClassID();
jpayne@69 142
jpayne@69 143 /**
jpayne@69 144 * ICU "poor man's RTTI", returns a UClassID for the actual class.
jpayne@69 145 *
jpayne@69 146 * @stable ICU 2.2
jpayne@69 147 */
jpayne@69 148 virtual UClassID getDynamicClassID() const;
jpayne@69 149
jpayne@69 150 private:
jpayne@69 151 // ===================== PRIVATES ==============================
jpayne@69 152 // private default constructor
jpayne@69 153 CanonicalIterator();
jpayne@69 154
jpayne@69 155
jpayne@69 156 /**
jpayne@69 157 * Copy constructor. Private for now.
jpayne@69 158 * @internal (private)
jpayne@69 159 */
jpayne@69 160 CanonicalIterator(const CanonicalIterator& other);
jpayne@69 161
jpayne@69 162 /**
jpayne@69 163 * Assignment operator. Private for now.
jpayne@69 164 * @internal (private)
jpayne@69 165 */
jpayne@69 166 CanonicalIterator& operator=(const CanonicalIterator& other);
jpayne@69 167
jpayne@69 168 // fields
jpayne@69 169 UnicodeString source;
jpayne@69 170 UBool done;
jpayne@69 171
jpayne@69 172 // 2 dimensional array holds the pieces of the string with
jpayne@69 173 // their different canonically equivalent representations
jpayne@69 174 UnicodeString **pieces;
jpayne@69 175 int32_t pieces_length;
jpayne@69 176 int32_t *pieces_lengths;
jpayne@69 177
jpayne@69 178 // current is used in iterating to combine pieces
jpayne@69 179 int32_t *current;
jpayne@69 180 int32_t current_length;
jpayne@69 181
jpayne@69 182 // transient fields
jpayne@69 183 UnicodeString buffer;
jpayne@69 184
jpayne@69 185 const Normalizer2 &nfd;
jpayne@69 186 const Normalizer2Impl &nfcImpl;
jpayne@69 187
jpayne@69 188 // we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
jpayne@69 189 UnicodeString *getEquivalents(const UnicodeString &segment, int32_t &result_len, UErrorCode &status); //private String[] getEquivalents(String segment)
jpayne@69 190
jpayne@69 191 //Set getEquivalents2(String segment);
jpayne@69 192 Hashtable *getEquivalents2(Hashtable *fillinResult, const char16_t *segment, int32_t segLen, UErrorCode &status);
jpayne@69 193 //Hashtable *getEquivalents2(const UnicodeString &segment, int32_t segLen, UErrorCode &status);
jpayne@69 194
jpayne@69 195 /**
jpayne@69 196 * See if the decomposition of cp2 is at segment starting at segmentPos
jpayne@69 197 * (with canonical rearrangment!)
jpayne@69 198 * If so, take the remainder, and return the equivalents
jpayne@69 199 */
jpayne@69 200 //Set extract(int comp, String segment, int segmentPos, StringBuffer buffer);
jpayne@69 201 Hashtable *extract(Hashtable *fillinResult, UChar32 comp, const char16_t *segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
jpayne@69 202 //Hashtable *extract(UChar32 comp, const UnicodeString &segment, int32_t segLen, int32_t segmentPos, UErrorCode &status);
jpayne@69 203
jpayne@69 204 void cleanPieces();
jpayne@69 205
jpayne@69 206 };
jpayne@69 207
jpayne@69 208 U_NAMESPACE_END
jpayne@69 209
jpayne@69 210 #endif /* #if !UCONFIG_NO_NORMALIZATION */
jpayne@69 211
jpayne@69 212 #endif /* U_SHOW_CPLUSPLUS_API */
jpayne@69 213
jpayne@69 214 #endif