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_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, U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
00241 
00242 
00255 U_DRAFT UText * U_EXPORT2
00256 utext_openConstUnicodeString(UText *ut, const U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status);
00257 
00258 
00271 U_DRAFT UText * U_EXPORT2
00272 utext_openReplaceable(UText *ut, U_NAMESPACE_QUALIFIER Replaceable *rep, UErrorCode *status);
00273 
00286 U_DRAFT UText * U_EXPORT2
00287 utext_openCharacterIterator(UText *ut, U_NAMESPACE_QUALIFIER 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 
00732 #define UTEXT_SETNATIVEINDEX(ut, ix)                       \
00733     { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
00734       if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
00735           (ut)->chunkOffset=(int32_t)__offset; \
00736       } else { \
00737           utext_setNativeIndex((ut), (ix)); } }
00738 
00739 
00740 
00741 #endif
00742 
00743 /************************************************************************************
00744  *
00745  *   Functions related to writing or modifying the text.
00746  *   These will work only with modifiable UTexts.  Attempting to
00747  *   modify a read-only UText will return an error status.
00748  *
00749  ************************************************************************************/
00750 
00751 
00770 U_DRAFT UBool U_EXPORT2
00771 utext_isWritable(const UText *ut);
00772 
00773 
00782 U_DRAFT UBool U_EXPORT2
00783 utext_hasMetaData(const UText *ut);
00784 
00785 
00813 U_DRAFT int32_t U_EXPORT2
00814 utext_replace(UText *ut,
00815              int64_t nativeStart, int64_t nativeLimit,
00816              const UChar *replacementText, int32_t replacementLength,
00817              UErrorCode *status);
00818 
00819 
00820 
00853 U_DRAFT void U_EXPORT2
00854 utext_copy(UText *ut,
00855           int64_t nativeStart, int64_t nativeLimit,
00856           int64_t destIndex,
00857           UBool move,
00858           UErrorCode *status);
00859 
00860 
00882 U_DRAFT void U_EXPORT2
00883 utext_freeze(UText *ut);
00884 
00885 
00886 #ifndef U_HIDE_DRAFT_API
00887 
00893 enum {
00898     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00905     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00912     UTEXT_PROVIDER_WRITABLE = 3,
00918     UTEXT_PROVIDER_HAS_META_DATA = 4,
00926      UTEXT_PROVIDER_OWNS_TEXT = 5
00927 };
00928 
00966 typedef UText * U_CALLCONV
00967 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
00968 
00969 
00978 typedef int64_t U_CALLCONV
00979 UTextNativeLength(UText *ut);
00980 
01006 typedef UBool U_CALLCONV
01007 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
01008 
01036 typedef int32_t U_CALLCONV
01037 UTextExtract(UText *ut,
01038              int64_t nativeStart, int64_t nativeLimit,
01039              UChar *dest, int32_t destCapacity,
01040              UErrorCode *status);
01041 
01071 typedef int32_t U_CALLCONV
01072 UTextReplace(UText *ut,
01073              int64_t nativeStart, int64_t nativeLimit,
01074              const UChar *replacementText, int32_t replacmentLength,
01075              UErrorCode *status);
01076 
01105 typedef void U_CALLCONV
01106 UTextCopy(UText *ut,
01107           int64_t nativeStart, int64_t nativeLimit,
01108           int64_t nativeDest,
01109           UBool move,
01110           UErrorCode *status);
01111 
01125 typedef int64_t U_CALLCONV
01126 UTextMapOffsetToNative(const UText *ut);
01127 
01143 typedef int32_t U_CALLCONV
01144 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
01145 
01146 
01164 typedef void U_CALLCONV
01165 UTextClose(UText *ut);
01166 
01167 
01177 struct UTextFuncs {
01192     int32_t       tableSize;
01193 
01199     int32_t       reserved1, reserved2, reserved3;
01200 
01201 
01208     UTextClone *clone;
01209 
01217     UTextNativeLength *nativeLength;
01218 
01225     UTextAccess *access;
01226 
01233     UTextExtract *extract;
01234 
01241     UTextReplace *replace;
01242 
01249     UTextCopy *copy;
01250 
01257     UTextMapOffsetToNative *mapOffsetToNative;
01258 
01265     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01266 
01273     UTextClose  *close;
01274 
01280     UTextClose  *spare1;
01285     UTextClose  *spare2;
01286 
01291     UTextClose  *spare3;
01292 
01293 };
01294 typedef struct UTextFuncs UTextFuncs;
01295 
01296 #endif
01297 
01298 #ifndef U_HIDE_DRAFT_API
01299 
01310 struct UText {
01323     uint32_t       magic;
01324 
01325 
01331     int32_t        flags;
01332 
01333 
01339     int32_t         providerProperties;
01340 
01347     int32_t         sizeOfStruct;
01348     
01349     /* ------ 16 byte alignment boundary -----------  */
01350     
01351 
01357     int64_t         chunkNativeLimit;
01358 
01363     int32_t        extraSize;
01364 
01372     int32_t         nativeIndexingLimit;
01373 
01374     /* ---- 16 byte alignment boundary------ */
01375     
01380     int64_t         chunkNativeStart;
01381 
01387     int32_t         chunkOffset;
01388 
01393     int32_t         chunkLength;
01394 
01395     /* ---- 16  byte alignment boundary-- */
01396     
01397 
01404     const UChar    *chunkContents;
01405 
01410     UTextFuncs     *pFuncs;
01411     
01417     void          *pExtra;
01418 
01425     const void   *context;
01426 
01427     /* --- 16 byte alignment boundary--- */
01428 
01434     const void     *p; 
01440     const void     *q;
01446     const void     *r;
01447 
01453     void           *privP;
01454 
01455 
01456     /* --- 16 byte alignment boundary--- */
01457     
01458 
01464     int64_t         a;
01465 
01471     int32_t         b;
01472 
01478     int32_t         c;
01479 
01480     /*  ---- 16 byte alignment boundary---- */
01481 
01482 
01488     int64_t         privA;
01494     int32_t         privB;
01500     int32_t         privC;
01501 };
01502 
01503 #endif 
01504 
01521 U_DRAFT UText * U_EXPORT2
01522 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01523 
01529 enum {
01530     UTEXT_MAGIC = 0x345ad82c
01531 };
01532 #ifndef U_HIDE_DRAFT_API
01533 
01541 #define UTEXT_INITIALIZER {                                        \
01542                   UTEXT_MAGIC,          /* magic                */ \
01543                   0,                    /* flags                */ \
01544                   0,                    /* providerProps        */ \
01545                   sizeof(UText),        /* sizeOfStruct         */ \
01546                   0,                    /* chunkNativeLimit     */ \
01547                   0,                    /* extraSize            */ \
01548                   0,                    /* nativeIndexingLimit  */ \
01549                   0,                    /* chunkNativeStart     */ \
01550                   0,                    /* chunkOffset          */ \
01551                   0,                    /* chunkLength          */ \
01552                   NULL,                 /* chunkContents        */ \
01553                   NULL,                 /* pFuncs               */ \
01554                   NULL,                 /* pExtra               */ \
01555                   NULL,                 /* context              */ \
01556                   NULL, NULL, NULL,     /* p, q, r              */ \
01557                   NULL,                 /* privP                */ \
01558                   0, 0, 0,              /* a, b, c              */ \
01559                   0, 0, 0               /* privA,B,C,           */ \
01560                   }
01561 
01562 
01563 #endif /* U_HIDE_DRAFT_API */
01564 
01565 U_CDECL_END
01566 
01567 
01568 
01569 #endif

Generated on Wed Aug 8 04:08:14 2007 for ICU 3.8 by  doxygen 1.5.2