ICU 54.1 54.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utext.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 2004-2012, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: utext.h
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2004oct06
14 * created by: Markus W. Scherer
15 */
16
17 #ifndef __UTEXT_H__
18 #define __UTEXT_H__
19
138 #include "unicode/utypes.h"
139 #include "unicode/uchar.h"
140 #if U_SHOW_CPLUSPLUS_API
141 #include "unicode/localpointer.h"
142 #include "unicode/rep.h"
143 #include "unicode/unistr.h"
144 #include "unicode/chariter.h"
145 #endif
146
147
148 U_CDECL_BEGIN
149
150 struct UText;
151 typedef struct UText UText;
154 /***************************************************************************************
155 *
156 * C Functions for creating UText wrappers around various kinds of text strings.
157 *
158 ****************************************************************************************/
159
160
181 U_STABLE UText * U_EXPORT2
182 utext_close(UText *ut);
183
184 #if U_SHOW_CPLUSPLUS_API
185
186 U_NAMESPACE_BEGIN
187
197 U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
198
199 U_NAMESPACE_END
200
201 #endif
202
224 U_STABLE UText * U_EXPORT2
225 utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status);
226
227
242 U_STABLE UText * U_EXPORT2
243 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status);
244
245
246 #if U_SHOW_CPLUSPLUS_API
247
259 U_STABLE UText * U_EXPORT2
260 utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status);
261
262
275 U_STABLE UText * U_EXPORT2
276 utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status);
277
278
291 U_STABLE UText * U_EXPORT2
292 utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status);
293
306 U_STABLE UText * U_EXPORT2
307 utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status);
308
309 #endif
310
311
369 U_STABLE UText * U_EXPORT2
370 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status);
371
372
384 U_STABLE UBool U_EXPORT2
385 utext_equals(const UText *a, const UText *b);
386
387
388 /*****************************************************************************
389 *
390 * Functions to work with the text represeted by a UText wrapper
391 *
392 *****************************************************************************/
393
405 U_STABLE int64_t U_EXPORT2
406 utext_nativeLength(UText *ut);
407
421 U_STABLE UBool U_EXPORT2
422 utext_isLengthExpensive(const UText *ut);
423
449 U_STABLE UChar32 U_EXPORT2
450 utext_char32At(UText *ut, int64_t nativeIndex);
451
452
463 U_STABLE UChar32 U_EXPORT2
464 utext_current32(UText *ut);
465
466
485 U_STABLE UChar32 U_EXPORT2
486 utext_next32(UText *ut);
487
488
506 U_STABLE UChar32 U_EXPORT2
507 utext_previous32(UText *ut);
508
509
528 U_STABLE UChar32 U_EXPORT2
529 utext_next32From(UText *ut, int64_t nativeIndex);
530
531
532
548 U_STABLE UChar32 U_EXPORT2
549 utext_previous32From(UText *ut, int64_t nativeIndex);
550
563 U_STABLE int64_t U_EXPORT2
564 utext_getNativeIndex(const UText *ut);
565
589 U_STABLE void U_EXPORT2
590 utext_setNativeIndex(UText *ut, int64_t nativeIndex);
591
608 U_STABLE UBool U_EXPORT2
609 utext_moveIndex32(UText *ut, int32_t delta);
610
633 U_STABLE int64_t U_EXPORT2
634 utext_getPreviousNativeIndex(UText *ut);
635
636
671 U_STABLE int32_t U_EXPORT2
672 utext_extract(UText *ut,
673 int64_t nativeStart, int64_t nativeLimit,
674 UChar *dest, int32_t destCapacity,
675 UErrorCode *status);
676
677
678
679 /************************************************************************************
680 *
681 * #define inline versions of selected performance-critical text access functions
682 * Caution: do not use auto increment++ or decrement-- expressions
683 * as parameters to these macros.
684 *
685 * For most use, where there is no extreme performance constraint, the
686 * normal, non-inline functions are a better choice. The resulting code
687 * will be smaller, and, if the need ever arises, easier to debug.
688 *
689 * These are implemented as #defines rather than real functions
690 * because there is no fully portable way to do inline functions in plain C.
691 *
692 ************************************************************************************/
693
694 #ifndef U_HIDE_INTERNAL_API
695
704 #define UTEXT_CURRENT32(ut) \
705 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
706 ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
707 #endif /* U_HIDE_INTERNAL_API */
708
720 #define UTEXT_NEXT32(ut) \
721 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
722 ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
723
734 #define UTEXT_PREVIOUS32(ut) \
735 ((ut)->chunkOffset > 0 && \
736 (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
737 (ut)->chunkContents[--((ut)->chunkOffset)] : utext_previous32(ut))
738
751 #define UTEXT_GETNATIVEINDEX(ut) \
752 ((ut)->chunkOffset <= (ut)->nativeIndexingLimit? \
753 (ut)->chunkNativeStart+(ut)->chunkOffset : \
754 (ut)->pFuncs->mapOffsetToNative(ut))
755
767 #define UTEXT_SETNATIVEINDEX(ut, ix) \
768 { int64_t __offset = (ix) - (ut)->chunkNativeStart; \
769 if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \
770 (ut)->chunkOffset=(int32_t)__offset; \
771 } else { \
772 utext_setNativeIndex((ut), (ix)); } }
773
774
775
776 /************************************************************************************
777 *
778 * Functions related to writing or modifying the text.
779 * These will work only with modifiable UTexts. Attempting to
780 * modify a read-only UText will return an error status.
781 *
782 ************************************************************************************/
783
784
803 U_STABLE UBool U_EXPORT2
804 utext_isWritable(const UText *ut);
805
806
815 U_STABLE UBool U_EXPORT2
816 utext_hasMetaData(const UText *ut);
817
818
846 U_STABLE int32_t U_EXPORT2
847 utext_replace(UText *ut,
848 int64_t nativeStart, int64_t nativeLimit,
849 const UChar *replacementText, int32_t replacementLength,
850 UErrorCode *status);
851
852
853
886 U_STABLE void U_EXPORT2
887 utext_copy(UText *ut,
888 int64_t nativeStart, int64_t nativeLimit,
889 int64_t destIndex,
890 UBool move,
891 UErrorCode *status);
892
893
915 U_STABLE void U_EXPORT2
916 utext_freeze(UText *ut);
917
918
925 enum {
930 UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1,
937 UTEXT_PROVIDER_STABLE_CHUNKS = 2,
944 UTEXT_PROVIDER_WRITABLE = 3,
950 UTEXT_PROVIDER_HAS_META_DATA = 4,
958 UTEXT_PROVIDER_OWNS_TEXT = 5
959 };
960
998 typedef UText * U_CALLCONV
999 UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
1000
1001
1010 typedef int64_t U_CALLCONV
1011 UTextNativeLength(UText *ut);
1012
1038 typedef UBool U_CALLCONV
1039 UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
1040
1068 typedef int32_t U_CALLCONV
1069 UTextExtract(UText *ut,
1070 int64_t nativeStart, int64_t nativeLimit,
1071 UChar *dest, int32_t destCapacity,
1072 UErrorCode *status);
1073
1103 typedef int32_t U_CALLCONV
1104 UTextReplace(UText *ut,
1105 int64_t nativeStart, int64_t nativeLimit,
1106 const UChar *replacementText, int32_t replacmentLength,
1107 UErrorCode *status);
1108
1137 typedef void U_CALLCONV
1138 UTextCopy(UText *ut,
1139 int64_t nativeStart, int64_t nativeLimit,
1140 int64_t nativeDest,
1141 UBool move,
1142 UErrorCode *status);
1143
1157 typedef int64_t U_CALLCONV
1158 UTextMapOffsetToNative(const UText *ut);
1159
1175 typedef int32_t U_CALLCONV
1176 UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
1177
1178
1196 typedef void U_CALLCONV
1197 UTextClose(UText *ut);
1198
1199
1209 struct UTextFuncs {
1224 int32_t tableSize;
1225
1231 int32_t reserved1, reserved2, reserved3;
1232
1233
1240 UTextClone *clone;
1241
1249 UTextNativeLength *nativeLength;
1250
1257 UTextAccess *access;
1258
1265 UTextExtract *extract;
1266
1273 UTextReplace *replace;
1274
1281 UTextCopy *copy;
1282
1289 UTextMapOffsetToNative *mapOffsetToNative;
1290
1297 UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16;
1298
1305 UTextClose *close;
1306
1311 UTextClose *spare1;
1312
1317 UTextClose *spare2;
1318
1323 UTextClose *spare3;
1324
1325 };
1330 typedef struct UTextFuncs UTextFuncs;
1331
1343 struct UText {
1356 uint32_t magic;
1357
1358
1364 int32_t flags;
1365
1366
1372 int32_t providerProperties;
1373
1380 int32_t sizeOfStruct;
1381
1382 /* ------ 16 byte alignment boundary ----------- */
1383
1384
1390 int64_t chunkNativeLimit;
1391
1396 int32_t extraSize;
1397
1405 int32_t nativeIndexingLimit;
1406
1407 /* ---- 16 byte alignment boundary------ */
1408
1413 int64_t chunkNativeStart;
1414
1420 int32_t chunkOffset;
1421
1426 int32_t chunkLength;
1427
1428 /* ---- 16 byte alignment boundary-- */
1429
1430
1437 const UChar *chunkContents;
1438
1443 const UTextFuncs *pFuncs;
1444
1450 void *pExtra;
1451
1458 const void *context;
1459
1460 /* --- 16 byte alignment boundary--- */
1461
1467 const void *p;
1473 const void *q;
1479 const void *r;
1480
1486 void *privP;
1487
1488
1489 /* --- 16 byte alignment boundary--- */
1490
1491
1497 int64_t a;
1498
1504 int32_t b;
1505
1511 int32_t c;
1512
1513 /* ---- 16 byte alignment boundary---- */
1514
1515
1521 int64_t privA;
1527 int32_t privB;
1533 int32_t privC;
1534 };
1535
1536
1553 U_STABLE UText * U_EXPORT2
1554 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status);
1555
1556 #ifndef U_HIDE_INTERNAL_API
1557
1562 enum {
1563 UTEXT_MAGIC = 0x345ad82c
1564 };
1565 #endif /* U_HIDE_INTERNAL_API */
1566
1574 #define UTEXT_INITIALIZER { \
1575 UTEXT_MAGIC, /* magic */ \
1576 0, /* flags */ \
1577 0, /* providerProps */ \
1578 sizeof(UText), /* sizeOfStruct */ \
1579 0, /* chunkNativeLimit */ \
1580 0, /* extraSize */ \
1581 0, /* nativeIndexingLimit */ \
1582 0, /* chunkNativeStart */ \
1583 0, /* chunkOffset */ \
1584 0, /* chunkLength */ \
1585 NULL, /* chunkContents */ \
1586 NULL, /* pFuncs */ \
1587 NULL, /* pExtra */ \
1588 NULL, /* context */ \
1589 NULL, NULL, NULL, /* p, q, r */ \
1590 NULL, /* privP */ \
1591 0, 0, 0, /* a, b, c */ \
1592 0, 0, 0 /* privA,B,C, */ \
1593 }
1594
1595
1596 U_CDECL_END
1597
1598
1599
1600 #endif