michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 1997-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * Date Name Description michael@0: * 06/21/00 aliu Creation. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef UTRANS_H michael@0: #define UTRANS_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: #include "unicode/localpointer.h" michael@0: #include "unicode/urep.h" michael@0: #include "unicode/parseerr.h" michael@0: #include "unicode/uenum.h" michael@0: michael@0: /******************************************************************** michael@0: * General Notes michael@0: ******************************************************************** michael@0: */ michael@0: /** michael@0: * \file michael@0: * \brief C API: Transliterator michael@0: * michael@0: *
After a transliteration operation, some of the indices in this michael@0: * structure will be modified. See the field descriptions for michael@0: * details. michael@0: * michael@0: *
contextStart <= start <= limit <= contextLimit michael@0: * michael@0: *
Note: All index values in this structure must be at code point michael@0: * boundaries. That is, none of them may occur between two code units michael@0: * of a surrogate pair. If any index does split a surrogate pair, michael@0: * results are unspecified. michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef struct UTransPosition { michael@0: michael@0: /** michael@0: * Beginning index, inclusive, of the context to be considered for michael@0: * a transliteration operation. The transliterator will ignore michael@0: * anything before this index. INPUT/OUTPUT parameter: This parameter michael@0: * is updated by a transliteration operation to reflect the maximum michael@0: * amount of antecontext needed by a transliterator. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t contextStart; michael@0: michael@0: /** michael@0: * Ending index, exclusive, of the context to be considered for a michael@0: * transliteration operation. The transliterator will ignore michael@0: * anything at or after this index. INPUT/OUTPUT parameter: This michael@0: * parameter is updated to reflect changes in the length of the michael@0: * text, but points to the same logical position in the text. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t contextLimit; michael@0: michael@0: /** michael@0: * Beginning index, inclusive, of the text to be transliteratd. michael@0: * INPUT/OUTPUT parameter: This parameter is advanced past michael@0: * characters that have already been transliterated by a michael@0: * transliteration operation. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t start; michael@0: michael@0: /** michael@0: * Ending index, exclusive, of the text to be transliteratd. michael@0: * INPUT/OUTPUT parameter: This parameter is updated to reflect michael@0: * changes in the length of the text, but points to the same michael@0: * logical position in the text. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: int32_t limit; michael@0: michael@0: } UTransPosition; michael@0: michael@0: /******************************************************************** michael@0: * General API michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Open a custom transliterator, given a custom rules string michael@0: * OR michael@0: * a system transliterator, given its ID. michael@0: * Any non-NULL result from this function should later be closed with michael@0: * utrans_close(). michael@0: * michael@0: * @param id a valid transliterator ID michael@0: * @param idLength the length of the ID string, or -1 if NUL-terminated michael@0: * @param dir the desired direction michael@0: * @param rules the transliterator rules. See the C++ header rbt.h for michael@0: * rules syntax. If NULL then a system transliterator matching michael@0: * the ID is returned. michael@0: * @param rulesLength the length of the rules, or -1 if the rules michael@0: * are NUL-terminated. michael@0: * @param parseError a pointer to a UParseError struct to receive the details michael@0: * of any parsing errors. This parameter may be NULL if no michael@0: * parsing error details are desired. michael@0: * @param pErrorCode a pointer to the UErrorCode michael@0: * @return a transliterator pointer that may be passed to other michael@0: * utrans_xxx() functions, or NULL if the open call fails. michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE UTransliterator* U_EXPORT2 michael@0: utrans_openU(const UChar *id, michael@0: int32_t idLength, michael@0: UTransDirection dir, michael@0: const UChar *rules, michael@0: int32_t rulesLength, michael@0: UParseError *parseError, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Open an inverse of an existing transliterator. For this to work, michael@0: * the inverse must be registered with the system. For example, if michael@0: * the Transliterator "A-B" is opened, and then its inverse is opened, michael@0: * the result is the Transliterator "B-A", if such a transliterator is michael@0: * registered with the system. Otherwise the result is NULL and a michael@0: * failing UErrorCode is set. Any non-NULL result from this function michael@0: * should later be closed with utrans_close(). michael@0: * michael@0: * @param trans the transliterator to open the inverse of. michael@0: * @param status a pointer to the UErrorCode michael@0: * @return a pointer to a newly-opened transliterator that is the michael@0: * inverse of trans, or NULL if the open call fails. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UTransliterator* U_EXPORT2 michael@0: utrans_openInverse(const UTransliterator* trans, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Create a copy of a transliterator. Any non-NULL result from this michael@0: * function should later be closed with utrans_close(). michael@0: * michael@0: * @param trans the transliterator to be copied. michael@0: * @param status a pointer to the UErrorCode michael@0: * @return a transliterator pointer that may be passed to other michael@0: * utrans_xxx() functions, or NULL if the clone call fails. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UTransliterator* U_EXPORT2 michael@0: utrans_clone(const UTransliterator* trans, michael@0: UErrorCode* status); michael@0: michael@0: /** michael@0: * Close a transliterator. Any non-NULL pointer returned by michael@0: * utrans_openXxx() or utrans_clone() should eventually be closed. michael@0: * @param trans the transliterator to be closed. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: utrans_close(UTransliterator* trans); michael@0: michael@0: #if U_SHOW_CPLUSPLUS_API michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \class LocalUTransliteratorPointer michael@0: * "Smart pointer" class, closes a UTransliterator via utrans_close(). michael@0: * For most methods see the LocalPointerBase base class. michael@0: * michael@0: * @see LocalPointerBase michael@0: * @see LocalPointer michael@0: * @stable ICU 4.4 michael@0: */ michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUTransliteratorPointer, UTransliterator, utrans_close); michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Return the programmatic identifier for this transliterator. michael@0: * If this identifier is passed to utrans_openU(), it will open michael@0: * a transliterator equivalent to this one, if the ID has been michael@0: * registered. michael@0: * michael@0: * @param trans the transliterator to return the ID of. michael@0: * @param resultLength pointer to an output variable receiving the length michael@0: * of the ID string; can be NULL michael@0: * @return the NUL-terminated ID string. This pointer remains michael@0: * valid until utrans_close() is called on this transliterator. michael@0: * michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_STABLE const UChar * U_EXPORT2 michael@0: utrans_getUnicodeID(const UTransliterator *trans, michael@0: int32_t *resultLength); michael@0: michael@0: /** michael@0: * Register an open transliterator with the system. When michael@0: * utrans_open() is called with an ID string that is equal to that michael@0: * returned by utrans_getID(adoptedTrans,...), then michael@0: * utrans_clone(adoptedTrans,...) is returned. michael@0: * michael@0: *
NOTE: After this call the system owns the adoptedTrans and will
michael@0: * close it. The user must not call utrans_close() on adoptedTrans.
michael@0: *
michael@0: * @param adoptedTrans a transliterator, typically the result of
michael@0: * utrans_openRules(), to be registered with the system.
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_register(UTransliterator* adoptedTrans,
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Unregister a transliterator from the system. After this call the
michael@0: * system will no longer recognize the given ID when passed to
michael@0: * utrans_open(). If the ID is invalid then nothing is done.
michael@0: *
michael@0: * @param id an ID to unregister
michael@0: * @param idLength the length of id, or -1 if id is zero-terminated
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_unregisterID(const UChar* id, int32_t idLength);
michael@0:
michael@0: /**
michael@0: * Set the filter used by a transliterator. A filter can be used to
michael@0: * make the transliterator pass certain characters through untouched.
michael@0: * The filter is expressed using a UnicodeSet pattern. If the
michael@0: * filterPattern is NULL or the empty string, then the transliterator
michael@0: * will be reset to use no filter.
michael@0: *
michael@0: * @param trans the transliterator
michael@0: * @param filterPattern a pattern string, in the form accepted by
michael@0: * UnicodeSet, specifying which characters to apply the
michael@0: * transliteration to. May be NULL or the empty string to indicate no
michael@0: * filter.
michael@0: * @param filterPatternLen the length of filterPattern, or -1 if
michael@0: * filterPattern is zero-terminated
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @see UnicodeSet
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_setFilter(UTransliterator* trans,
michael@0: const UChar* filterPattern,
michael@0: int32_t filterPatternLen,
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Return the number of system transliterators.
michael@0: * It is recommended to use utrans_openIDs() instead.
michael@0: *
michael@0: * @return the number of system transliterators.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: utrans_countAvailableIDs(void);
michael@0:
michael@0: /**
michael@0: * Return a UEnumeration for the available transliterators.
michael@0: *
michael@0: * @param pErrorCode Pointer to the UErrorCode in/out parameter.
michael@0: * @return UEnumeration for the available transliterators.
michael@0: * Close with uenum_close().
michael@0: *
michael@0: * @stable ICU 2.8
michael@0: */
michael@0: U_STABLE UEnumeration * U_EXPORT2
michael@0: utrans_openIDs(UErrorCode *pErrorCode);
michael@0:
michael@0: /********************************************************************
michael@0: * Transliteration API
michael@0: ********************************************************************/
michael@0:
michael@0: /**
michael@0: * Transliterate a segment of a UReplaceable string. The string is
michael@0: * passed in as a UReplaceable pointer rep and a UReplaceableCallbacks
michael@0: * function pointer struct repFunc. Functions in the repFunc struct
michael@0: * will be called in order to modify the rep string.
michael@0: *
michael@0: * @param trans the transliterator
michael@0: * @param rep a pointer to the string. This will be passed to the
michael@0: * repFunc functions.
michael@0: * @param repFunc a set of function pointers that will be used to
michael@0: * modify the string pointed to by rep.
michael@0: * @param start the beginning index, inclusive; 0 <= start <=
michael@0: * limit
.
michael@0: * @param limit pointer to the ending index, exclusive; start <=
michael@0: * limit <= repFunc->length(rep)
. Upon return, *limit will
michael@0: * contain the new limit index. The text previously occupying
michael@0: * [start, limit)
has been transliterated, possibly to a
michael@0: * string of a different length, at [start,
michael@0: *
new-limit)
, where new-limit
michael@0: * is the return value.
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_trans(const UTransliterator* trans,
michael@0: UReplaceable* rep,
michael@0: UReplaceableCallbacks* repFunc,
michael@0: int32_t start,
michael@0: int32_t* limit,
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Transliterate the portion of the UReplaceable text buffer that can
michael@0: * be transliterated unambiguosly. This method is typically called
michael@0: * after new text has been inserted, e.g. as a result of a keyboard
michael@0: * event. The transliterator will try to transliterate characters of
michael@0: * rep
between index.cursor
and
michael@0: * index.limit
. Characters before
michael@0: * index.cursor
will not be changed.
michael@0: *
michael@0: *
Upon return, values in index
will be updated.
michael@0: * index.start
will be advanced to the first
michael@0: * character that future calls to this method will read.
michael@0: * index.cursor
and index.limit
will
michael@0: * be adjusted to delimit the range of text that future calls to
michael@0: * this method may change.
michael@0: *
michael@0: *
Typical usage of this method begins with an initial call
michael@0: * with index.start
and index.limit
michael@0: * set to indicate the portion of text
to be
michael@0: * transliterated, and index.cursor == index.start
.
michael@0: * Thereafter, index
can be used without
michael@0: * modification in future calls, provided that all changes to
michael@0: * text
are made via this method.
michael@0: *
michael@0: *
This method assumes that future calls may be made that will
michael@0: * insert new text into the buffer. As a result, it only performs
michael@0: * unambiguous transliterations. After the last call to this method,
michael@0: * there may be untransliterated text that is waiting for more input
michael@0: * to resolve an ambiguity. In order to perform these pending
michael@0: * transliterations, clients should call utrans_trans() with a start
michael@0: * of index.start and a limit of index.end after the last call to this
michael@0: * method has been made.
michael@0: *
michael@0: * @param trans the transliterator
michael@0: * @param rep a pointer to the string. This will be passed to the
michael@0: * repFunc functions.
michael@0: * @param repFunc a set of function pointers that will be used to
michael@0: * modify the string pointed to by rep.
michael@0: * @param pos a struct containing the start and limit indices of the
michael@0: * text to be read and the text to be transliterated
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_transIncremental(const UTransliterator* trans,
michael@0: UReplaceable* rep,
michael@0: UReplaceableCallbacks* repFunc,
michael@0: UTransPosition* pos,
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Transliterate a segment of a UChar* string. The string is passed
michael@0: * in in a UChar* buffer. The string is modified in place. If the
michael@0: * result is longer than textCapacity, it is truncated. The actual
michael@0: * length of the result is returned in *textLength, if textLength is
michael@0: * non-NULL. *textLength may be greater than textCapacity, but only
michael@0: * textCapacity UChars will be written to *text, including the zero
michael@0: * terminator.
michael@0: *
michael@0: * @param trans the transliterator
michael@0: * @param text a pointer to a buffer containing the text to be
michael@0: * transliterated on input and the result text on output.
michael@0: * @param textLength a pointer to the length of the string in text.
michael@0: * If the length is -1 then the string is assumed to be
michael@0: * zero-terminated. Upon return, the new length is stored in
michael@0: * *textLength. If textLength is NULL then the string is assumed to
michael@0: * be zero-terminated.
michael@0: * @param textCapacity a pointer to the length of the text buffer.
michael@0: * Upon return,
michael@0: * @param start the beginning index, inclusive; 0 <= start <=
michael@0: * limit
.
michael@0: * @param limit pointer to the ending index, exclusive; start <=
michael@0: * limit <= repFunc->length(rep)
. Upon return, *limit will
michael@0: * contain the new limit index. The text previously occupying
michael@0: * [start, limit)
has been transliterated, possibly to a
michael@0: * string of a different length, at [start,
michael@0: *
new-limit)
, where new-limit
michael@0: * is the return value.
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_transUChars(const UTransliterator* trans,
michael@0: UChar* text,
michael@0: int32_t* textLength,
michael@0: int32_t textCapacity,
michael@0: int32_t start,
michael@0: int32_t* limit,
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Transliterate the portion of the UChar* text buffer that can be
michael@0: * transliterated unambiguosly. See utrans_transIncremental(). The
michael@0: * string is passed in in a UChar* buffer. The string is modified in
michael@0: * place. If the result is longer than textCapacity, it is truncated.
michael@0: * The actual length of the result is returned in *textLength, if
michael@0: * textLength is non-NULL. *textLength may be greater than
michael@0: * textCapacity, but only textCapacity UChars will be written to
michael@0: * *text, including the zero terminator. See utrans_transIncremental()
michael@0: * for usage details.
michael@0: *
michael@0: * @param trans the transliterator
michael@0: * @param text a pointer to a buffer containing the text to be
michael@0: * transliterated on input and the result text on output.
michael@0: * @param textLength a pointer to the length of the string in text.
michael@0: * If the length is -1 then the string is assumed to be
michael@0: * zero-terminated. Upon return, the new length is stored in
michael@0: * *textLength. If textLength is NULL then the string is assumed to
michael@0: * be zero-terminated.
michael@0: * @param textCapacity the length of the text buffer
michael@0: * @param pos a struct containing the start and limit indices of the
michael@0: * text to be read and the text to be transliterated
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @see utrans_transIncremental
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: utrans_transIncrementalUChars(const UTransliterator* trans,
michael@0: UChar* text,
michael@0: int32_t* textLength,
michael@0: int32_t textCapacity,
michael@0: UTransPosition* pos,
michael@0: UErrorCode* status);
michael@0:
michael@0: /* deprecated API ----------------------------------------------------------- */
michael@0:
michael@0: #ifndef U_HIDE_DEPRECATED_API
michael@0:
michael@0: /* see utrans.h documentation for why these functions are deprecated */
michael@0:
michael@0: /**
michael@0: * Deprecated, use utrans_openU() instead.
michael@0: * Open a custom transliterator, given a custom rules string
michael@0: * OR
michael@0: * a system transliterator, given its ID.
michael@0: * Any non-NULL result from this function should later be closed with
michael@0: * utrans_close().
michael@0: *
michael@0: * @param id a valid ID, as returned by utrans_getAvailableID()
michael@0: * @param dir the desired direction
michael@0: * @param rules the transliterator rules. See the C++ header rbt.h
michael@0: * for rules syntax. If NULL then a system transliterator matching
michael@0: * the ID is returned.
michael@0: * @param rulesLength the length of the rules, or -1 if the rules
michael@0: * are zero-terminated.
michael@0: * @param parseError a pointer to a UParseError struct to receive the
michael@0: * details of any parsing errors. This parameter may be NULL if no
michael@0: * parsing error details are desired.
michael@0: * @param status a pointer to the UErrorCode
michael@0: * @return a transliterator pointer that may be passed to other
michael@0: * utrans_xxx() functions, or NULL if the open call fails.
michael@0: * @deprecated ICU 2.8 Use utrans_openU() instead, see utrans.h
michael@0: */
michael@0: U_DEPRECATED UTransliterator* U_EXPORT2
michael@0: utrans_open(const char* id,
michael@0: UTransDirection dir,
michael@0: const UChar* rules, /* may be Null */
michael@0: int32_t rulesLength, /* -1 if null-terminated */
michael@0: UParseError* parseError, /* may be Null */
michael@0: UErrorCode* status);
michael@0:
michael@0: /**
michael@0: * Deprecated, use utrans_getUnicodeID() instead.
michael@0: * Return the programmatic identifier for this transliterator.
michael@0: * If this identifier is passed to utrans_open(), it will open
michael@0: * a transliterator equivalent to this one, if the ID has been
michael@0: * registered.
michael@0: * @param trans the transliterator to return the ID of.
michael@0: * @param buf the buffer in which to receive the ID. This may be
michael@0: * NULL, in which case no characters are copied.
michael@0: * @param bufCapacity the capacity of the buffer. Ignored if buf is
michael@0: * NULL.
michael@0: * @return the actual length of the ID, not including
michael@0: * zero-termination. This may be greater than bufCapacity.
michael@0: * @deprecated ICU 2.8 Use utrans_getUnicodeID() instead, see utrans.h
michael@0: */
michael@0: U_DEPRECATED int32_t U_EXPORT2
michael@0: utrans_getID(const UTransliterator* trans,
michael@0: char* buf,
michael@0: int32_t bufCapacity);
michael@0:
michael@0: /**
michael@0: * Deprecated, use utrans_unregisterID() instead.
michael@0: * Unregister a transliterator from the system. After this call the
michael@0: * system will no longer recognize the given ID when passed to
michael@0: * utrans_open(). If the id is invalid then nothing is done.
michael@0: *
michael@0: * @param id a zero-terminated ID
michael@0: * @deprecated ICU 2.8 Use utrans_unregisterID() instead, see utrans.h
michael@0: */
michael@0: U_DEPRECATED void U_EXPORT2
michael@0: utrans_unregister(const char* id);
michael@0:
michael@0: /**
michael@0: * Deprecated, use utrans_openIDs() instead.
michael@0: * Return the ID of the index-th system transliterator. The result
michael@0: * is placed in the given buffer. If the given buffer is too small,
michael@0: * the initial substring is copied to buf. The result in buf is
michael@0: * always zero-terminated.
michael@0: *
michael@0: * @param index the number of the transliterator to return. Must
michael@0: * satisfy 0 <= index < utrans_countAvailableIDs(). If index is out
michael@0: * of range then it is treated as if it were 0.
michael@0: * @param buf the buffer in which to receive the ID. This may be
michael@0: * NULL, in which case no characters are copied.
michael@0: * @param bufCapacity the capacity of the buffer. Ignored if buf is
michael@0: * NULL.
michael@0: * @return the actual length of the index-th ID, not including
michael@0: * zero-termination. This may be greater than bufCapacity.
michael@0: * @deprecated ICU 2.8 Use utrans_openIDs() instead, see utrans.h
michael@0: */
michael@0: U_DEPRECATED int32_t U_EXPORT2
michael@0: utrans_getAvailableID(int32_t index,
michael@0: char* buf,
michael@0: int32_t bufCapacity);
michael@0:
michael@0: #endif /* U_HIDE_DEPRECATED_API */
michael@0:
michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */
michael@0:
michael@0: #endif