00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00159
00160
00161
00162
00183 U_STABLE UText * U_EXPORT2
00184 utext_close(UText *ut);
00185
00186 #if U_SHOW_CPLUSPLUS_API
00187
00188 U_NAMESPACE_BEGIN
00189
00199 U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
00200
00201 U_NAMESPACE_END
00202
00203 #endif
00204
00226 U_STABLE UText * U_EXPORT2
00227 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
00228
00229
00244 U_STABLE UText * U_EXPORT2
00245 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status);
00246
00247
00248 #if U_SHOW_CPLUSPLUS_API
00249
00261 U_STABLE UText * U_EXPORT2
00262 utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status);
00263
00264
00277 U_STABLE UText * U_EXPORT2
00278 utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status);
00279
00280
00293 U_STABLE UText * U_EXPORT2
00294 utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status);
00295
00308 U_STABLE UText * U_EXPORT2
00309 utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status);
00310
00311 #endif
00312
00313
00371 U_STABLE UText * U_EXPORT2
00372 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
00373
00374
00386 U_STABLE UBool U_EXPORT2
00387 utext_equals(const UText *a, const UText *b);
00388
00389
00390
00391
00392
00393
00394
00395
00407 U_STABLE int64_t U_EXPORT2
00408 utext_nativeLength(UText *ut);
00409
00423 U_STABLE UBool U_EXPORT2
00424 utext_isLengthExpensive(const UText *ut);
00425
00451 U_STABLE UChar32 U_EXPORT2
00452 utext_char32At(UText *ut, int64_t nativeIndex);
00453
00454
00465 U_STABLE UChar32 U_EXPORT2
00466 utext_current32(UText *ut);
00467
00468
00487 U_STABLE UChar32 U_EXPORT2
00488 utext_next32(UText *ut);
00489
00490
00508 U_STABLE UChar32 U_EXPORT2
00509 utext_previous32(UText *ut);
00510
00511
00530 U_STABLE UChar32 U_EXPORT2
00531 utext_next32From(UText *ut, int64_t nativeIndex);
00532
00533
00534
00550 U_STABLE UChar32 U_EXPORT2
00551 utext_previous32From(UText *ut, int64_t nativeIndex);
00552
00565 U_STABLE int64_t U_EXPORT2
00566 utext_getNativeIndex(const UText *ut);
00567
00591 U_STABLE void U_EXPORT2
00592 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
00593
00610 U_STABLE UBool U_EXPORT2
00611 utext_moveIndex32(UText *ut, int32_t delta);
00612
00635 U_STABLE int64_t U_EXPORT2
00636 utext_getPreviousNativeIndex(UText *ut);
00637
00638
00673 U_STABLE int32_t U_EXPORT2
00674 utext_extract(UText *ut,
00675 int64_t nativeStart, int64_t nativeLimit,
00676 UChar *dest, int32_t destCapacity,
00677 UErrorCode *status);
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 #ifndef U_HIDE_INTERNAL_API
00697
00706 #define UTEXT_CURRENT32(ut) \
00707 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00708 ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
00709 #endif
00710
00722 #define UTEXT_NEXT32(ut) \
00723 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
00724 ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
00725
00736 #define UTEXT_PREVIOUS32(ut) \
00737 ((ut)->chunkOffset > 0 && \
00738 (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
00739 (ut)->chunkContents[--((ut)->chunkOffset)] : utext_previous32(ut))
00740
00753 #define UTEXT_GETNATIVEINDEX(ut) \
00754 ((ut)->chunkOffset <= (ut)->nativeIndexingLimit? \
00755 (ut)->chunkNativeStart+(ut)->chunkOffset : \
00756 (ut)->pFuncs->mapOffsetToNative(ut))
00757
00769 #define UTEXT_SETNATIVEINDEX(ut, ix) \
00770 { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
00771 if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \
00772 (ut)->chunkOffset=(int32_t)__offset; \
00773 } else { \
00774 utext_setNativeIndex((ut), (ix)); } }
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00805 U_STABLE UBool U_EXPORT2
00806 utext_isWritable(const UText *ut);
00807
00808
00817 U_STABLE UBool U_EXPORT2
00818 utext_hasMetaData(const UText *ut);
00819
00820
00848 U_STABLE int32_t U_EXPORT2
00849 utext_replace(UText *ut,
00850 int64_t nativeStart, int64_t nativeLimit,
00851 const UChar *replacementText, int32_t replacementLength,
00852 UErrorCode *status);
00853
00854
00855
00888 U_STABLE void U_EXPORT2
00889 utext_copy(UText *ut,
00890 int64_t nativeStart, int64_t nativeLimit,
00891 int64_t destIndex,
00892 UBool move,
00893 UErrorCode *status);
00894
00895
00917 U_STABLE void U_EXPORT2
00918 utext_freeze(UText *ut);
00919
00920
00927 enum {
00932 UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
00939 UTEXT_PROVIDER_STABLE_CHUNKS = 2,
00946 UTEXT_PROVIDER_WRITABLE = 3,
00952 UTEXT_PROVIDER_HAS_META_DATA = 4,
00960 UTEXT_PROVIDER_OWNS_TEXT = 5
00961 };
00962
01000 typedef UText * U_CALLCONV
01001 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
01002
01003
01012 typedef int64_t U_CALLCONV
01013 UTextNativeLength(UText *ut);
01014
01040 typedef UBool U_CALLCONV
01041 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
01042
01070 typedef int32_t U_CALLCONV
01071 UTextExtract(UText *ut,
01072 int64_t nativeStart, int64_t nativeLimit,
01073 UChar *dest, int32_t destCapacity,
01074 UErrorCode *status);
01075
01105 typedef int32_t U_CALLCONV
01106 UTextReplace(UText *ut,
01107 int64_t nativeStart, int64_t nativeLimit,
01108 const UChar *replacementText, int32_t replacmentLength,
01109 UErrorCode *status);
01110
01139 typedef void U_CALLCONV
01140 UTextCopy(UText *ut,
01141 int64_t nativeStart, int64_t nativeLimit,
01142 int64_t nativeDest,
01143 UBool move,
01144 UErrorCode *status);
01145
01159 typedef int64_t U_CALLCONV
01160 UTextMapOffsetToNative(const UText *ut);
01161
01177 typedef int32_t U_CALLCONV
01178 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
01179
01180
01198 typedef void U_CALLCONV
01199 UTextClose(UText *ut);
01200
01201
01211 struct UTextFuncs {
01226 int32_t tableSize;
01227
01233 int32_t reserved1, reserved2, reserved3;
01234
01235
01242 UTextClone *clone;
01243
01251 UTextNativeLength *nativeLength;
01252
01259 UTextAccess *access;
01260
01267 UTextExtract *extract;
01268
01275 UTextReplace *replace;
01276
01283 UTextCopy *copy;
01284
01291 UTextMapOffsetToNative *mapOffsetToNative;
01292
01299 UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
01300
01307 UTextClose *close;
01308
01313 UTextClose *spare1;
01314
01319 UTextClose *spare2;
01320
01325 UTextClose *spare3;
01326
01327 };
01332 typedef struct UTextFuncs UTextFuncs;
01333
01345 struct UText {
01358 uint32_t magic;
01359
01360
01366 int32_t flags;
01367
01368
01374 int32_t providerProperties;
01375
01382 int32_t sizeOfStruct;
01383
01384
01385
01386
01392 int64_t chunkNativeLimit;
01393
01398 int32_t extraSize;
01399
01407 int32_t nativeIndexingLimit;
01408
01409
01410
01415 int64_t chunkNativeStart;
01416
01422 int32_t chunkOffset;
01423
01428 int32_t chunkLength;
01429
01430
01431
01432
01439 const UChar *chunkContents;
01440
01445 const UTextFuncs *pFuncs;
01446
01452 void *pExtra;
01453
01460 const void *context;
01461
01462
01463
01469 const void *p;
01475 const void *q;
01481 const void *r;
01482
01488 void *privP;
01489
01490
01491
01492
01493
01499 int64_t a;
01500
01506 int32_t b;
01507
01513 int32_t c;
01514
01515
01516
01517
01523 int64_t privA;
01529 int32_t privB;
01535 int32_t privC;
01536 };
01537
01538
01555 U_STABLE UText * U_EXPORT2
01556 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
01557
01558
01564 enum {
01565 UTEXT_MAGIC = 0x345ad82c
01566 };
01567
01575 #define UTEXT_INITIALIZER { \
01576 UTEXT_MAGIC, \
01577 0, \
01578 0, \
01579 sizeof(UText), \
01580 0, \
01581 0, \
01582 0, \
01583 0, \
01584 0, \
01585 0, \
01586 NULL, \
01587 NULL, \
01588 NULL, \
01589 NULL, \
01590 NULL, NULL, NULL, \
01591 NULL, \
01592 0, 0, 0, \
01593 0, 0, 0 \
01594 }
01595
01596
01597 U_CDECL_END
01598
01599
01600
01601 #endif