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

- File List
- Globals

# utext.h

Go to the documentation of this file.

    00001 /*
    00002 *******************************************************************************
    00003 *
    00004 *   Copyright (C) 2004-2010, 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 #include "unicode/uchar.h"
    00140 #if U_SHOW_CPLUSPLUS_API
    00141 #include "unicode/localpointer.h"
    00142 #include "unicode/rep.h"
    00143 #include "unicode/unistr.h"
    00144 #include "unicode/chariter.h"
    00145 #endif
    00146
    00147
    00148 U_CDECL_BEGIN
    00149
    00150 struct UText;
    00151 typedef struct UText UText;
    00154 /***************************************************************************************
    00155  *
    00156  *   C Functions for creating UText wrappers around various kinds of text strings.
    00157  *
    00158  ****************************************************************************************/
    00159
    00160
    00181 U_STABLE UText * U_EXPORT2
    00182 utext_close(UText *ut);
    00183
    00184 #if U_SHOW_CPLUSPLUS_API
    00185
    00186 U_NAMESPACE_BEGIN
    00187
    00197 U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
    00198
    00199 U_NAMESPACE_END
    00200
    00201 #endif
    00202
    00224 U_STABLE UText * U_EXPORT2
    00225 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
    00226
    00227
    00242 U_STABLE UText * U_EXPORT2
    00243 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status);
    00244
    00245
    00246 #if U_SHOW_CPLUSPLUS_API
    00247
    00259 U_STABLE UText * U_EXPORT2
    00260 utext_openUnicodeString(UText *ut, U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
    00261
    00262
    00275 U_STABLE UText * U_EXPORT2
    00276 utext_openConstUnicodeString(UText *ut, const U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
    00277
    00278
    00291 U_STABLE UText * U_EXPORT2
    00292 utext_openReplaceable(UText *ut, U_NAMESPACE_QUALIFIER Replaceable *rep, UErrorCode *status);
    00293
    00306 U_STABLE UText * U_EXPORT2
    00307 utext_openCharacterIterator(UText *ut, U_NAMESPACE_QUALIFIER CharacterIterator *ic, UErrorCode *status);
    00308
    00309 #endif
    00310
    00311
    00369 U_STABLE UText * U_EXPORT2
    00370 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
    00371
    00372
    00384 U_STABLE UBool U_EXPORT2
    00385 utext_equals(const UText *a, const UText *b);
    00386
    00387
    00388 /*****************************************************************************
    00389  *
    00390  *   Functions to work with the text represeted by a UText wrapper
    00391  *
    00392  *****************************************************************************/
    00393
    00405 U_STABLE int64_t U_EXPORT2
    00406 utext_nativeLength(UText *ut);
    00407
    00421 U_STABLE UBool U_EXPORT2
    00422 utext_isLengthExpensive(const UText *ut);
    00423
    00449 U_STABLE UChar32 U_EXPORT2
    00450 utext_char32At(UText *ut, int64_t nativeIndex);
    00451
    00452
    00463 U_STABLE UChar32 U_EXPORT2
    00464 utext_current32(UText *ut);
    00465
    00466
    00485 U_STABLE UChar32 U_EXPORT2
    00486 utext_next32(UText *ut);
    00487
    00488
    00506 U_STABLE UChar32 U_EXPORT2
    00507 utext_previous32(UText *ut);
    00508
    00509
    00528 U_STABLE UChar32 U_EXPORT2
    00529 utext_next32From(UText *ut, int64_t nativeIndex);
    00530
    00531
    00532
    00548 U_STABLE UChar32 U_EXPORT2
    00549 utext_previous32From(UText *ut, int64_t nativeIndex);
    00550
    00563 U_STABLE int64_t U_EXPORT2
    00564 utext_getNativeIndex(const UText *ut);
    00565
    00589 U_STABLE void U_EXPORT2
    00590 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
    00591
    00608 U_STABLE UBool U_EXPORT2
    00609 utext_moveIndex32(UText *ut, int32_t delta);
    00610
    00633 U_STABLE int64_t U_EXPORT2
    00634 utext_getPreviousNativeIndex(UText *ut);
    00635
    00636
    00671 U_STABLE int32_t U_EXPORT2
    00672 utext_extract(UText *ut,
    00673              int64_t nativeStart, int64_t nativeLimit,
    00674              UChar *dest, int32_t destCapacity,
    00675              UErrorCode *status);
    00676
    00677
    00704 U_INTERNAL int32_t U_EXPORT2
    00705 utext_compare(UText *s1, int32_t length1,
    00706               UText *s2, int32_t length2);
    00707
    00735 U_INTERNAL int32_t U_EXPORT2
    00736 utext_compareNativeLimit(UText *s1, int64_t limit1,
    00737                          UText *s2, int64_t limit2);
    00738
    00773 U_INTERNAL int32_t U_EXPORT2
    00774 utext_caseCompare(UText *s1, int32_t length1,
    00775                   UText *s2, int32_t length2,
    00776                   uint32_t options, UErrorCode *pErrorCode);
    00777
    00814 U_INTERNAL int32_t U_EXPORT2
    00815 utext_caseCompareNativeLimit(UText *s1, int64_t limit1,
    00816                              UText *s2, int64_t limit2,
    00817                              uint32_t options, UErrorCode *pErrorCode);
    00818
    00819
    00820 /************************************************************************************
    00821  *
    00822  *  #define inline versions of selected performance-critical text access functions
    00823  *          Caution:  do not use auto increment++ or decrement-- expressions
    00824  *                    as parameters to these macros.
    00825  *
    00826  *          For most use, where there is no extreme performance constraint, the
    00827  *          normal, non-inline functions are a better choice.  The resulting code
    00828  *          will be smaller, and, if the need ever arises, easier to debug.
    00829  *
    00830  *          These are implemented as #defines rather than real functions
    00831  *          because there is no fully portable way to do inline functions in plain C.
    00832  *
    00833  ************************************************************************************/
    00834
    00844 #define UTEXT_CURRENT32(ut)  \
    00845     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
    00846     ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
    00847
    00859 #define UTEXT_NEXT32(ut)  \
    00860     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
    00861     ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
    00862
    00873 #define UTEXT_PREVIOUS32(ut)  \
    00874     ((ut)->chunkOffset > 0 && \
    00875      (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
    00876           (ut)->chunkContents[--((ut)->chunkOffset)]  :  utext_previous32(ut))
    00877
    00890 #define UTEXT_GETNATIVEINDEX(ut)                       \
    00891     ((ut)->chunkOffset <= (ut)->nativeIndexingLimit?   \
    00892         (ut)->chunkNativeStart+(ut)->chunkOffset :     \
    00893         (ut)->pFuncs->mapOffsetToNative(ut))
    00894
    00906 #define UTEXT_SETNATIVEINDEX(ut, ix)                       \
    00907     { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
    00908       if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
    00909           (ut)->chunkOffset=(int32_t)__offset; \
    00910       } else { \
    00911           utext_setNativeIndex((ut), (ix)); } }
    00912
    00913
    00914
    00915 /************************************************************************************
    00916  *
    00917  *   Functions related to writing or modifying the text.
    00918  *   These will work only with modifiable UTexts.  Attempting to
    00919  *   modify a read-only UText will return an error status.
    00920  *
    00921  ************************************************************************************/
    00922
    00923
    00942 U_STABLE UBool U_EXPORT2
    00943 utext_isWritable(const UText *ut);
    00944
    00945
    00954 U_STABLE UBool U_EXPORT2
    00955 utext_hasMetaData(const UText *ut);
    00956
    00957
    00985 U_STABLE int32_t U_EXPORT2
    00986 utext_replace(UText *ut,
    00987              int64_t nativeStart, int64_t nativeLimit,
    00988              const UChar *replacementText, int32_t replacementLength,
    00989              UErrorCode *status);
    00990
    00991
    00992
    01025 U_STABLE void U_EXPORT2
    01026 utext_copy(UText *ut,
    01027           int64_t nativeStart, int64_t nativeLimit,
    01028           int64_t destIndex,
    01029           UBool move,
    01030           UErrorCode *status);
    01031
    01032
    01054 U_STABLE void U_EXPORT2
    01055 utext_freeze(UText *ut);
    01056
    01057
    01064 enum {
    01069     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
    01076     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
    01083     UTEXT_PROVIDER_WRITABLE = 3,
    01089     UTEXT_PROVIDER_HAS_META_DATA = 4,
    01097      UTEXT_PROVIDER_OWNS_TEXT = 5
    01098 };
    01099
    01137 typedef UText * U_CALLCONV
    01138 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
    01139
    01140
    01149 typedef int64_t U_CALLCONV
    01150 UTextNativeLength(UText *ut);
    01151
    01177 typedef UBool U_CALLCONV
    01178 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
    01179
    01207 typedef int32_t U_CALLCONV
    01208 UTextExtract(UText *ut,
    01209              int64_t nativeStart, int64_t nativeLimit,
    01210              UChar *dest, int32_t destCapacity,
    01211              UErrorCode *status);
    01212
    01242 typedef int32_t U_CALLCONV
    01243 UTextReplace(UText *ut,
    01244              int64_t nativeStart, int64_t nativeLimit,
    01245              const UChar *replacementText, int32_t replacmentLength,
    01246              UErrorCode *status);
    01247
    01276 typedef void U_CALLCONV
    01277 UTextCopy(UText *ut,
    01278           int64_t nativeStart, int64_t nativeLimit,
    01279           int64_t nativeDest,
    01280           UBool move,
    01281           UErrorCode *status);
    01282
    01296 typedef int64_t U_CALLCONV
    01297 UTextMapOffsetToNative(const UText *ut);
    01298
    01314 typedef int32_t U_CALLCONV
    01315 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
    01316
    01317
    01335 typedef void U_CALLCONV
    01336 UTextClose(UText *ut);
    01337
    01338
    01348 struct UTextFuncs {
    01363     int32_t       tableSize;
    01364
    01370     int32_t       reserved1,  reserved2,  reserved3;
    01371
    01372
    01379     UTextClone *clone;
    01380
    01388     UTextNativeLength *nativeLength;
    01389
    01396     UTextAccess *access;
    01397
    01404     UTextExtract *extract;
    01405
    01412     UTextReplace *replace;
    01413
    01420     UTextCopy *copy;
    01421
    01428     UTextMapOffsetToNative *mapOffsetToNative;
    01429
    01436     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
    01437
    01444     UTextClose  *close;
    01445
    01450     UTextClose  *spare1;
    01451
    01456     UTextClose  *spare2;
    01457
    01462     UTextClose  *spare3;
    01463
    01464 };
    01469 typedef struct UTextFuncs UTextFuncs;
    01470
    01482 struct UText {
    01495     uint32_t       magic;
    01496
    01497
    01503     int32_t        flags;
    01504
    01505
    01511     int32_t         providerProperties;
    01512
    01519     int32_t         sizeOfStruct;
    01520
    01521     /* ------ 16 byte alignment boundary -----------  */
    01522
    01523
    01529     int64_t         chunkNativeLimit;
    01530
    01535     int32_t        extraSize;
    01536
    01544     int32_t         nativeIndexingLimit;
    01545
    01546     /* ---- 16 byte alignment boundary------ */
    01547
    01552     int64_t         chunkNativeStart;
    01553
    01559     int32_t         chunkOffset;
    01560
    01565     int32_t         chunkLength;
    01566
    01567     /* ---- 16  byte alignment boundary-- */
    01568
    01569
    01576     const UChar    *chunkContents;
    01577
    01582     const UTextFuncs     *pFuncs;
    01583
    01589     void          *pExtra;
    01590
    01597     const void   *context;
    01598
    01599     /* --- 16 byte alignment boundary--- */
    01600
    01606     const void     *p;
    01612     const void     *q;
    01618     const void     *r;
    01619
    01625     void           *privP;
    01626
    01627
    01628     /* --- 16 byte alignment boundary--- */
    01629
    01630
    01636     int64_t         a;
    01637
    01643     int32_t         b;
    01644
    01650     int32_t         c;
    01651
    01652     /*  ---- 16 byte alignment boundary---- */
    01653
    01654
    01660     int64_t         privA;
    01666     int32_t         privB;
    01672     int32_t         privC;
    01673 };
    01674
    01675
    01692 U_STABLE UText * U_EXPORT2
    01693 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
    01694
    01700 enum {
    01701     UTEXT_MAGIC = 0x345ad82c
    01702 };
    01703
    01711 #define UTEXT_INITIALIZER {                                        \
    01712                   UTEXT_MAGIC,          /* magic                */ \
    01713                   0,                    /* flags                */ \
    01714                   0,                    /* providerProps        */ \
    01715                   sizeof(UText),        /* sizeOfStruct         */ \
    01716                   0,                    /* chunkNativeLimit     */ \
    01717                   0,                    /* extraSize            */ \
    01718                   0,                    /* nativeIndexingLimit  */ \
    01719                   0,                    /* chunkNativeStart     */ \
    01720                   0,                    /* chunkOffset          */ \
    01721                   0,                    /* chunkLength          */ \
    01722                   NULL,                 /* chunkContents        */ \
    01723                   NULL,                 /* pFuncs               */ \
    01724                   NULL,                 /* pExtra               */ \
    01725                   NULL,                 /* context              */ \
    01726                   NULL, NULL, NULL,     /* p, q, r              */ \
    01727                   NULL,                 /* privP                */ \
    01728                   0, 0, 0,              /* a, b, c              */ \
    01729                   0, 0, 0               /* privA,B,C,           */ \
    01730                   }
    01731
    01732
    01733 U_CDECL_END
    01734
    01735
    01736
    01737 #endif

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines