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