utext.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *
00004 *   Copyright (C) 2004-2006, 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_DRAFT UText * U_EXPORT2
00180 utext_close(UText *ut);
00181 
00182 
00204 U_DRAFT UText * U_EXPORT2
00205 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
00206 
00207 
00222 U_DRAFT 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_DRAFT UText * U_EXPORT2
00240 utext_openUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status);
00241 
00242 
00255 U_DRAFT UText * U_EXPORT2
00256 utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *status);
00257 
00258 
00271 U_DRAFT UText * U_EXPORT2
00272 utext_openReplaceable(UText *ut, Replaceable *rep, UErrorCode *status);
00273 
00286 U_DRAFT UText * U_EXPORT2
00287 utext_openCharacterIterator(UText *ut, CharacterIterator *ic, UErrorCode *status);
00288 
00289 #endif
00290 
00291 
00349 U_DRAFT UText * U_EXPORT2
00350 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
00351 
00352 
00364 U_DRAFT 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_DRAFT int64_t U_EXPORT2
00386 utext_nativeLength(UText *ut);
00387 
00401 U_DRAFT UBool U_EXPORT2
00402 utext_isLengthExpensive(const UText *ut);
00403 
00429 U_DRAFT UChar32 U_EXPORT2
00430 utext_char32At(UText *ut, int64_t nativeIndex);
00431 
00432 
00443 U_DRAFT UChar32 U_EXPORT2
00444 utext_current32(UText *ut);
00445 
00446 
00465 U_DRAFT UChar32 U_EXPORT2
00466 utext_next32(UText *ut);
00467 
00468 
00486 U_DRAFT UChar32 U_EXPORT2
00487 utext_previous32(UText *ut);
00488 
00489 
00508 U_DRAFT UChar32 U_EXPORT2
00509 utext_next32From(UText *ut, int64_t nativeIndex);
00510 
00511 
00512 
00528 U_DRAFT UChar32 U_EXPORT2
00529 utext_previous32From(UText *ut, int64_t nativeIndex);
00530 
00543 U_DRAFT int64_t U_EXPORT2
00544 utext_getNativeIndex(const UText *ut);
00545 
00569 U_DRAFT void U_EXPORT2
00570 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
00571 
00588 U_DRAFT UBool U_EXPORT2
00589 utext_moveIndex32(UText *ut, int32_t delta);
00590 
00613 U_DRAFT int64_t U_EXPORT2
00614 utext_getPreviousNativeIndex(UText *ut); 
00615 
00616 
00651 U_DRAFT 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 #ifndef U_HIDE_DRAFT_API
00659 /************************************************************************************
00660  *
00661  *  #define inline versions of selected performance-critical text access functions
00662  *          Caution:  do not use auto increment++ or decrement-- expressions
00663  *                    as parameters to these macros.
00664  *
00665  *          For most use, where there is no extreme performance constraint, the
00666  *          normal, non-inline functions are a better choice.  The resulting code
00667  *          will be smaller, and, if the need ever arises, easier to debug.
00668  *
00669  *          These are implemented as #defines rather than real functions
00670  *          because there is no fully portable way to do inline functions in plain C.
00671  *
00672  ************************************************************************************/
00673 
00685 #define UTEXT_NEXT32(ut)  \
00686     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00687     ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
00688 
00699 #define UTEXT_PREVIOUS32(ut)  \
00700     ((ut)->chunkOffset > 0 && \
00701      (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
00702           (ut)->chunkContents[--((ut)->chunkOffset)]  :  utext_previous32(ut))
00703 
00716 #define UTEXT_GETNATIVEINDEX(ut)                       \
00717     ((ut)->chunkOffset <= (ut)->nativeIndexingLimit?   \
00718         (ut)->chunkNativeStart+(ut)->chunkOffset :     \
00719         (ut)->pFuncs->mapOffsetToNative(ut))    
00720 
00721 
00722 
00723 
00724 #endif
00725 
00726 /************************************************************************************
00727  *
00728  *   Functions related to writing or modifying the text.
00729  *   These will work only with modifiable UTexts.  Attempting to
00730  *   modify a read-only UText will return an error status.
00731  *
00732  ************************************************************************************/
00733 
00734 
00753 U_DRAFT UBool U_EXPORT2
00754 utext_isWritable(const UText *ut);
00755 
00756 
00765 U_DRAFT UBool U_EXPORT2
00766 utext_hasMetaData(const UText *ut);
00767 
00768 
00796 U_DRAFT int32_t U_EXPORT2
00797 utext_replace(UText *ut,
00798              int64_t nativeStart, int64_t nativeLimit,
00799              const UChar *replacementText, int32_t replacementLength,
00800              UErrorCode *status);
00801 
00802 
00803 
00836 U_DRAFT void U_EXPORT2
00837 utext_copy(UText *ut,
00838           int64_t nativeStart, int64_t nativeLimit,
00839           int64_t destIndex,
00840           UBool move,
00841           UErrorCode *status);
00842 
00843 
00865 U_DRAFT void U_EXPORT2
00866 utext_freeze(UText *ut);
00867 
00868 
00869 #ifndef U_HIDE_DRAFT_API
00870 
00876 enum {
00881     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00888     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00895     UTEXT_PROVIDER_WRITABLE = 3,
00901     UTEXT_PROVIDER_HAS_META_DATA = 4,
00909      UTEXT_PROVIDER_OWNS_TEXT = 5
00910 };
00911 
00949 typedef UText * U_CALLCONV
00950 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
00951 
00952 
00961 typedef int64_t U_CALLCONV
00962 UTextNativeLength(UText *ut);
00963 
00989 typedef UBool U_CALLCONV
00990 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
00991 
01019 typedef int32_t U_CALLCONV
01020 UTextExtract(UText *ut,
01021              int64_t nativeStart, int64_t nativeLimit,
01022              UChar *dest, int32_t destCapacity,
01023              UErrorCode *status);
01024 
01054 typedef int32_t U_CALLCONV
01055 UTextReplace(UText *ut,
01056              int64_t nativeStart, int64_t nativeLimit,
01057              const UChar *replacementText, int32_t replacmentLength,
01058              UErrorCode *status);
01059 
01088 typedef void U_CALLCONV
01089 UTextCopy(UText *ut,
01090           int64_t nativeStart, int64_t nativeLimit,
01091           int64_t nativeDest,
01092           UBool move,
01093           UErrorCode *status);
01094 
01108 typedef int64_t U_CALLCONV
01109 UTextMapOffsetToNative(const UText *ut);
01110 
01126 typedef int32_t U_CALLCONV
01127 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
01128 
01129 
01147 typedef void U_CALLCONV
01148 UTextClose(UText *ut);
01149 
01150 
01160 struct UTextFuncs {
01175     int32_t       tableSize;
01176 
01182     int32_t       reserved1, reserved2, reserved3;
01183 
01184 
01191     UTextClone *clone;
01192 
01200     UTextNativeLength *nativeLength;
01201 
01208     UTextAccess *access;
01209 
01216     UTextExtract *extract;
01217 
01224     UTextReplace *replace;
01225 
01232     UTextCopy *copy;
01233 
01240     UTextMapOffsetToNative *mapOffsetToNative;
01241 
01248     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01249 
01256     UTextClose  *close;
01257 
01263     UTextClose  *spare1;
01268     UTextClose  *spare2;
01269 
01274     UTextClose  *spare3;
01275 
01276 };
01277 typedef struct UTextFuncs UTextFuncs;
01278 
01279 #endif
01280 
01281 #ifndef U_HIDE_DRAFT_API
01282 
01293 struct UText {
01306     uint32_t       magic;
01307 
01308 
01314     int32_t        flags;
01315 
01316 
01322     int32_t         providerProperties;
01323 
01330     int32_t         sizeOfStruct;
01331     
01332     /* ------ 16 byte alignment boundary -----------  */
01333     
01334 
01340     int64_t         chunkNativeLimit;
01341 
01346     int32_t        extraSize;
01347 
01355     int32_t         nativeIndexingLimit;
01356 
01357     /* ---- 16 byte alignment boundary------ */
01358     
01363     int64_t         chunkNativeStart;
01364 
01370     int32_t         chunkOffset;
01371 
01376     int32_t         chunkLength;
01377 
01378     /* ---- 16  byte alignment boundary-- */
01379     
01380 
01387     const UChar    *chunkContents;
01388 
01393     UTextFuncs     *pFuncs;
01394     
01400     void          *pExtra;
01401 
01408     const void   *context;
01409 
01410     /* --- 16 byte alignment boundary--- */
01411 
01417     const void     *p; 
01423     const void     *q;
01429     const void     *r;
01430 
01436     void           *privP;
01437 
01438 
01439     /* --- 16 byte alignment boundary--- */
01440     
01441 
01447     int64_t         a;
01448 
01454     int32_t         b;
01455 
01461     int32_t         c;
01462 
01463     /*  ---- 16 byte alignment boundary---- */
01464 
01465 
01471     int64_t         privA;
01477     int32_t         privB;
01483     int32_t         privC;
01484 };
01485 
01486 #endif 
01487 
01504 U_DRAFT UText * U_EXPORT2
01505 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01506 
01512 enum {
01513     UTEXT_MAGIC = 0x345ad82c
01514 };
01515 #ifndef U_HIDE_DRAFT_API
01516 
01524 #define UTEXT_INITIALIZER {                                        \
01525                   UTEXT_MAGIC,          /* magic                */ \
01526                   0,                    /* flags                */ \
01527                   0,                    /* providerProps        */ \
01528                   sizeof(UText),        /* sizeOfStruct         */ \
01529                   0,                    /* chunkNativeLimit     */ \
01530                   0,                    /* extraSize            */ \
01531                   0,                    /* nativeIndexingLimit  */ \
01532                   0,                    /* chunkNativeStart     */ \
01533                   0,                    /* chunkOffset          */ \
01534                   0,                    /* chunkLength          */ \
01535                   NULL,                 /* chunkContents        */ \
01536                   NULL,                 /* pFuncs               */ \
01537                   NULL,                 /* pExtra               */ \
01538                   NULL,                 /* context              */ \
01539                   NULL, NULL, NULL,     /* p, q, r              */ \
01540                   NULL,                 /* privP                */ \
01541                   0, 0, 0,              /* a, b, c              */ \
01542                   0, 0, 0               /* privA,B,C,           */ \
01543                   }
01544 
01545 
01546 #endif /* U_HIDE_DRAFT_API */
01547 
01548 U_CDECL_END
01549 
01550 
01551 
01552 #endif

Generated on Mon Aug 13 07:17:25 2007 for ICU 3.6 by  doxygen 1.5.2