utext.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *
00004 *   Copyright (C) 2004-2005, 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 
00109 #include "unicode/utypes.h"
00110 #ifdef XP_CPLUSPLUS
00111 #include "unicode/rep.h"
00112 #include "unicode/unistr.h"
00113 #endif
00114 
00115 #ifndef U_HIDE_DRAFT_API
00116 
00117 U_CDECL_BEGIN
00118 
00119 struct UText;
00120 typedef struct UText UText; 
00122 struct UTextChunk;
00123 typedef struct UTextChunk UTextChunk; 
00127 /***************************************************************************************
00128  *
00129  *   C Functions for creating UText wrappers around various kinds of text strings.
00130  *
00131  ****************************************************************************************/
00132 
00133 
00155 U_DRAFT UText * U_EXPORT2
00156 utext_close(UText *ut);
00157 
00158 
00180 U_DRAFT UText * U_EXPORT2
00181 utext_openUTF8(UText *ut, const char *s, int32_t length, UErrorCode *status);
00182 
00183 
00198 U_DRAFT UText * U_EXPORT2
00199 utext_openUChars(UText *ut, const UChar *s, int32_t length, UErrorCode *status);
00200 
00201 
00202 #ifdef XP_CPLUSPLUS
00203 
00215 U_DRAFT UText * U_EXPORT2
00216 utext_openUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status);
00217 
00218 
00231 U_DRAFT UText * U_EXPORT2
00232 utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *status);
00233 
00234 
00247 U_DRAFT UText * U_EXPORT2
00248 utext_openReplaceable(UText *ut, Replaceable *rep, UErrorCode *status);
00249 
00250 #endif
00251 
00252 
00286 U_DRAFT UText * U_EXPORT2
00287 utext_clone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
00288 
00289 
00290 /*****************************************************************************
00291  *
00292  *   C Functions to work with the text represeted by a UText wrapper
00293  *
00294  *****************************************************************************/
00295 
00307 U_DRAFT int32_t U_EXPORT2
00308 utext_nativeLength(UText *ut);
00309 
00323 U_DRAFT UBool U_EXPORT2
00324 utext_isLengthExpensive(const UText *ut);
00325 
00348 U_DRAFT UChar32 U_EXPORT2
00349 utext_char32At(UText *ut, int32_t nativeIndex);
00350 
00351 
00362 U_DRAFT UChar32 U_EXPORT2
00363 utext_current32(UText *ut);
00364 
00365 
00381 U_DRAFT UChar32 U_EXPORT2
00382 utext_next32(UText *ut);
00383 
00384 
00401 U_DRAFT UChar32 U_EXPORT2
00402 utext_previous32(UText *ut);
00403 
00404 
00419 U_DRAFT UChar32 U_EXPORT2
00420 utext_next32From(UText *ut, int32_t nativeIndex);
00421 
00422 
00423 
00439 U_DRAFT UChar32 U_EXPORT2
00440 utext_previous32From(UText *ut, int32_t nativeIndex);
00441 
00454 U_DRAFT int32_t U_EXPORT2
00455 utext_getNativeIndex(UText *ut);
00456 
00480 U_DRAFT void U_EXPORT2
00481 utext_setNativeIndex(UText *ut, int32_t nativeIndex);
00482 
00503 U_DRAFT UBool U_EXPORT2
00504 utext_moveIndex32(UText *ut, int32_t delta);
00505 
00506 
00536 U_DRAFT int32_t U_EXPORT2
00537 utext_extract(UText *ut,
00538              int32_t nativeStart, int32_t nativeLimit,
00539              UChar *dest, int32_t destCapacity,
00540              UErrorCode *status);
00541 
00542 
00543 
00544 /************************************************************************************
00545  *
00546  *  #define inline versions of selected performance-critical text access functions
00547  *          Caution:  do not use auto increment++ or decrement-- expressions
00548  *                    as parameters to these macros.
00549  *
00550  *          For most use, where there is no extreme performance constraint, the
00551  *          normal, non-inline functions are a better choice.  The resulting code
00552  *          will be smaller, and, if the need ever arises, easier to debug.
00553  *
00554  *          These are implemented as #defines rather than real functions
00555  *          because there is no fully portable way to do inline functions in plain C.
00556  *
00557  ************************************************************************************/
00558 
00570 #define UTEXT_NEXT32(ut)  \
00571     ((ut)->chunk.offset < (ut)->chunk.length && ((ut)->chunk.contents)[(ut)->chunk.offset]<0xd800 ? \
00572     ((ut)->chunk.contents)[((ut)->chunk.offset)++] : utext_next32(ut))
00573 
00584 #define UTEXT_PREVIOUS32(ut)  \
00585     ((ut)->chunk.offset > 0 && \
00586      (ut)->chunk.contents[(ut)->chunk.offset-1] < 0xd800 ? \
00587           (ut)->chunk.contents[--((ut)->chunk.offset)]  :  utext_previous32(ut))
00588 
00589 
00590 
00591 
00592 /************************************************************************************
00593  *
00594  *   Functions related to writing or modifying the text.
00595  *   These will work only with modifiable UTexts.  Attempting to
00596  *   modify a read-only UText will return an error status.
00597  *
00598  ************************************************************************************/
00599 
00600 
00611 U_DRAFT UBool U_EXPORT2
00612 utext_isWritable(const UText *ut);
00613 
00614 
00623 U_DRAFT UBool U_EXPORT2
00624 utext_hasMetaData(const UText *ut);
00625 
00626 
00654 U_DRAFT int32_t U_EXPORT2
00655 utext_replace(UText *ut,
00656              int32_t nativeStart, int32_t nativeLimit,
00657              const UChar *replacementText, int32_t replacementLength,
00658              UErrorCode *status);
00659 
00660 
00661 
00689 U_DRAFT void U_EXPORT2
00690 utext_copy(UText *ut,
00691           int32_t nativeStart, int32_t nativeLimit,
00692           int32_t destIndex,
00693           UBool move,
00694           UErrorCode *status);
00695 
00696 
00697 
00698 
00699 
00700 /****************************************************************************************
00701  *
00702  *   The following items are required by text providers implementations -
00703  *    by packages that are writing UText wrappers for additional types of text strings.
00704  *    These declarations are not needed by applications that use already existing
00705  *    UText functions for wrapping strings or accessing text data that has been
00706  *    wrapped in a UText.
00707  *
00708  *****************************************************************************************/
00709 
00710 
00723 struct UTextChunk {
00725     const UChar *contents;
00726 
00728     int32_t     offset;  
00729 
00731     int32_t     length;
00732 
00734     int32_t     nativeStart;
00735 
00737     int32_t     nativeLimit;
00738 
00740     UBool       nonUTF16Indexes;
00741 
00743     UBool       padding1, padding2, padding3;
00744 
00746     int32_t     padInt1, padInt2;
00747 
00749     int32_t     sizeOfStruct;
00750 };
00751 
00752 
00759 enum {
00765     UTEXT_PROVIDER_NON_UTF16_INDEXES = 0,
00770     UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00777     UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00784     UTEXT_PROVIDER_WRITABLE = 3,
00790     UTEXT_PROVIDER_HAS_META_DATA = 4
00791 };
00792 
00830 typedef UText * U_CALLCONV
00831 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
00832 
00833 
00842 typedef int32_t U_CALLCONV
00843 UTextNativeLength(UText *ut);
00844 
00870 typedef UBool U_CALLCONV
00871 UTextAccess(UText *ut, int32_t nativeIndex, UBool forward, UTextChunk *chunk);
00872 
00900 typedef int32_t U_CALLCONV
00901 UTextExtract(UText *ut,
00902              int32_t nativeStart, int32_t nativeLimit,
00903              UChar *dest, int32_t destCapacity,
00904              UErrorCode *status);
00905 
00935 typedef int32_t U_CALLCONV
00936 UTextReplace(UText *ut,
00937              int32_t nativeStart, int32_t nativeLimit,
00938              const UChar *replacementText, int32_t replacmentLength,
00939              UErrorCode *status);
00940 
00969 typedef void U_CALLCONV
00970 UTextCopy(UText *ut,
00971           int32_t nativeStart, int32_t nativeLimit,
00972           int32_t nativeDest,
00973           UBool move,
00974           UErrorCode *status);
00975 
00993 typedef int32_t U_CALLCONV
00994 UTextMapOffsetToNative(UText *ut, int32_t offset);
00995 
01010 typedef int32_t U_CALLCONV
01011 UTextMapNativeIndexToUTF16(UText *ut, int32_t nativeIndex);
01012 
01013 
01031 typedef void U_CALLCONV
01032 UTextClose(UText *ut);
01033 
01034 
01046 struct UText {
01052     const void *context;
01053 
01059     const void *p, *q, *r;
01060 
01066     void          *pExtra;
01067 
01072     int32_t        extraSize;
01073 
01079     int32_t        flags;
01080 
01092     uint32_t       magic;
01093 
01094 
01101     int32_t         sizeOfStruct;
01102 
01108     int32_t         a, b, c;
01109 
01110 
01116     int32_t providerProperties;     
01117 
01118 
01119 
01124     UTextChunk      chunk;   
01125 
01126 
01133     UTextClone *clone;
01134 
01142     UTextNativeLength *nativeLength;
01143 
01150     UTextAccess *access;
01151 
01158     UTextExtract *extract;
01159 
01166     UTextReplace *replace;
01167 
01174     UTextCopy *copy;
01175 
01182     UTextMapOffsetToNative *mapOffsetToNative;
01183 
01190     UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01191 
01198     UTextClose  *close;
01199 };
01200 
01201 
01218 U_DRAFT UText * U_EXPORT2
01219 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01220 
01224 enum {
01225     UTEXT_MAGIC = 0x345ad82c
01226 };
01227 
01228 
01233 #define UTEXT_CHUNK_INIT   {                               \
01234                   NULL,                /* contents      */ \
01235                   0,                   /* offset        */ \
01236                   0,                   /* length        */ \
01237                   0,                   /* start         */ \
01238                   0,                   /* limit         */ \
01239                   FALSE,               /* nonUTF16idx   */ \
01240                   FALSE, FALSE, FALSE, /* padding1,2,3  */ \
01241                   0, 0,                /* padInt1, 2    */ \
01242                   sizeof(UTextChunk)                       \
01243 }               
01244 
01245 
01246 
01253 #define UTEXT_INITIALIZER_HEAD  \
01254                   NULL,                 /* context       */ \
01255                   NULL, NULL, NULL,     /* p, q, r       */ \
01256                   NULL,                 /* pExtra        */ \
01257                   0,                    /* extraSize     */ \
01258                   0,                    /* flags         */ \
01259                   UTEXT_MAGIC,          /* magic         */ \
01260                   sizeof(UText),        /* sizeOfStruct  */ \
01261                   0, 0, 0,              /* a, b, c       */ \
01262                   0,                    /* providerProps */ \
01263                   UTEXT_CHUNK_INIT      /* UTextChunk    */
01264 
01265 
01266 
01274 #define UTEXT_INITIALIZER {                                \
01275                   UTEXT_INITIALIZER_HEAD,                  \
01276                   NULL,                 /* clone ()     */ \
01277                   NULL,                 /* length ()    */ \
01278                   NULL,                 /* access ()    */ \
01279                   NULL,                 /* extract ()   */ \
01280                   NULL,                 /* replace ()   */ \
01281                   NULL,                 /* copy ()      */ \
01282                   NULL, NULL,           /* map * 2 ()   */ \
01283                   NULL                  /* close ()     */ \
01284 }
01285 
01286 
01287 U_CDECL_END
01288 
01289 
01290 
01291 #endif /* U_HIDE_DRAFT_API */
01292 
01293 #endif

Generated on Tue Feb 28 01:37:40 2006 for ICU 3.4 by  doxygen 1.4.4