intl/icu/source/i18n/unicode/coleitr.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 * Copyright (C) 1997-2013, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 ******************************************************************************
michael@0 6 */
michael@0 7
michael@0 8 /**
michael@0 9 * \file
michael@0 10 * \brief C++ API: Collation Element Iterator.
michael@0 11 */
michael@0 12
michael@0 13 /**
michael@0 14 * File coleitr.h
michael@0 15 *
michael@0 16 *
michael@0 17 *
michael@0 18 * Created by: Helena Shih
michael@0 19 *
michael@0 20 * Modification History:
michael@0 21 *
michael@0 22 * Date Name Description
michael@0 23 *
michael@0 24 * 8/18/97 helena Added internal API documentation.
michael@0 25 * 08/03/98 erm Synched with 1.2 version CollationElementIterator.java
michael@0 26 * 12/10/99 aliu Ported Thai collation support from Java.
michael@0 27 * 01/25/01 swquek Modified into a C++ wrapper calling C APIs (ucoliter.h)
michael@0 28 * 02/19/01 swquek Removed CollationElementsIterator() since it is
michael@0 29 * private constructor and no calls are made to it
michael@0 30 */
michael@0 31
michael@0 32 #ifndef COLEITR_H
michael@0 33 #define COLEITR_H
michael@0 34
michael@0 35 #include "unicode/utypes.h"
michael@0 36
michael@0 37
michael@0 38 #if !UCONFIG_NO_COLLATION
michael@0 39
michael@0 40 #include "unicode/uobject.h"
michael@0 41 #include "unicode/tblcoll.h"
michael@0 42 #include "unicode/ucoleitr.h"
michael@0 43
michael@0 44 /**
michael@0 45 * The UCollationElements struct.
michael@0 46 * For usage in C programs.
michael@0 47 * @stable ICU 2.0
michael@0 48 */
michael@0 49 typedef struct UCollationElements UCollationElements;
michael@0 50
michael@0 51 U_NAMESPACE_BEGIN
michael@0 52
michael@0 53 /**
michael@0 54 * The CollationElementIterator class is used as an iterator to walk through
michael@0 55 * each character of an international string. Use the iterator to return the
michael@0 56 * ordering priority of the positioned character. The ordering priority of a
michael@0 57 * character, which we refer to as a key, defines how a character is collated in
michael@0 58 * the given collation object.
michael@0 59 * For example, consider the following in Spanish:
michael@0 60 * <pre>
michael@0 61 * "ca" -> the first key is key('c') and second key is key('a').
michael@0 62 * "cha" -> the first key is key('ch') and second key is key('a').</pre>
michael@0 63 * And in German,
michael@0 64 * <pre> \htmlonly "&#x00E6;b"-> the first key is key('a'), the second key is key('e'), and
michael@0 65 * the third key is key('b'). \endhtmlonly </pre>
michael@0 66 * The key of a character, is an integer composed of primary order(short),
michael@0 67 * secondary order(char), and tertiary order(char). Java strictly defines the
michael@0 68 * size and signedness of its primitive data types. Therefore, the static
michael@0 69 * functions primaryOrder(), secondaryOrder(), and tertiaryOrder() return
michael@0 70 * int32_t to ensure the correctness of the key value.
michael@0 71 * <p>Example of the iterator usage: (without error checking)
michael@0 72 * <pre>
michael@0 73 * \code
michael@0 74 * void CollationElementIterator_Example()
michael@0 75 * {
michael@0 76 * UnicodeString str = "This is a test";
michael@0 77 * UErrorCode success = U_ZERO_ERROR;
michael@0 78 * RuleBasedCollator* rbc =
michael@0 79 * (RuleBasedCollator*) RuleBasedCollator::createInstance(success);
michael@0 80 * CollationElementIterator* c =
michael@0 81 * rbc->createCollationElementIterator( str );
michael@0 82 * int32_t order = c->next(success);
michael@0 83 * c->reset();
michael@0 84 * order = c->previous(success);
michael@0 85 * delete c;
michael@0 86 * delete rbc;
michael@0 87 * }
michael@0 88 * \endcode
michael@0 89 * </pre>
michael@0 90 * <p>
michael@0 91 * The method next() returns the collation order of the next character based on
michael@0 92 * the comparison level of the collator. The method previous() returns the
michael@0 93 * collation order of the previous character based on the comparison level of
michael@0 94 * the collator. The Collation Element Iterator moves only in one direction
michael@0 95 * between calls to reset(), setOffset(), or setText(). That is, next()
michael@0 96 * and previous() can not be inter-used. Whenever previous() is to be called after
michael@0 97 * next() or vice versa, reset(), setOffset() or setText() has to be called first
michael@0 98 * to reset the status, shifting pointers to either the end or the start of
michael@0 99 * the string (reset() or setText()), or the specified position (setOffset()).
michael@0 100 * Hence at the next call of next() or previous(), the first or last collation order,
michael@0 101 * or collation order at the spefcifieid position will be returned. If a change of
michael@0 102 * direction is done without one of these calls, the result is undefined.
michael@0 103 * <p>
michael@0 104 * The result of a forward iterate (next()) and reversed result of the backward
michael@0 105 * iterate (previous()) on the same string are equivalent, if collation orders
michael@0 106 * with the value UCOL_IGNORABLE are ignored.
michael@0 107 * Character based on the comparison level of the collator. A collation order
michael@0 108 * consists of primary order, secondary order and tertiary order. The data
michael@0 109 * type of the collation order is <strong>t_int32</strong>.
michael@0 110 *
michael@0 111 * Note, CollationElementIterator should not be subclassed.
michael@0 112 * @see Collator
michael@0 113 * @see RuleBasedCollator
michael@0 114 * @version 1.8 Jan 16 2001
michael@0 115 */
michael@0 116 class U_I18N_API CollationElementIterator : public UObject {
michael@0 117 public:
michael@0 118
michael@0 119 // CollationElementIterator public data member ------------------------------
michael@0 120
michael@0 121 enum {
michael@0 122 /**
michael@0 123 * NULLORDER indicates that an error has occured while processing
michael@0 124 * @stable ICU 2.0
michael@0 125 */
michael@0 126 NULLORDER = (int32_t)0xffffffff
michael@0 127 };
michael@0 128
michael@0 129 // CollationElementIterator public constructor/destructor -------------------
michael@0 130
michael@0 131 /**
michael@0 132 * Copy constructor.
michael@0 133 *
michael@0 134 * @param other the object to be copied from
michael@0 135 * @stable ICU 2.0
michael@0 136 */
michael@0 137 CollationElementIterator(const CollationElementIterator& other);
michael@0 138
michael@0 139 /**
michael@0 140 * Destructor
michael@0 141 * @stable ICU 2.0
michael@0 142 */
michael@0 143 virtual ~CollationElementIterator();
michael@0 144
michael@0 145 // CollationElementIterator public methods ----------------------------------
michael@0 146
michael@0 147 /**
michael@0 148 * Returns true if "other" is the same as "this"
michael@0 149 *
michael@0 150 * @param other the object to be compared
michael@0 151 * @return true if "other" is the same as "this"
michael@0 152 * @stable ICU 2.0
michael@0 153 */
michael@0 154 UBool operator==(const CollationElementIterator& other) const;
michael@0 155
michael@0 156 /**
michael@0 157 * Returns true if "other" is not the same as "this".
michael@0 158 *
michael@0 159 * @param other the object to be compared
michael@0 160 * @return true if "other" is not the same as "this"
michael@0 161 * @stable ICU 2.0
michael@0 162 */
michael@0 163 UBool operator!=(const CollationElementIterator& other) const;
michael@0 164
michael@0 165 /**
michael@0 166 * Resets the cursor to the beginning of the string.
michael@0 167 * @stable ICU 2.0
michael@0 168 */
michael@0 169 void reset(void);
michael@0 170
michael@0 171 /**
michael@0 172 * Gets the ordering priority of the next character in the string.
michael@0 173 * @param status the error code status.
michael@0 174 * @return the next character's ordering. otherwise returns NULLORDER if an
michael@0 175 * error has occured or if the end of string has been reached
michael@0 176 * @stable ICU 2.0
michael@0 177 */
michael@0 178 int32_t next(UErrorCode& status);
michael@0 179
michael@0 180 /**
michael@0 181 * Get the ordering priority of the previous collation element in the string.
michael@0 182 * @param status the error code status.
michael@0 183 * @return the previous element's ordering. otherwise returns NULLORDER if an
michael@0 184 * error has occured or if the start of string has been reached
michael@0 185 * @stable ICU 2.0
michael@0 186 */
michael@0 187 int32_t previous(UErrorCode& status);
michael@0 188
michael@0 189 /**
michael@0 190 * Gets the primary order of a collation order.
michael@0 191 * @param order the collation order
michael@0 192 * @return the primary order of a collation order.
michael@0 193 * @stable ICU 2.0
michael@0 194 */
michael@0 195 static inline int32_t primaryOrder(int32_t order);
michael@0 196
michael@0 197 /**
michael@0 198 * Gets the secondary order of a collation order.
michael@0 199 * @param order the collation order
michael@0 200 * @return the secondary order of a collation order.
michael@0 201 * @stable ICU 2.0
michael@0 202 */
michael@0 203 static inline int32_t secondaryOrder(int32_t order);
michael@0 204
michael@0 205 /**
michael@0 206 * Gets the tertiary order of a collation order.
michael@0 207 * @param order the collation order
michael@0 208 * @return the tertiary order of a collation order.
michael@0 209 * @stable ICU 2.0
michael@0 210 */
michael@0 211 static inline int32_t tertiaryOrder(int32_t order);
michael@0 212
michael@0 213 /**
michael@0 214 * Return the maximum length of any expansion sequences that end with the
michael@0 215 * specified comparison order.
michael@0 216 * @param order a collation order returned by previous or next.
michael@0 217 * @return maximum size of the expansion sequences ending with the collation
michael@0 218 * element or 1 if collation element does not occur at the end of any
michael@0 219 * expansion sequence
michael@0 220 * @stable ICU 2.0
michael@0 221 */
michael@0 222 int32_t getMaxExpansion(int32_t order) const;
michael@0 223
michael@0 224 /**
michael@0 225 * Gets the comparison order in the desired strength. Ignore the other
michael@0 226 * differences.
michael@0 227 * @param order The order value
michael@0 228 * @stable ICU 2.0
michael@0 229 */
michael@0 230 int32_t strengthOrder(int32_t order) const;
michael@0 231
michael@0 232 /**
michael@0 233 * Sets the source string.
michael@0 234 * @param str the source string.
michael@0 235 * @param status the error code status.
michael@0 236 * @stable ICU 2.0
michael@0 237 */
michael@0 238 void setText(const UnicodeString& str, UErrorCode& status);
michael@0 239
michael@0 240 /**
michael@0 241 * Sets the source string.
michael@0 242 * @param str the source character iterator.
michael@0 243 * @param status the error code status.
michael@0 244 * @stable ICU 2.0
michael@0 245 */
michael@0 246 void setText(CharacterIterator& str, UErrorCode& status);
michael@0 247
michael@0 248 /**
michael@0 249 * Checks if a comparison order is ignorable.
michael@0 250 * @param order the collation order.
michael@0 251 * @return TRUE if a character is ignorable, FALSE otherwise.
michael@0 252 * @stable ICU 2.0
michael@0 253 */
michael@0 254 static inline UBool isIgnorable(int32_t order);
michael@0 255
michael@0 256 /**
michael@0 257 * Gets the offset of the currently processed character in the source string.
michael@0 258 * @return the offset of the character.
michael@0 259 * @stable ICU 2.0
michael@0 260 */
michael@0 261 int32_t getOffset(void) const;
michael@0 262
michael@0 263 /**
michael@0 264 * Sets the offset of the currently processed character in the source string.
michael@0 265 * @param newOffset the new offset.
michael@0 266 * @param status the error code status.
michael@0 267 * @return the offset of the character.
michael@0 268 * @stable ICU 2.0
michael@0 269 */
michael@0 270 void setOffset(int32_t newOffset, UErrorCode& status);
michael@0 271
michael@0 272 /**
michael@0 273 * ICU "poor man's RTTI", returns a UClassID for the actual class.
michael@0 274 *
michael@0 275 * @stable ICU 2.2
michael@0 276 */
michael@0 277 virtual UClassID getDynamicClassID() const;
michael@0 278
michael@0 279 /**
michael@0 280 * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0 281 *
michael@0 282 * @stable ICU 2.2
michael@0 283 */
michael@0 284 static UClassID U_EXPORT2 getStaticClassID();
michael@0 285
michael@0 286 private:
michael@0 287 friend class RuleBasedCollator;
michael@0 288
michael@0 289 /**
michael@0 290 * CollationElementIterator constructor. This takes the source string and the
michael@0 291 * collation object. The cursor will walk thru the source string based on the
michael@0 292 * predefined collation rules. If the source string is empty, NULLORDER will
michael@0 293 * be returned on the calls to next().
michael@0 294 * @param sourceText the source string.
michael@0 295 * @param order the collation object.
michael@0 296 * @param status the error code status.
michael@0 297 */
michael@0 298 CollationElementIterator(const UnicodeString& sourceText,
michael@0 299 const RuleBasedCollator* order, UErrorCode& status);
michael@0 300
michael@0 301 /**
michael@0 302 * CollationElementIterator constructor. This takes the source string and the
michael@0 303 * collation object. The cursor will walk thru the source string based on the
michael@0 304 * predefined collation rules. If the source string is empty, NULLORDER will
michael@0 305 * be returned on the calls to next().
michael@0 306 * @param sourceText the source string.
michael@0 307 * @param order the collation object.
michael@0 308 * @param status the error code status.
michael@0 309 */
michael@0 310 CollationElementIterator(const CharacterIterator& sourceText,
michael@0 311 const RuleBasedCollator* order, UErrorCode& status);
michael@0 312
michael@0 313 /**
michael@0 314 * Assignment operator
michael@0 315 *
michael@0 316 * @param other the object to be copied
michael@0 317 */
michael@0 318 const CollationElementIterator&
michael@0 319 operator=(const CollationElementIterator& other);
michael@0 320
michael@0 321 CollationElementIterator(); // default constructor not implemented
michael@0 322
michael@0 323 // CollationElementIterator private data members ----------------------------
michael@0 324
michael@0 325 /**
michael@0 326 * Data wrapper for collation elements
michael@0 327 */
michael@0 328 UCollationElements *m_data_;
michael@0 329
michael@0 330 /**
michael@0 331 * Indicates if m_data_ belongs to this object.
michael@0 332 */
michael@0 333 UBool isDataOwned_;
michael@0 334 };
michael@0 335
michael@0 336 // CollationElementIterator inline method defination --------------------------
michael@0 337
michael@0 338 /**
michael@0 339 * Get the primary order of a collation order.
michael@0 340 * @param order the collation order
michael@0 341 * @return the primary order of a collation order.
michael@0 342 */
michael@0 343 inline int32_t CollationElementIterator::primaryOrder(int32_t order)
michael@0 344 {
michael@0 345 order &= RuleBasedCollator::PRIMARYORDERMASK;
michael@0 346 return (order >> RuleBasedCollator::PRIMARYORDERSHIFT);
michael@0 347 }
michael@0 348
michael@0 349 /**
michael@0 350 * Get the secondary order of a collation order.
michael@0 351 * @param order the collation order
michael@0 352 * @return the secondary order of a collation order.
michael@0 353 */
michael@0 354 inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
michael@0 355 {
michael@0 356 order = order & RuleBasedCollator::SECONDARYORDERMASK;
michael@0 357 return (order >> RuleBasedCollator::SECONDARYORDERSHIFT);
michael@0 358 }
michael@0 359
michael@0 360 /**
michael@0 361 * Get the tertiary order of a collation order.
michael@0 362 * @param order the collation order
michael@0 363 * @return the tertiary order of a collation order.
michael@0 364 */
michael@0 365 inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
michael@0 366 {
michael@0 367 return (order &= RuleBasedCollator::TERTIARYORDERMASK);
michael@0 368 }
michael@0 369
michael@0 370 inline int32_t CollationElementIterator::getMaxExpansion(int32_t order) const
michael@0 371 {
michael@0 372 return ucol_getMaxExpansion(m_data_, (uint32_t)order);
michael@0 373 }
michael@0 374
michael@0 375 inline UBool CollationElementIterator::isIgnorable(int32_t order)
michael@0 376 {
michael@0 377 return (primaryOrder(order) == RuleBasedCollator::PRIMIGNORABLE);
michael@0 378 }
michael@0 379
michael@0 380 U_NAMESPACE_END
michael@0 381
michael@0 382 #endif /* #if !UCONFIG_NO_COLLATION */
michael@0 383
michael@0 384 #endif

mercurial