michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2003, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: unorm_it.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2003jan21 michael@0: * created by: Markus W. Scherer michael@0: */ michael@0: michael@0: #ifndef __UNORM_IT_H__ michael@0: #define __UNORM_IT_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION michael@0: michael@0: #include "unicode/uiter.h" michael@0: #include "unicode/unorm.h" michael@0: michael@0: /** michael@0: * Normalizing UCharIterator wrapper. michael@0: * This internal API basically duplicates the functionality of the C++ Normalizer michael@0: * but michael@0: * - it actually implements a character iterator (UCharIterator) michael@0: * with few restrictions (see unorm_setIter()) michael@0: * - it supports UCharIterator getState()/setState() michael@0: * - it uses lower-level APIs and buffers more text and states, michael@0: * hopefully resulting in higher performance michael@0: * michael@0: * Usage example: michael@0: * \code michael@0: * function(UCharIterator *srcIter) { michael@0: * UNormIterator *uni; michael@0: * UCharIterator *iter; michael@0: * UErrorCode errorCode; michael@0: * michael@0: * errorCode=U_ZERO_ERROR; michael@0: * uni=unorm_openIter(&errorCode); michael@0: * if(U_FAILURE(errorCode)) { michael@0: * // report error michael@0: * return; michael@0: * } michael@0: * michael@0: * iter=unorm_setIter(uni, srcIter, UNORM_FCD, &errorCode); michael@0: * if(U_FAILURE(errorCode)) { michael@0: * // report error michael@0: * } else { michael@0: * // use iter to iterate over the canonically ordered michael@0: * // version of srcIter's text michael@0: * uint32_t state; michael@0: * michael@0: * ... michael@0: * michael@0: * state=uiter_getState(iter); michael@0: * if(state!=UITER_NO_STATE) { michael@0: * // use valid state, store it, use iter some more michael@0: * ... michael@0: * michael@0: * // later restore iter to the saved state: michael@0: * uiter_setState(iter, state, &errorCode); michael@0: * michael@0: * ... michael@0: * } michael@0: * michael@0: * ... michael@0: * } michael@0: * unorm_closeIter(uni); michael@0: * } michael@0: * \endcode michael@0: * michael@0: * See also the ICU test suites. michael@0: * michael@0: * @internal michael@0: */ michael@0: struct UNormIterator; michael@0: typedef struct UNormIterator UNormIterator; michael@0: michael@0: /** michael@0: * Size of a stack buffer to hold a UNormIterator, see the stackMem parameter michael@0: * of unorm_openIter(). michael@0: * michael@0: * @internal michael@0: */ michael@0: #define UNORM_ITER_SIZE 1024 michael@0: michael@0: /** michael@0: * Open a normalizing iterator. Must be closed later. michael@0: * Use unorm_setIter(). michael@0: * michael@0: * @param stackMem Pointer to preallocated (stack-allocated) buffer to hold michael@0: * the UNormIterator if possible; can be NULL. michael@0: * @param stackMemSize Number of bytes at stackMem; can be 0, michael@0: * or should be >= UNORM_ITER_SIZE for a non-NULL stackMem. michael@0: * @param pErrorCode ICU error code michael@0: * @return an allocated and pre-initialized UNormIterator michael@0: * @internal michael@0: */ michael@0: U_CAPI UNormIterator * U_EXPORT2 michael@0: unorm_openIter(void *stackMem, int32_t stackMemSize, UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Close a normalizing iterator. michael@0: * michael@0: * @param uni UNormIterator from unorm_openIter() michael@0: * @internal michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: unorm_closeIter(UNormIterator *uni); michael@0: michael@0: /** michael@0: * Set a UCharIterator and a normalization mode for the normalizing iterator michael@0: * to wrap. The normalizing iterator will read from the character iterator, michael@0: * normalize the text, and in turn deliver it with its own wrapper UCharIterator michael@0: * interface which it returns. michael@0: * michael@0: * The source iterator remains at its current position through the unorm_setIter() michael@0: * call but will be used and moved as soon as the michael@0: * the returned normalizing iterator is. michael@0: * michael@0: * The returned interface pointer is valid for as long as the normalizing iterator michael@0: * is open and until another unorm_setIter() call is made on it. michael@0: * michael@0: * The normalizing iterator's UCharIterator interface has the following properties: michael@0: * - getIndex() and move() will almost always return UITER_UNKNOWN_INDEX michael@0: * - getState() will return UITER_NO_STATE for unknown states for positions michael@0: * that are not at normalization boundaries michael@0: * michael@0: * @param uni UNormIterator from unorm_openIter() michael@0: * @param iter The source text UCharIterator to be wrapped. It is aliases into the normalizing iterator. michael@0: * Must support getState() and setState(). michael@0: * @param mode The normalization mode. michael@0: * @param pErrorCode ICU error code michael@0: * @return an alias to the normalizing iterator's UCharIterator interface michael@0: * @internal michael@0: */ michael@0: U_CAPI UCharIterator * U_EXPORT2 michael@0: unorm_setIter(UNormIterator *uni, UCharIterator *iter, UNormalizationMode mode, UErrorCode *pErrorCode); michael@0: michael@0: #endif /* uconfig.h switches */ michael@0: michael@0: #endif