ICU 49.1.1  49.1.1
utext.h
Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *
00004 *   Copyright (C) 2004-2012, 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, icu::UnicodeString *s, UErrorCode *status);
00261 
00262 
00275 U_STABLE UText * U_EXPORT2
00276 utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status);
00277 
00278 
00291 U_STABLE UText * U_EXPORT2
00292 utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status);
00293 
00306 U_STABLE UText * U_EXPORT2
00307 utext_openCharacterIterator(UText *ut, icu::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 
00678 
00679 /************************************************************************************
00680  *
00681  *  #define inline versions of selected performance-critical text access functions
00682  *          Caution:  do not use auto increment++ or decrement-- expressions
00683  *                    as parameters to these macros.
00684  *
00685  *          For most use, where there is no extreme performance constraint, the
00686  *          normal, non-inline functions are a better choice.  The resulting code
00687  *          will be smaller, and, if the need ever arises, easier to debug.
00688  *
00689  *          These are implemented as #defines rather than real functions
00690  *          because there is no fully portable way to do inline functions in plain C.
00691  *
00692  ************************************************************************************/
00693 
00694 #ifndef U_HIDE_INTERNAL_API
00695 
00704 #define UTEXT_CURRENT32(ut)  \
00705     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00706     ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
00707 #endif  /* U_HIDE_INTERNAL_API */
00708 
00720 #define UTEXT_NEXT32(ut)  \
00721     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00722     ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
00723 
00734 #define UTEXT_PREVIOUS32(ut)  \
00735     ((ut)->chunkOffset > 0 && \
00736      (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
00737           (ut)->chunkContents[--((ut)->chunkOffset)]  :  utext_previous32(ut))
00738 
00751 #define UTEXT_GETNATIVEINDEX(ut)                       \
00752     ((ut)->chunkOffset <= (ut)->nativeIndexingLimit?   \
00753         (ut)->chunkNativeStart+(ut)->chunkOffset :     \
00754         (ut)->pFuncs->mapOffsetToNative(ut))    
00755 
00767 #define UTEXT_SETNATIVEINDEX(ut, ix)                       \
00768     { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
00769       if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
00770           (ut)->chunkOffset=(int32_t)__offset; \
00771       } else { \
00772           utext_setNativeIndex((ut), (ix)); } }
00773 
00774 
00775 
00776 /************************************************************************************
00777  *
00778  *   Functions related to writing or modifying the text.
00779  *   These will work only with modifiable UTexts.  Attempting to
00780  *   modify a read-only UText will return an error status.
00781  *
00782  ************************************************************************************/
00783 
00784 
00803 U_STABLE UBool U_EXPORT2
00804 utext_isWritable(const UText *ut);
00805 
00806 
00815 U_STABLE UBool U_EXPORT2
00816 utext_hasMetaData(const UText *ut);
00817 
00818 
00846 U_STABLE int32_t U_EXPORT2
00847 utext_replace(UText *ut,
00848              int64_t nativeStart, int64_t nativeLimit,
00849              const UChar *replacementText, int32_t replacementLength,
00850              UErrorCode *status);
00851 
00852 
00853 
00886 U_STABLE void U_EXPORT2
00887 utext_copy(UText *ut,
00888           int64_t nativeStart, int64_t nativeLimit,
00889           int64_t destIndex,
00890           UBool move,
00891           UErrorCode *status);
00892 
00893 
00915 U_STABLE void U_EXPORT2
00916 utext_freeze(UText *ut);
00917 
00918 
00925 enum {
00930     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00937     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00944     UTEXT_PROVIDER_WRITABLE = 3,
00950     UTEXT_PROVIDER_HAS_META_DATA = 4,
00958      UTEXT_PROVIDER_OWNS_TEXT = 5
00959 };
00960 
00998 typedef UText * U_CALLCONV
00999 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
01000 
01001 
01010 typedef int64_t U_CALLCONV
01011 UTextNativeLength(UText *ut);
01012 
01038 typedef UBool U_CALLCONV
01039 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
01040 
01068 typedef int32_t U_CALLCONV
01069 UTextExtract(UText *ut,
01070              int64_t nativeStart, int64_t nativeLimit,
01071              UChar *dest, int32_t destCapacity,
01072              UErrorCode *status);
01073 
01103 typedef int32_t U_CALLCONV
01104 UTextReplace(UText *ut,
01105              int64_t nativeStart, int64_t nativeLimit,
01106              const UChar *replacementText, int32_t replacmentLength,
01107              UErrorCode *status);
01108 
01137 typedef void U_CALLCONV
01138 UTextCopy(UText *ut,
01139           int64_t nativeStart, int64_t nativeLimit,
01140           int64_t nativeDest,
01141           UBool move,
01142           UErrorCode *status);
01143 
01157 typedef int64_t U_CALLCONV
01158 UTextMapOffsetToNative(const UText *ut);
01159 
01175 typedef int32_t U_CALLCONV
01176 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
01177 
01178 
01196 typedef void U_CALLCONV
01197 UTextClose(UText *ut);
01198 
01199 
01209 struct UTextFuncs {
01224     int32_t       tableSize;
01225 
01231     int32_t       reserved1,  reserved2,  reserved3;
01232 
01233 
01240     UTextClone *clone;
01241 
01249     UTextNativeLength *nativeLength;
01250 
01257     UTextAccess *access;
01258 
01265     UTextExtract *extract;
01266 
01273     UTextReplace *replace;
01274 
01281     UTextCopy *copy;
01282 
01289     UTextMapOffsetToNative *mapOffsetToNative;
01290 
01297     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01298 
01305     UTextClose  *close;
01306 
01311     UTextClose  *spare1;
01312     
01317     UTextClose  *spare2;
01318 
01323     UTextClose  *spare3;
01324 
01325 };
01330 typedef struct UTextFuncs UTextFuncs;
01331 
01343 struct UText {
01356     uint32_t       magic;
01357 
01358 
01364     int32_t        flags;
01365 
01366 
01372     int32_t         providerProperties;
01373 
01380     int32_t         sizeOfStruct;
01381     
01382     /* ------ 16 byte alignment boundary -----------  */
01383     
01384 
01390     int64_t         chunkNativeLimit;
01391 
01396     int32_t        extraSize;
01397 
01405     int32_t         nativeIndexingLimit;
01406 
01407     /* ---- 16 byte alignment boundary------ */
01408     
01413     int64_t         chunkNativeStart;
01414 
01420     int32_t         chunkOffset;
01421 
01426     int32_t         chunkLength;
01427 
01428     /* ---- 16  byte alignment boundary-- */
01429     
01430 
01437     const UChar    *chunkContents;
01438 
01443     const UTextFuncs     *pFuncs;
01444 
01450     void          *pExtra;
01451 
01458     const void   *context;
01459 
01460     /* --- 16 byte alignment boundary--- */
01461 
01467     const void     *p; 
01473     const void     *q;
01479     const void     *r;
01480 
01486     void           *privP;
01487 
01488 
01489     /* --- 16 byte alignment boundary--- */
01490     
01491 
01497     int64_t         a;
01498 
01504     int32_t         b;
01505 
01511     int32_t         c;
01512 
01513     /*  ---- 16 byte alignment boundary---- */
01514 
01515 
01521     int64_t         privA;
01527     int32_t         privB;
01533     int32_t         privC;
01534 };
01535 
01536 
01553 U_STABLE UText * U_EXPORT2
01554 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01555 
01556 #ifndef U_HIDE_INTERNAL_API
01557 
01562 enum {
01563     UTEXT_MAGIC = 0x345ad82c
01564 };
01565 #endif  /* U_HIDE_INTERNAL_API */
01566 
01574 #define UTEXT_INITIALIZER {                                        \
01575                   UTEXT_MAGIC,          /* magic                */ \
01576                   0,                    /* flags                */ \
01577                   0,                    /* providerProps        */ \
01578                   sizeof(UText),        /* sizeOfStruct         */ \
01579                   0,                    /* chunkNativeLimit     */ \
01580                   0,                    /* extraSize            */ \
01581                   0,                    /* nativeIndexingLimit  */ \
01582                   0,                    /* chunkNativeStart     */ \
01583                   0,                    /* chunkOffset          */ \
01584                   0,                    /* chunkLength          */ \
01585                   NULL,                 /* chunkContents        */ \
01586                   NULL,                 /* pFuncs               */ \
01587                   NULL,                 /* pExtra               */ \
01588                   NULL,                 /* context              */ \
01589                   NULL, NULL, NULL,     /* p, q, r              */ \
01590                   NULL,                 /* privP                */ \
01591                   0, 0, 0,              /* a, b, c              */ \
01592                   0, 0, 0               /* privA,B,C,           */ \
01593                   }
01594 
01595 
01596 U_CDECL_END
01597 
01598 
01599 
01600 #endif