ICU4C 79
Loading...
Searching...
No Matches
utext.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5*
6* Copyright (C) 2004-2012, International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9*******************************************************************************
10* file name: utext.h
11* encoding: UTF-8
12* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2004oct06
16* created by: Markus W. Scherer
17*/
18
19#ifndef __UTEXT_H__
20#define __UTEXT_H__
21
137
138
139
140#include "unicode/utypes.h"
141#include "unicode/uchar.h"
142#if U_SHOW_CPLUSPLUS_API
143#include "unicode/localpointer.h"
144#include "unicode/rep.h"
145#include "unicode/unistr.h"
146#include "unicode/chariter.h"
147#endif
148
149
151
152struct UText;
153typedef struct UText UText;
154
155
156/***************************************************************************************
157 *
158 * C Functions for creating UText wrappers around various kinds of text strings.
159 *
160 ****************************************************************************************/
161
162
183U_CAPI UText* U_EXPORT2
184utext_close(UText* ut U_LIFETIME_BOUND);
185
207U_CAPI UText* U_EXPORT2
208utext_openUTF8(UText* ut U_LIFETIME_BOUND,
209 const char* s U_LIFETIME_BOUND,
210 int64_t length,
211 UErrorCode* status);
212
227U_CAPI UText* U_EXPORT2
228utext_openUChars(UText* ut U_LIFETIME_BOUND,
229 const UChar* s U_LIFETIME_BOUND,
230 int64_t length,
231 UErrorCode* status);
232
233#if U_SHOW_CPLUSPLUS_API
246U_CAPI UText* U_EXPORT2
247utext_openUnicodeString(UText* ut U_LIFETIME_BOUND,
248 icu::UnicodeString* s U_LIFETIME_BOUND,
249 UErrorCode* status);
250
263U_CAPI UText* U_EXPORT2
265 const icu::UnicodeString* s U_LIFETIME_BOUND,
266 UErrorCode* status);
267
268
281U_CAPI UText* U_EXPORT2
282utext_openReplaceable(UText* ut U_LIFETIME_BOUND,
283 icu::Replaceable* rep U_LIFETIME_BOUND,
284 UErrorCode* status);
285
298U_CAPI UText* U_EXPORT2
300 icu::CharacterIterator* ci U_LIFETIME_BOUND,
301 UErrorCode* status);
302
303#endif
304
305
363U_CAPI UText* U_EXPORT2
364utext_clone(UText* dest U_LIFETIME_BOUND,
365 const UText* src,
366 UBool deep,
367 UBool readOnly,
368 UErrorCode* status);
369
381U_CAPI UBool U_EXPORT2
382utext_equals(const UText *a, const UText *b);
383
384
385/*****************************************************************************
386 *
387 * Functions to work with the text represented by a UText wrapper
388 *
389 *****************************************************************************/
390
402U_CAPI int64_t U_EXPORT2
404
418U_CAPI UBool U_EXPORT2
420
446U_CAPI UChar32 U_EXPORT2
447utext_char32At(UText *ut, int64_t nativeIndex);
448
449
460U_CAPI UChar32 U_EXPORT2
462
463
482U_CAPI UChar32 U_EXPORT2
484
485
503U_CAPI UChar32 U_EXPORT2
505
506
525U_CAPI UChar32 U_EXPORT2
526utext_next32From(UText *ut, int64_t nativeIndex);
527
528
529
545U_CAPI UChar32 U_EXPORT2
546utext_previous32From(UText *ut, int64_t nativeIndex);
547
560U_CAPI int64_t U_EXPORT2
562
586U_CAPI void U_EXPORT2
587utext_setNativeIndex(UText *ut, int64_t nativeIndex);
588
605U_CAPI UBool U_EXPORT2
606utext_moveIndex32(UText *ut, int32_t delta);
607
630U_CAPI int64_t U_EXPORT2
632
633
668U_CAPI int32_t U_EXPORT2
670 int64_t nativeStart, int64_t nativeLimit,
671 UChar *dest, int32_t destCapacity,
672 UErrorCode *status);
673
674
675
676/************************************************************************************
677 *
678 * #define inline versions of selected performance-critical text access functions
679 * Caution: do not use auto increment++ or decrement-- expressions
680 * as parameters to these macros.
681 *
682 * For most use, where there is no extreme performance constraint, the
683 * normal, non-inline functions are a better choice. The resulting code
684 * will be smaller, and, if the need ever arises, easier to debug.
685 *
686 * These are implemented as #defines rather than real functions
687 * because there is no fully portable way to do inline functions in plain C.
688 *
689 ************************************************************************************/
690
691#ifndef U_HIDE_INTERNAL_API
701#define UTEXT_CURRENT32(ut) \
702 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
703 ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut))
704#endif /* U_HIDE_INTERNAL_API */
705
717#define UTEXT_NEXT32(ut) \
718 ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \
719 ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut))
720
731#define UTEXT_PREVIOUS32(ut) \
732 ((ut)->chunkOffset > 0 && \
733 (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \
734 (ut)->chunkContents[--((ut)->chunkOffset)] : utext_previous32(ut))
735
748#define UTEXT_GETNATIVEINDEX(ut) \
749 ((ut)->chunkOffset <= (ut)->nativeIndexingLimit? \
750 (ut)->chunkNativeStart+(ut)->chunkOffset : \
751 (ut)->pFuncs->mapOffsetToNative(ut))
752
764#define UTEXT_SETNATIVEINDEX(ut, ix) UPRV_BLOCK_MACRO_BEGIN { \
765 int64_t __offset = (ix) - (ut)->chunkNativeStart; \
766 if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \
767 (ut)->chunkOffset=(int32_t)__offset; \
768 } else { \
769 utext_setNativeIndex((ut), (ix)); \
770 } \
771} UPRV_BLOCK_MACRO_END
772
773
774
775/************************************************************************************
776 *
777 * Functions related to writing or modifying the text.
778 * These will work only with modifiable UTexts. Attempting to
779 * modify a read-only UText will return an error status.
780 *
781 ************************************************************************************/
782
783
802U_CAPI UBool U_EXPORT2
804
805
814U_CAPI UBool U_EXPORT2
816
817
845U_CAPI int32_t U_EXPORT2
847 int64_t nativeStart, int64_t nativeLimit,
848 const UChar *replacementText, int32_t replacementLength,
849 UErrorCode *status);
850
851
852
885U_CAPI void U_EXPORT2
887 int64_t nativeStart, int64_t nativeLimit,
888 int64_t destIndex,
889 UBool move,
890 UErrorCode *status);
891
892
914U_CAPI void U_EXPORT2
916
917
924enum {
958};
959
997typedef UText * U_CALLCONV
998UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status);
999
1000
1009typedef int64_t U_CALLCONV
1011
1037typedef UBool U_CALLCONV
1038UTextAccess(UText *ut, int64_t nativeIndex, UBool forward);
1039
1067typedef int32_t U_CALLCONV
1069 int64_t nativeStart, int64_t nativeLimit,
1070 UChar *dest, int32_t destCapacity,
1071 UErrorCode *status);
1072
1102typedef int32_t U_CALLCONV
1104 int64_t nativeStart, int64_t nativeLimit,
1105 const UChar *replacementText, int32_t replacmentLength,
1106 UErrorCode *status);
1107
1136typedef void U_CALLCONV
1138 int64_t nativeStart, int64_t nativeLimit,
1139 int64_t nativeDest,
1140 UBool move,
1141 UErrorCode *status);
1142
1156typedef int64_t U_CALLCONV
1158
1174typedef int32_t U_CALLCONV
1175UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex);
1176
1177
1195typedef void U_CALLCONV
1197
1198
1325
1329typedef struct UTextFuncs UTextFuncs;
1330
1342struct UText {
1355 uint32_t magic;
1356
1357
1363 int32_t flags;
1364
1365
1372
1380
1381 /* ------ 16 byte alignment boundary ----------- */
1382
1383
1390
1395 int32_t extraSize;
1396
1405
1406 /* ---- 16 byte alignment boundary------ */
1407
1413
1420
1426
1427 /* ---- 16 byte alignment boundary-- */
1428
1429
1437
1443
1449 void *pExtra;
1450
1457 const void *context;
1458
1459 /* --- 16 byte alignment boundary--- */
1460
1466 const void *p;
1472 const void *q;
1478 const void *r;
1479
1485 void *privP;
1486
1487
1488 /* --- 16 byte alignment boundary--- */
1489
1490
1496 int64_t a;
1497
1503 int32_t b;
1504
1510 int32_t c;
1511
1512 /* ---- 16 byte alignment boundary---- */
1513
1514
1520 int64_t privA;
1526 int32_t privB;
1532 int32_t privC;
1533};
1534
1535
1552U_CAPI UText* U_EXPORT2
1553utext_setup(UText* ut U_LIFETIME_BOUND, int32_t extraSpace, UErrorCode* status);
1554
1555// do not use #ifndef U_HIDE_INTERNAL_API around the following!
1561enum {
1562 UTEXT_MAGIC = 0x345ad82c
1563};
1564
1572#define UTEXT_INITIALIZER { \
1573 UTEXT_MAGIC, /* magic */ \
1574 0, /* flags */ \
1575 0, /* providerProps */ \
1576 sizeof(UText), /* sizeOfStruct */ \
1577 0, /* chunkNativeLimit */ \
1578 0, /* extraSize */ \
1579 0, /* nativeIndexingLimit */ \
1580 0, /* chunkNativeStart */ \
1581 0, /* chunkOffset */ \
1582 0, /* chunkLength */ \
1583 NULL, /* chunkContents */ \
1584 NULL, /* pFuncs */ \
1585 NULL, /* pExtra */ \
1586 NULL, /* context */ \
1587 NULL, NULL, NULL, /* p, q, r */ \
1588 NULL, /* privP */ \
1589 0, 0, 0, /* a, b, c */ \
1590 0, 0, 0 /* privA,B,C, */ \
1591 }
1592
1593
1595
1596
1597#if U_SHOW_CPLUSPLUS_API
1598
1599U_NAMESPACE_BEGIN
1600
1611
1612U_NAMESPACE_END
1613
1614#endif
1615
1616
1617#endif
C++ API: Character Iterator.
"Smart pointer" class, closes a UText via utext_close().
Abstract class that defines an API for iteration on text objects.
Definition chariter.h:363
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition rep.h:77
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:303
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:880
C++ API: Replaceable String.
(public) Function dispatch table for UText.
Definition utext.h:1208
int32_t reserved1
(private) Alignment padding.
Definition utext.h:1230
int32_t reserved2
Definition utext.h:1230
UTextMapOffsetToNative * mapOffsetToNative
(public) Function pointer for UTextMapOffsetToNative.
Definition utext.h:1288
UTextAccess * access
(public) Function pointer for UTextAccess.
Definition utext.h:1256
UTextExtract * extract
(public) Function pointer for UTextExtract.
Definition utext.h:1264
int32_t reserved3
Definition utext.h:1230
UTextClose * spare3
(private) Spare function pointer
Definition utext.h:1322
int32_t tableSize
(public) Function table size, sizeof(UTextFuncs) Intended for use should the table grow to accommodat...
Definition utext.h:1223
UTextNativeLength * nativeLength
(public) function pointer for UTextLength May be expensive to compute!
Definition utext.h:1248
UTextReplace * replace
(public) Function pointer for UTextReplace.
Definition utext.h:1272
UTextClose * spare2
(private) Spare function pointer
Definition utext.h:1316
UTextClose * spare1
(private) Spare function pointer
Definition utext.h:1310
UTextCopy * copy
(public) Function pointer for UTextCopy.
Definition utext.h:1280
UTextMapNativeIndexToUTF16 * mapNativeIndexToUTF16
(public) Function pointer for UTextMapNativeIndexToUTF16.
Definition utext.h:1296
UTextClose * close
(public) Function pointer for UTextClose.
Definition utext.h:1304
UTextClone * clone
(public) Function pointer for UTextClone
Definition utext.h:1239
UText struct.
Definition utext.h:1342
int32_t b
(protected) Integer field reserved for use by the text provider.
Definition utext.h:1503
int32_t chunkOffset
(protected) Current iteration position within the text chunk (UTF-16 buffer).
Definition utext.h:1419
const void * p
(protected) Pointer fields available for use by the text provider.
Definition utext.h:1466
int32_t extraSize
(protected) Size in bytes of the extra space (pExtra).
Definition utext.h:1395
int64_t privA
Private field reserved for future use by the UText framework itself.
Definition utext.h:1520
int32_t nativeIndexingLimit
(protected) The highest chunk offset where native indexing and chunk (UTF-16) indexing correspond.
Definition utext.h:1404
int32_t flags
(private) Flags for managing the allocation and freeing of memory associated with this UText.
Definition utext.h:1363
int32_t sizeOfStruct
(public) sizeOfStruct=sizeof(UText) Allows possible backward compatible extension.
Definition utext.h:1379
void * pExtra
(protected) Pointer to additional space requested by the text provider during the utext_open operatio...
Definition utext.h:1449
int64_t chunkNativeLimit
(protected) Native index of the first character position following the current chunk.
Definition utext.h:1389
const void * r
(protected) Pointer fields available for use by the text provider.
Definition utext.h:1478
int32_t privB
Private field reserved for future use by the UText framework itself.
Definition utext.h:1526
uint32_t magic
(private) Magic.
Definition utext.h:1355
const UTextFuncs * pFuncs
(public) Pointer to Dispatch table for accessing functions for this UText.
Definition utext.h:1442
int32_t chunkLength
(protected) Length the text chunk (UTF-16 buffer), in UChars.
Definition utext.h:1425
int32_t providerProperties
Text provider properties.
Definition utext.h:1371
const UChar * chunkContents
(protected) pointer to a chunk of text in UTF-16 format.
Definition utext.h:1436
int32_t privC
Private field reserved for future use by the UText framework itself.
Definition utext.h:1532
const void * q
(protected) Pointer fields available for use by the text provider.
Definition utext.h:1472
void * privP
Private field reserved for future use by the UText framework itself.
Definition utext.h:1485
int64_t chunkNativeStart
(protected) Native index of the first character in the text chunk.
Definition utext.h:1412
const void * context
(protected) Pointer to string or text-containing object or similar.
Definition utext.h:1457
int32_t c
(protected) Integer field reserved for use by the text provider.
Definition utext.h:1510
int64_t a
(protected) Integer field reserved for use by the text provider.
Definition utext.h:1496
C API: Unicode Properties.
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition umachine.h:400
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:449
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:86
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:269
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition umachine.h:110
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:85
C++ API: Unicode String.
int32_t UTextReplace(UText *ut, int64_t nativeStart, int64_t nativeLimit, const UChar *replacementText, int32_t replacmentLength, UErrorCode *status)
Function type declaration for UText.replace().
Definition utext.h:1103
U_CAPI UChar32 utext_previous32From(UText *ut, int64_t nativeIndex)
Set the iteration index, and return the code point preceding the one specified by the initial index.
U_CAPI UText * utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status)
Open a read-only UText implementation for UTF-8 strings.
U_CAPI UText * utext_close(UText *ut)
Close function for UText instances.
U_CAPI UChar32 utext_previous32(UText *ut)
Move the iterator position to the character (code point) whose index precedes the current position,...
UText * UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status)
Function type declaration for UText.clone().
Definition utext.h:998
U_CAPI UBool utext_moveIndex32(UText *ut, int32_t delta)
Move the iterator position by delta code points.
U_CAPI UText * utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status)
Open a UText for a const UnicodeString.
int64_t UTextNativeLength(UText *ut)
Function type declaration for UText.nativeLength().
Definition utext.h:1010
U_CAPI UBool utext_hasMetaData(const UText *ut)
Test whether there is meta data associated with the text.
int32_t UTextExtract(UText *ut, int64_t nativeStart, int64_t nativeLimit, UChar *dest, int32_t destCapacity, UErrorCode *status)
Function type declaration for UText.extract().
Definition utext.h:1068
void UTextClose(UText *ut)
Function type declaration for UText.utextClose().
Definition utext.h:1196
U_CAPI int32_t utext_extract(UText *ut, int64_t nativeStart, int64_t nativeLimit, UChar *dest, int32_t destCapacity, UErrorCode *status)
Extract text from a UText into a UChar buffer.
@ UTEXT_PROVIDER_HAS_META_DATA
There is meta data associated with the text.
Definition utext.h:949
@ UTEXT_PROVIDER_STABLE_CHUNKS
Text chunks remain valid and usable until the text object is modified or deleted, not just until the ...
Definition utext.h:936
@ UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE
It is potentially time consuming for the provider to determine the length of the text.
Definition utext.h:929
@ UTEXT_PROVIDER_OWNS_TEXT
Text provider owns the text storage.
Definition utext.h:957
@ UTEXT_PROVIDER_WRITABLE
The provider supports modifying the text via the replace() and copy() functions.
Definition utext.h:943
U_CAPI UText * utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status)
Common function for use by Text Provider implementations to allocate and/or initialize a new UText st...
UBool UTextAccess(UText *ut, int64_t nativeIndex, UBool forward)
Function type declaration for UText.access().
Definition utext.h:1038
U_CAPI UText * utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status)
Open a UText implementation over an ICU CharacterIterator.
U_CAPI UText * utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status)
Open a read-only UText for UChar * string.
int64_t UTextMapOffsetToNative(const UText *ut)
Function type declaration for UText.mapOffsetToNative().
Definition utext.h:1157
U_CAPI void utext_copy(UText *ut, int64_t nativeStart, int64_t nativeLimit, int64_t destIndex, UBool move, UErrorCode *status)
Copy or move a substring from one position to another within the text, while retaining any metadata a...
int32_t UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex)
Function type declaration for UText.mapIndexToUTF16().
Definition utext.h:1175
U_CAPI UText * utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status)
Open a writable UText implementation for an ICU Replaceable object.
U_CAPI UChar32 utext_char32At(UText *ut, int64_t nativeIndex)
Returns the code point at the requested index, or U_SENTINEL (-1) if it is out of bounds.
U_CAPI UBool utext_equals(const UText *a, const UText *b)
Compare two UText objects for equality.
U_CAPI int64_t utext_nativeLength(UText *ut)
Get the length of the text.
U_CAPI UBool utext_isLengthExpensive(const UText *ut)
Return true if calculating the length of the text could be expensive.
void UTextCopy(UText *ut, int64_t nativeStart, int64_t nativeLimit, int64_t nativeDest, UBool move, UErrorCode *status)
Function type declaration for UText.copy().
Definition utext.h:1137
U_CAPI void utext_freeze(UText *ut)
U_CAPI int64_t utext_getPreviousNativeIndex(UText *ut)
Get the native index of the character preceding the current position.
U_CAPI UBool utext_isWritable(const UText *ut)
Return true if the text can be written (modified) with utext_replace() or utext_copy().
U_CAPI int32_t utext_replace(UText *ut, int64_t nativeStart, int64_t nativeLimit, const UChar *replacementText, int32_t replacementLength, UErrorCode *status)
Replace a range of the original text with a replacement text.
U_CAPI void utext_setNativeIndex(UText *ut, int64_t nativeIndex)
Set the current iteration position to the nearest code point boundary at or preceding the specified i...
U_CAPI UChar32 utext_next32From(UText *ut, int64_t nativeIndex)
Set the iteration index and return the code point at that index.
U_CAPI int64_t utext_getNativeIndex(const UText *ut)
Get the current iterator position, which can range from 0 to the length of the text.
U_CAPI UText * utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status)
Clone a UText.
U_CAPI UChar32 utext_next32(UText *ut)
Get the code point at the current iteration position of the UText, and advance the position to the fi...
U_CAPI UChar32 utext_current32(UText *ut)
Get the code point at the current iteration position, or U_SENTINEL (-1) if the iteration has reached...
U_CAPI UText * utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status)
Open a writable UText for a non-const UnicodeString.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:509