- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- File List
- Globals

# utext.h

Go to the documentation of this file.

    00001 /*
    00002 *******************************************************************************
    00003 *
    00004 *   Copyright (C) 2004-2007, International Business Machines
    00005 *   Corporation and others.  All Rights Reserved.
    00006 *
    00007 *******************************************************************************
    00008 *   file name:  utext.h
    00009 *   encoding:   US-ASCII
    00010 *   tab size:   8 (not used)
    00011 *   indentation:4
    00012 *
    00013 *   created on: 2004oct06
    00014 *   created by: Markus W. Scherer
    00015 */
    00016
    00017 #ifndef __UTEXT_H__
    00018 #define __UTEXT_H__
    00019
    00138 #include "unicode/utypes.h"
    00139 #ifdef XP_CPLUSPLUS
    00140 #include "unicode/rep.h"
    00141 #include "unicode/unistr.h"
    00142 #include "unicode/chariter.h"
    00143 #endif
    00144
    00145
    00146 U_CDECL_BEGIN
    00147
    00148 struct UText;
    00149 typedef struct UText UText;
    00152 /***************************************************************************************
    00153  *
    00154  *   C Functions for creating UText wrappers around various kinds of text strings.
    00155  *
    00156  ****************************************************************************************/
    00157
    00158
    00179 U_STABLE UText * U_EXPORT2
    00180 utext_close(UText *ut);
    00181
    00182
    00204 U_STABLE UText * U_EXPORT2
    00205 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
    00206
    00207
    00222 U_STABLE UText * U_EXPORT2
    00223 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status);
    00224
    00225
    00226 #ifdef XP_CPLUSPLUS
    00227
    00239 U_STABLE UText * U_EXPORT2
    00240 utext_openUnicodeString(UText *ut, U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
    00241
    00242
    00255 U_STABLE UText * U_EXPORT2
    00256 utext_openConstUnicodeString(UText *ut, const U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
    00257
    00258
    00271 U_STABLE UText * U_EXPORT2
    00272 utext_openReplaceable(UText *ut, U_NAMESPACE_QUALIFIER Replaceable *rep, UErrorCode *status);
    00273
    00286 U_STABLE UText * U_EXPORT2
    00287 utext_openCharacterIterator(UText *ut, U_NAMESPACE_QUALIFIER CharacterIterator *ic, UErrorCode *status);
    00288
    00289 #endif
    00290
    00291
    00349 U_STABLE UText * U_EXPORT2
    00350 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
    00351
    00352
    00364 U_STABLE UBool U_EXPORT2
    00365 utext_equals(const UText *a, const UText *b);
    00366
    00367
    00368 /*****************************************************************************
    00369  *
    00370  *   Functions to work with the text represeted by a UText wrapper
    00371  *
    00372  *****************************************************************************/
    00373
    00385 U_STABLE int64_t U_EXPORT2
    00386 utext_nativeLength(UText *ut);
    00387
    00401 U_STABLE UBool U_EXPORT2
    00402 utext_isLengthExpensive(const UText *ut);
    00403
    00429 U_STABLE UChar32 U_EXPORT2
    00430 utext_char32At(UText *ut, int64_t nativeIndex);
    00431
    00432
    00443 U_STABLE UChar32 U_EXPORT2
    00444 utext_current32(UText *ut);
    00445
    00446
    00465 U_STABLE UChar32 U_EXPORT2
    00466 utext_next32(UText *ut);
    00467
    00468
    00486 U_STABLE UChar32 U_EXPORT2
    00487 utext_previous32(UText *ut);
    00488
    00489
    00508 U_STABLE UChar32 U_EXPORT2
    00509 utext_next32From(UText *ut, int64_t nativeIndex);
    00510
    00511
    00512
    00528 U_STABLE UChar32 U_EXPORT2
    00529 utext_previous32From(UText *ut, int64_t nativeIndex);
    00530
    00543 U_STABLE int64_t U_EXPORT2
    00544 utext_getNativeIndex(const UText *ut);
    00545
    00569 U_STABLE void U_EXPORT2
    00570 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
    00571
    00588 U_STABLE UBool U_EXPORT2
    00589 utext_moveIndex32(UText *ut, int32_t delta);
    00590
    00613 U_STABLE int64_t U_EXPORT2
    00614 utext_getPreviousNativeIndex(UText *ut);
    00615
    00616
    00651 U_STABLE int32_t U_EXPORT2
    00652 utext_extract(UText *ut,
    00653              int64_t nativeStart, int64_t nativeLimit,
    00654              UChar *dest, int32_t destCapacity,
    00655              UErrorCode *status);
    00656
    00657
    00658 /************************************************************************************
    00659  *
    00660  *  #define inline versions of selected performance-critical text access functions
    00661  *          Caution:  do not use auto increment++ or decrement-- expressions
    00662  *                    as parameters to these macros.
    00663  *
    00664  *          For most use, where there is no extreme performance constraint, the
    00665  *          normal, non-inline functions are a better choice.  The resulting code
    00666  *          will be smaller, and, if the need ever arises, easier to debug.
    00667  *
    00668  *          These are implemented as #defines rather than real functions
    00669  *          because there is no fully portable way to do inline functions in plain C.
    00670  *
    00671  ************************************************************************************/
    00672
    00684 #define UTEXT_NEXT32(ut)  \
    00685     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
    00686     ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
    00687
    00698 #define UTEXT_PREVIOUS32(ut)  \
    00699     ((ut)->chunkOffset > 0 && \
    00700      (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
    00701           (ut)->chunkContents[--((ut)->chunkOffset)]  :  utext_previous32(ut))
    00702
    00715 #define UTEXT_GETNATIVEINDEX(ut)                       \
    00716     ((ut)->chunkOffset <= (ut)->nativeIndexingLimit?   \
    00717         (ut)->chunkNativeStart+(ut)->chunkOffset :     \
    00718         (ut)->pFuncs->mapOffsetToNative(ut))
    00719
    00731 #define UTEXT_SETNATIVEINDEX(ut, ix)                       \
    00732     { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
    00733       if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
    00734           (ut)->chunkOffset=(int32_t)__offset; \
    00735       } else { \
    00736           utext_setNativeIndex((ut), (ix)); } }
    00737
    00738
    00739
    00740 /************************************************************************************
    00741  *
    00742  *   Functions related to writing or modifying the text.
    00743  *   These will work only with modifiable UTexts.  Attempting to
    00744  *   modify a read-only UText will return an error status.
    00745  *
    00746  ************************************************************************************/
    00747
    00748
    00767 U_STABLE UBool U_EXPORT2
    00768 utext_isWritable(const UText *ut);
    00769
    00770
    00779 U_STABLE UBool U_EXPORT2
    00780 utext_hasMetaData(const UText *ut);
    00781
    00782
    00810 U_STABLE int32_t U_EXPORT2
    00811 utext_replace(UText *ut,
    00812              int64_t nativeStart, int64_t nativeLimit,
    00813              const UChar *replacementText, int32_t replacementLength,
    00814              UErrorCode *status);
    00815
    00816
    00817
    00850 U_STABLE void U_EXPORT2
    00851 utext_copy(UText *ut,
    00852           int64_t nativeStart, int64_t nativeLimit,
    00853           int64_t destIndex,
    00854           UBool move,
    00855           UErrorCode *status);
    00856
    00857
    00879 U_STABLE void U_EXPORT2
    00880 utext_freeze(UText *ut);
    00881
    00882
    00889 enum {
    00894     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
    00901     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
    00908     UTEXT_PROVIDER_WRITABLE = 3,
    00914     UTEXT_PROVIDER_HAS_META_DATA = 4,
    00922      UTEXT_PROVIDER_OWNS_TEXT = 5
    00923 };
    00924
    00962 typedef UText * U_CALLCONV
    00963 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
    00964
    00965
    00974 typedef int64_t U_CALLCONV
    00975 UTextNativeLength(UText *ut);
    00976
    01002 typedef UBool U_CALLCONV
    01003 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
    01004
    01032 typedef int32_t U_CALLCONV
    01033 UTextExtract(UText *ut,
    01034              int64_t nativeStart, int64_t nativeLimit,
    01035              UChar *dest, int32_t destCapacity,
    01036              UErrorCode *status);
    01037
    01067 typedef int32_t U_CALLCONV
    01068 UTextReplace(UText *ut,
    01069              int64_t nativeStart, int64_t nativeLimit,
    01070              const UChar *replacementText, int32_t replacmentLength,
    01071              UErrorCode *status);
    01072
    01101 typedef void U_CALLCONV
    01102 UTextCopy(UText *ut,
    01103           int64_t nativeStart, int64_t nativeLimit,
    01104           int64_t nativeDest,
    01105           UBool move,
    01106           UErrorCode *status);
    01107
    01121 typedef int64_t U_CALLCONV
    01122 UTextMapOffsetToNative(const UText *ut);
    01123
    01139 typedef int32_t U_CALLCONV
    01140 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
    01141
    01142
    01160 typedef void U_CALLCONV
    01161 UTextClose(UText *ut);
    01162
    01163
    01173 struct UTextFuncs {
    01188     int32_t       tableSize;
    01189
    01195     int32_t       reserved1, reserved2, reserved3;
    01196
    01197
    01204     UTextClone *clone;
    01205
    01213     UTextNativeLength *nativeLength;
    01214
    01221     UTextAccess *access;
    01222
    01229     UTextExtract *extract;
    01230
    01237     UTextReplace *replace;
    01238
    01245     UTextCopy *copy;
    01246
    01253     UTextMapOffsetToNative *mapOffsetToNative;
    01254
    01261     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
    01262
    01269     UTextClose  *close;
    01270
    01276     UTextClose  *spare1;
    01281     UTextClose  *spare2;
    01282
    01287     UTextClose  *spare3;
    01288
    01289 };
    01290 typedef struct UTextFuncs UTextFuncs;
    01291
    01303 struct UText {
    01316     uint32_t       magic;
    01317
    01318
    01324     int32_t        flags;
    01325
    01326
    01332     int32_t         providerProperties;
    01333
    01340     int32_t         sizeOfStruct;
    01341
    01342     /* ------ 16 byte alignment boundary -----------  */
    01343
    01344
    01350     int64_t         chunkNativeLimit;
    01351
    01356     int32_t        extraSize;
    01357
    01365     int32_t         nativeIndexingLimit;
    01366
    01367     /* ---- 16 byte alignment boundary------ */
    01368
    01373     int64_t         chunkNativeStart;
    01374
    01380     int32_t         chunkOffset;
    01381
    01386     int32_t         chunkLength;
    01387
    01388     /* ---- 16  byte alignment boundary-- */
    01389
    01390
    01397     const UChar    *chunkContents;
    01398
    01403     UTextFuncs     *pFuncs;
    01404
    01410     void          *pExtra;
    01411
    01418     const void   *context;
    01419
    01420     /* --- 16 byte alignment boundary--- */
    01421
    01427     const void     *p;
    01433     const void     *q;
    01439     const void     *r;
    01440
    01446     void           *privP;
    01447
    01448
    01449     /* --- 16 byte alignment boundary--- */
    01450
    01451
    01457     int64_t         a;
    01458
    01464     int32_t         b;
    01465
    01471     int32_t         c;
    01472
    01473     /*  ---- 16 byte alignment boundary---- */
    01474
    01475
    01481     int64_t         privA;
    01487     int32_t         privB;
    01493     int32_t         privC;
    01494 };
    01495
    01496
    01513 U_STABLE UText * U_EXPORT2
    01514 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
    01515
    01521 enum {
    01522     UTEXT_MAGIC = 0x345ad82c
    01523 };
    01524
    01532 #define UTEXT_INITIALIZER {                                        \
    01533                   UTEXT_MAGIC,          /* magic                */ \
    01534                   0,                    /* flags                */ \
    01535                   0,                    /* providerProps        */ \
    01536                   sizeof(UText),        /* sizeOfStruct         */ \
    01537                   0,                    /* chunkNativeLimit     */ \
    01538                   0,                    /* extraSize            */ \
    01539                   0,                    /* nativeIndexingLimit  */ \
    01540                   0,                    /* chunkNativeStart     */ \
    01541                   0,                    /* chunkOffset          */ \
    01542                   0,                    /* chunkLength          */ \
    01543                   NULL,                 /* chunkContents        */ \
    01544                   NULL,                 /* pFuncs               */ \
    01545                   NULL,                 /* pExtra               */ \
    01546                   NULL,                 /* context              */ \
    01547                   NULL, NULL, NULL,     /* p, q, r              */ \
    01548                   NULL,                 /* privP                */ \
    01549                   0, 0, 0,              /* a, b, c              */ \
    01550                   0, 0, 0               /* privA,B,C,           */ \
    01551                   }
    01552
    01553
    01554 U_CDECL_END
    01555
    01556
    01557
    01558 #endif