ICU 73.2  73.2
utext.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 *******************************************************************************
00005 *
00006 *   Copyright (C) 2004-2012, International Business Machines
00007 *   Corporation and others.  All Rights Reserved.
00008 *
00009 *******************************************************************************
00010 *   file name:  utext.h
00011 *   encoding:   UTF-8
00012 *   tab size:   8 (not used)
00013 *   indentation:4
00014 *
00015 *   created on: 2004oct06
00016 *   created by: Markus W. Scherer
00017 */
00018 
00019 #ifndef __UTEXT_H__
00020 #define __UTEXT_H__
00021 
00140 #include "unicode/utypes.h"
00141 #include "unicode/uchar.h"
00142 #if U_SHOW_CPLUSPLUS_API
00143 #include "unicode/localpointer.h"
00144 #include "unicode/rep.h"
00145 #include "unicode/unistr.h"
00146 #include "unicode/chariter.h"
00147 #endif
00148 
00149 
00150 U_CDECL_BEGIN
00151 
00152 struct UText;
00153 typedef struct UText UText; 
00156 /***************************************************************************************
00157  *
00158  *   C Functions for creating UText wrappers around various kinds of text strings.
00159  *
00160  ****************************************************************************************/
00161 
00162 
00183 U_CAPI UText * U_EXPORT2
00184 utext_close(UText *ut);
00185 
00207 U_CAPI UText * U_EXPORT2
00208 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
00209 
00210 
00225 U_CAPI UText * U_EXPORT2
00226 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status);
00227 
00228 
00229 #if U_SHOW_CPLUSPLUS_API
00230 
00242 U_CAPI UText * U_EXPORT2
00243 utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status);
00244 
00245 
00258 U_CAPI UText * U_EXPORT2
00259 utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status);
00260 
00261 
00274 U_CAPI UText * U_EXPORT2
00275 utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status);
00276 
00289 U_CAPI UText * U_EXPORT2
00290 utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status);
00291 
00292 #endif
00293 
00294 
00352 U_CAPI UText * U_EXPORT2
00353 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
00354 
00355 
00367 U_CAPI UBool U_EXPORT2
00368 utext_equals(const UText *a, const UText *b);
00369 
00370 
00371 /*****************************************************************************
00372  *
00373  *   Functions to work with the text represented by a UText wrapper
00374  *
00375  *****************************************************************************/
00376 
00388 U_CAPI int64_t U_EXPORT2
00389 utext_nativeLength(UText *ut);
00390 
00404 U_CAPI UBool U_EXPORT2
00405 utext_isLengthExpensive(const UText *ut);
00406 
00432 U_CAPI UChar32 U_EXPORT2
00433 utext_char32At(UText *ut, int64_t nativeIndex);
00434 
00435 
00446 U_CAPI UChar32 U_EXPORT2
00447 utext_current32(UText *ut);
00448 
00449 
00468 U_CAPI UChar32 U_EXPORT2
00469 utext_next32(UText *ut);
00470 
00471 
00489 U_CAPI UChar32 U_EXPORT2
00490 utext_previous32(UText *ut);
00491 
00492 
00511 U_CAPI UChar32 U_EXPORT2
00512 utext_next32From(UText *ut, int64_t nativeIndex);
00513 
00514 
00515 
00531 U_CAPI UChar32 U_EXPORT2
00532 utext_previous32From(UText *ut, int64_t nativeIndex);
00533 
00546 U_CAPI int64_t U_EXPORT2
00547 utext_getNativeIndex(const UText *ut);
00548 
00572 U_CAPI void U_EXPORT2
00573 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
00574 
00591 U_CAPI UBool U_EXPORT2
00592 utext_moveIndex32(UText *ut, int32_t delta);
00593 
00616 U_CAPI int64_t U_EXPORT2
00617 utext_getPreviousNativeIndex(UText *ut); 
00618 
00619 
00654 U_CAPI int32_t U_EXPORT2
00655 utext_extract(UText *ut,
00656              int64_t nativeStart, int64_t nativeLimit,
00657              UChar *dest, int32_t destCapacity,
00658              UErrorCode *status);
00659 
00660 
00661 
00662 /************************************************************************************
00663  *
00664  *  #define inline versions of selected performance-critical text access functions
00665  *          Caution:  do not use auto increment++ or decrement-- expressions
00666  *                    as parameters to these macros.
00667  *
00668  *          For most use, where there is no extreme performance constraint, the
00669  *          normal, non-inline functions are a better choice.  The resulting code
00670  *          will be smaller, and, if the need ever arises, easier to debug.
00671  *
00672  *          These are implemented as #defines rather than real functions
00673  *          because there is no fully portable way to do inline functions in plain C.
00674  *
00675  ************************************************************************************/
00676 
00677 #ifndef U_HIDE_INTERNAL_API
00678 
00687 #define UTEXT_CURRENT32(ut)  \
00688     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00689     ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
00690 #endif  /* U_HIDE_INTERNAL_API */
00691 
00703 #define UTEXT_NEXT32(ut)  \
00704     ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00705     ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
00706 
00717 #define UTEXT_PREVIOUS32(ut)  \
00718     ((ut)->chunkOffset > 0 && \
00719      (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
00720           (ut)->chunkContents[--((ut)->chunkOffset)]  :  utext_previous32(ut))
00721 
00734 #define UTEXT_GETNATIVEINDEX(ut)                       \
00735     ((ut)->chunkOffset <= (ut)->nativeIndexingLimit?   \
00736         (ut)->chunkNativeStart+(ut)->chunkOffset :     \
00737         (ut)->pFuncs->mapOffsetToNative(ut))    
00738 
00750 #define UTEXT_SETNATIVEINDEX(ut, ix) UPRV_BLOCK_MACRO_BEGIN { \
00751     int64_t __offset = (ix) - (ut)->chunkNativeStart; \
00752     if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \
00753         (ut)->chunkOffset=(int32_t)__offset; \
00754     } else { \
00755         utext_setNativeIndex((ut), (ix)); \
00756     } \
00757 } UPRV_BLOCK_MACRO_END
00758 
00759 
00760 
00761 /************************************************************************************
00762  *
00763  *   Functions related to writing or modifying the text.
00764  *   These will work only with modifiable UTexts.  Attempting to
00765  *   modify a read-only UText will return an error status.
00766  *
00767  ************************************************************************************/
00768 
00769 
00788 U_CAPI UBool U_EXPORT2
00789 utext_isWritable(const UText *ut);
00790 
00791 
00800 U_CAPI UBool U_EXPORT2
00801 utext_hasMetaData(const UText *ut);
00802 
00803 
00831 U_CAPI int32_t U_EXPORT2
00832 utext_replace(UText *ut,
00833              int64_t nativeStart, int64_t nativeLimit,
00834              const UChar *replacementText, int32_t replacementLength,
00835              UErrorCode *status);
00836 
00837 
00838 
00871 U_CAPI void U_EXPORT2
00872 utext_copy(UText *ut,
00873           int64_t nativeStart, int64_t nativeLimit,
00874           int64_t destIndex,
00875           UBool move,
00876           UErrorCode *status);
00877 
00878 
00900 U_CAPI void U_EXPORT2
00901 utext_freeze(UText *ut);
00902 
00903 
00910 enum {
00915     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00922     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00929     UTEXT_PROVIDER_WRITABLE = 3,
00935     UTEXT_PROVIDER_HAS_META_DATA = 4,
00943      UTEXT_PROVIDER_OWNS_TEXT = 5
00944 };
00945 
00983 typedef UText * U_CALLCONV
00984 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
00985 
00986 
00995 typedef int64_t U_CALLCONV
00996 UTextNativeLength(UText *ut);
00997 
01023 typedef UBool U_CALLCONV
01024 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
01025 
01053 typedef int32_t U_CALLCONV
01054 UTextExtract(UText *ut,
01055              int64_t nativeStart, int64_t nativeLimit,
01056              UChar *dest, int32_t destCapacity,
01057              UErrorCode *status);
01058 
01088 typedef int32_t U_CALLCONV
01089 UTextReplace(UText *ut,
01090              int64_t nativeStart, int64_t nativeLimit,
01091              const UChar *replacementText, int32_t replacmentLength,
01092              UErrorCode *status);
01093 
01122 typedef void U_CALLCONV
01123 UTextCopy(UText *ut,
01124           int64_t nativeStart, int64_t nativeLimit,
01125           int64_t nativeDest,
01126           UBool move,
01127           UErrorCode *status);
01128 
01142 typedef int64_t U_CALLCONV
01143 UTextMapOffsetToNative(const UText *ut);
01144 
01160 typedef int32_t U_CALLCONV
01161 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
01162 
01163 
01181 typedef void U_CALLCONV
01182 UTextClose(UText *ut);
01183 
01184 
01194 struct UTextFuncs {
01209     int32_t       tableSize;
01210 
01216     int32_t       reserved1,  reserved2,  reserved3;
01217 
01218 
01225     UTextClone *clone;
01226 
01234     UTextNativeLength *nativeLength;
01235 
01242     UTextAccess *access;
01243 
01250     UTextExtract *extract;
01251 
01258     UTextReplace *replace;
01259 
01266     UTextCopy *copy;
01267 
01274     UTextMapOffsetToNative *mapOffsetToNative;
01275 
01282     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01283 
01290     UTextClose  *close;
01291 
01296     UTextClose  *spare1;
01297     
01302     UTextClose  *spare2;
01303 
01308     UTextClose  *spare3;
01309 
01310 };
01315 typedef struct UTextFuncs UTextFuncs;
01316 
01328 struct UText {
01341     uint32_t       magic;
01342 
01343 
01349     int32_t        flags;
01350 
01351 
01357     int32_t         providerProperties;
01358 
01365     int32_t         sizeOfStruct;
01366     
01367     /* ------ 16 byte alignment boundary -----------  */
01368     
01369 
01375     int64_t         chunkNativeLimit;
01376 
01381     int32_t        extraSize;
01382 
01390     int32_t         nativeIndexingLimit;
01391 
01392     /* ---- 16 byte alignment boundary------ */
01393     
01398     int64_t         chunkNativeStart;
01399 
01405     int32_t         chunkOffset;
01406 
01411     int32_t         chunkLength;
01412 
01413     /* ---- 16  byte alignment boundary-- */
01414     
01415 
01422     const UChar    *chunkContents;
01423 
01428     const UTextFuncs     *pFuncs;
01429 
01435     void          *pExtra;
01436 
01443     const void   *context;
01444 
01445     /* --- 16 byte alignment boundary--- */
01446 
01452     const void     *p; 
01458     const void     *q;
01464     const void     *r;
01465 
01471     void           *privP;
01472 
01473 
01474     /* --- 16 byte alignment boundary--- */
01475     
01476 
01482     int64_t         a;
01483 
01489     int32_t         b;
01490 
01496     int32_t         c;
01497 
01498     /*  ---- 16 byte alignment boundary---- */
01499 
01500 
01506     int64_t         privA;
01512     int32_t         privB;
01518     int32_t         privC;
01519 };
01520 
01521 
01538 U_CAPI UText * U_EXPORT2
01539 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01540 
01541 // do not use #ifndef U_HIDE_INTERNAL_API around the following!
01547 enum {
01548     UTEXT_MAGIC = 0x345ad82c
01549 };
01550 
01558 #define UTEXT_INITIALIZER {                                        \
01559                   UTEXT_MAGIC,          /* magic                */ \
01560                   0,                    /* flags                */ \
01561                   0,                    /* providerProps        */ \
01562                   sizeof(UText),        /* sizeOfStruct         */ \
01563                   0,                    /* chunkNativeLimit     */ \
01564                   0,                    /* extraSize            */ \
01565                   0,                    /* nativeIndexingLimit  */ \
01566                   0,                    /* chunkNativeStart     */ \
01567                   0,                    /* chunkOffset          */ \
01568                   0,                    /* chunkLength          */ \
01569                   NULL,                 /* chunkContents        */ \
01570                   NULL,                 /* pFuncs               */ \
01571                   NULL,                 /* pExtra               */ \
01572                   NULL,                 /* context              */ \
01573                   NULL, NULL, NULL,     /* p, q, r              */ \
01574                   NULL,                 /* privP                */ \
01575                   0, 0, 0,              /* a, b, c              */ \
01576                   0, 0, 0               /* privA,B,C,           */ \
01577                   }
01578 
01579 
01580 U_CDECL_END
01581 
01582 
01583 #if U_SHOW_CPLUSPLUS_API
01584 
01585 U_NAMESPACE_BEGIN
01586 
01596 U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
01597 
01598 U_NAMESPACE_END
01599 
01600 #endif
01601 
01602 
01603 #endif