/* ****************************************************************************** * * © 2016 and later: Unicode, Inc. and others. * License & terms of use: http://www.unicode.org/copyright.html * ****************************************************************************** * file name: ubiditransform.c * encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * * created on: 2016jul24 * created by: Lina Kemmel * */ #include "cmemory.h" #include "unicode/ubidi.h" #include "unicode/ustring.h" #include "unicode/ushape.h" #include "unicode/utf16.h" #include "ustr_imp.h" #include "unicode/ubiditransform.h" /* Some convenience defines */ #define LTR … #define RTL … #define LOGICAL … #define VISUAL … #define SHAPE_LOGICAL … #define SHAPE_VISUAL … #define CHECK_LEN(STR, LEN, ERROR) … #define MAX_ACTIONS … /** * Typedef for a pointer to a function, which performs some operation (such as * reordering, setting "inverse" mode, character mirroring, etc.). Return value * indicates whether the text was changed in the course of this operation or * not. */ UBiDiAction; /** * Structure that holds a predefined reordering scheme, including the following * information: * <ul> * <li>an input base direction,</li> * <li>an input order,</li> * <li>an output base direction,</li> * <li>an output order,</li> * <li>a digit shaping direction,</li> * <li>a letter shaping direction,</li> * <li>a base direction that should be applied when the reordering engine is * invoked (which can not always be derived from the caller-defined * options),</li> * <li>an array of pointers to functions that accomplish the bidi layout * transformation.</li> * </ul> */ ReorderingScheme; struct UBiDiTransform { … }; U_CAPI UBiDiTransform* U_EXPORT2 ubiditransform_open(UErrorCode *pErrorCode) { … } U_CAPI void U_EXPORT2 ubiditransform_close(UBiDiTransform *pBiDiTransform) { … } /** * Performs Bidi resolution of text. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_resolve(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Performs basic reordering of text (Logical -> Visual LTR). * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_reorder(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Sets "inverse" mode on the <code>UBiDi</code> object. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_setInverse(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Sets "runs only" reordering mode indicating a Logical LTR <-> Logical RTL * transformation. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_setRunsOnly(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Performs string reverse. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_reverse(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Applies a new value to the text that serves as input at the current * processing step. This value is identical to the original one when we begin * the processing, but usually changes as the transformation progresses. * * @param pTransform A pointer to the <code>UBiDiTransform</code> structure. * @param newSrc A pointer whose value is to be used as input text. * @param newLength A length of the new text in <code>char16_t</code>s. * @param newSize A new source capacity in <code>char16_t</code>s. * @param pErrorCode Pointer to the error code value. */ static void updateSrc(UBiDiTransform *pTransform, const char16_t *newSrc, uint32_t newLength, uint32_t newSize, UErrorCode *pErrorCode) { … } /** * Calls a lower level shaping function. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param options Shaping options. * @param pErrorCode Pointer to the error code value. */ static void doShape(UBiDiTransform *pTransform, uint32_t options, UErrorCode *pErrorCode) { … } /** * Performs digit and letter shaping. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_shapeArabic(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * Performs character mirroring. * * @param pTransform Pointer to the <code>UBiDiTransform</code> structure. * @param pErrorCode Pointer to the error code value. * * @return Whether or not this function modifies the text. Besides the return * value, the caller should also check <code>U_SUCCESS(*pErrorCode)</code>. */ static UBool action_mirror(UBiDiTransform *pTransform, UErrorCode *pErrorCode) { … } /** * All possible reordering schemes. * */ static const ReorderingScheme Schemes[] = …; static const uint32_t nSchemes = …; /** * When the direction option is <code>UBIDI_DEFAULT_LTR</code> or * <code>UBIDI_DEFAULT_RTL</code>, resolve the base direction according to that * of the first strong bidi character. */ static void resolveBaseDirection(const char16_t *text, uint32_t length, UBiDiLevel *pInLevel, UBiDiLevel *pOutLevel) { … } /** * Finds a valid <code>ReorderingScheme</code> matching the * caller-defined scheme. * * @return A valid <code>ReorderingScheme</code> object or nullptr */ static const ReorderingScheme* findMatchingScheme(UBiDiLevel inLevel, UBiDiLevel outLevel, UBiDiOrder inOrder, UBiDiOrder outOrder) { … } U_CAPI uint32_t U_EXPORT2 ubiditransform_transform(UBiDiTransform *pBiDiTransform, const char16_t *src, int32_t srcLength, char16_t *dest, int32_t destSize, UBiDiLevel inParaLevel, UBiDiOrder inOrder, UBiDiLevel outParaLevel, UBiDiOrder outOrder, UBiDiMirroring doMirroring, uint32_t shapingOptions, UErrorCode *pErrorCode) { … }