X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/common/unicode/utext.h diff --git a/icuSources/common/unicode/utext.h b/icuSources/common/unicode/utext.h index 866b8503..94d1275e 100644 --- a/icuSources/common/unicode/utext.h +++ b/icuSources/common/unicode/utext.h @@ -1,12 +1,14 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * -* Copyright (C) 2004-2008, International Business Machines +* Copyright (C) 2004-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: utext.h -* encoding: US-ASCII +* encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * @@ -136,7 +138,9 @@ #include "unicode/utypes.h" -#ifdef XP_CPLUSPLUS +#include "unicode/uchar.h" +#if U_SHOW_CPLUSPLUS_API +#include "unicode/localpointer.h" #include "unicode/rep.h" #include "unicode/unistr.h" #include "unicode/chariter.h" @@ -179,6 +183,24 @@ typedef struct UText UText; /**< C typedef for struct UText. @stable ICU 3.6 */ U_STABLE UText * U_EXPORT2 utext_close(UText *ut); +#if U_SHOW_CPLUSPLUS_API + +U_NAMESPACE_BEGIN + +/** + * \class LocalUTextPointer + * "Smart pointer" class, closes a UText via utext_close(). + * For most methods see the LocalPointerBase base class. + * + * @see LocalPointerBase + * @see LocalPointer + * @stable ICU 4.4 + */ +U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close); + +U_NAMESPACE_END + +#endif /** * Open a read-only UText implementation for UTF-8 strings. @@ -223,7 +245,7 @@ U_STABLE UText * U_EXPORT2 utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status); -#ifdef XP_CPLUSPLUS +#if U_SHOW_CPLUSPLUS_API /** * Open a writable UText for a non-const UnicodeString. * @@ -237,7 +259,7 @@ utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status); * @stable ICU 3.4 */ U_STABLE UText * U_EXPORT2 -utext_openUnicodeString(UText *ut, U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status); +utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status); /** @@ -253,7 +275,7 @@ utext_openUnicodeString(UText *ut, U_NAMESPACE_QUALIFIER UnicodeString *s, UErro * @stable ICU 3.4 */ U_STABLE UText * U_EXPORT2 -utext_openConstUnicodeString(UText *ut, const U_NAMESPACE_QUALIFIER UnicodeString *s, UErrorCode *status); +utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status); /** @@ -269,7 +291,7 @@ utext_openConstUnicodeString(UText *ut, const U_NAMESPACE_QUALIFIER UnicodeStrin * @stable ICU 3.4 */ U_STABLE UText * U_EXPORT2 -utext_openReplaceable(UText *ut, U_NAMESPACE_QUALIFIER Replaceable *rep, UErrorCode *status); +utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status); /** * Open a UText implementation over an ICU CharacterIterator. @@ -284,7 +306,7 @@ utext_openReplaceable(UText *ut, U_NAMESPACE_QUALIFIER Replaceable *rep, UErrorC * @stable ICU 3.4 */ U_STABLE UText * U_EXPORT2 -utext_openCharacterIterator(UText *ut, U_NAMESPACE_QUALIFIER CharacterIterator *ic, UErrorCode *status); +utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status); #endif @@ -367,7 +389,7 @@ utext_equals(const UText *a, const UText *b); /***************************************************************************** * - * Functions to work with the text represeted by a UText wrapper + * Functions to work with the text represented by a UText wrapper * *****************************************************************************/ @@ -411,7 +433,7 @@ utext_isLengthExpensive(const UText *ut); * * The iteration position will be set to the start of the returned code point. * - * This function is roughly equivalent to the the sequence + * This function is roughly equivalent to the sequence * utext_setNativeIndex(index); * utext_current32(); * (There is a subtle difference if the index is out of bounds by being less than zero - @@ -570,7 +592,7 @@ U_STABLE void U_EXPORT2 utext_setNativeIndex(UText *ut, int64_t nativeIndex); /** - * Move the iterator postion by delta code points. The number of code points + * Move the iterator position by delta code points. The number of code points * is a signed number; a negative delta will move the iterator backwards, * towards the start of the text. *

@@ -589,7 +611,7 @@ U_STABLE UBool U_EXPORT2 utext_moveIndex32(UText *ut, int32_t delta); /** - * Get the native index of the character preceeding the current position. + * Get the native index of the character preceding the current position. * If the iteration position is already at the start of the text, zero * is returned. * The value returned is the same as that obtained from the following sequence, @@ -606,7 +628,7 @@ utext_moveIndex32(UText *ut, int32_t delta); * native index of the character most recently returned from utext_next(). * * @param ut the text to be accessed - * @return the native index of the character preceeding the current index position, + * @return the native index of the character preceding the current index position, * or zero if the current position is at the start of the text. * @stable ICU 3.6 */ @@ -633,10 +655,10 @@ utext_getPreviousNativeIndex(UText *ut); * @param ut the UText from which to extract data. * @param nativeStart the native index of the first character to extract.\ * If the specified index is out of range, - * it will be pinned to to be within 0 <= index <= textLength + * it will be pinned to be within 0 <= index <= textLength * @param nativeLimit the native string index of the position following the last * character to extract. If the specified index is out of range, - * it will be pinned to to be within 0 <= index <= textLength. + * it will be pinned to be within 0 <= index <= textLength. * nativeLimit must be >= nativeStart. * @param dest the UChar (UTF-16) buffer into which the extracted text is placed * @param destCapacity The size, in UChars, of the destination buffer. May be zero @@ -655,6 +677,7 @@ utext_extract(UText *ut, UErrorCode *status); + /************************************************************************************ * * #define inline versions of selected performance-critical text access functions @@ -670,6 +693,21 @@ utext_extract(UText *ut, * ************************************************************************************/ +#ifndef U_HIDE_INTERNAL_API +/** + * inline version of utext_current32(), for performance-critical situations. + * + * Get the code point at the current iteration position of the UText. + * Returns U_SENTINEL (-1) if the position is at the end of the + * text. + * + * @internal ICU 4.4 technology preview + */ +#define UTEXT_CURRENT32(ut) \ + ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \ + ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut)) +#endif /* U_HIDE_INTERNAL_API */ + /** * inline version of utext_next32(), for performance-critical situations. * @@ -726,14 +764,30 @@ utext_extract(UText *ut, * If the index is out of range, it will be pinned to be within * the range of the input text. * - * @stable ICU 4.0 + * @stable ICU 3.8 */ -#define UTEXT_SETNATIVEINDEX(ut, ix) \ - { int64_t __offset = (ix) - (ut)->chunkNativeStart; \ - if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \ - (ut)->chunkOffset=(int32_t)__offset; \ - } else { \ - utext_setNativeIndex((ut), (ix)); } } +#if LOG_UTEXT_SETNATIVEINDEX +/* Add logging for */ +#define UTEXT_SETNATIVEINDEX(ut, ix) UPRV_BLOCK_MACRO_BEGIN { \ + int64_t __offset = (ix) - (ut)->chunkNativeStart; \ + if ((ut)->chunkContents!=0 && __offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \ + (ut)->chunkOffset=(int32_t)__offset; \ + } else if ((ut)->chunkContents==0 && __offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit) { \ + os_log(OS_LOG_DEFAULT, "# UTEXT_SETNATIVEINDEX (ut) %p, (ut)->chunkContents 0, __offset %lld", (ut), __offset); \ + } else { \ + utext_setNativeIndex((ut), (ix)); + } \ +} UPRV_BLOCK_MACRO_END +#else +#define UTEXT_SETNATIVEINDEX(ut, ix) UPRV_BLOCK_MACRO_BEGIN { \ + int64_t __offset = (ix) - (ut)->chunkNativeStart; \ + if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \ + (ut)->chunkOffset=(int32_t)__offset; \ + } else { \ + utext_setNativeIndex((ut), (ix)); \ + } \ +} UPRV_BLOCK_MACRO_END +#endif @@ -868,7 +922,7 @@ utext_copy(UText *ut, * Caution: freezing a UText will disable changes made via the specific * frozen UText wrapper only; it will not have any effect on the ability to * directly modify the text by bypassing the UText. Any such backdoor modifications - * are always an error while UText access is occuring because the underlying + * are always an error while UText access is occurring because the underlying * text can get out of sync with UText's buffering. *

* @@ -1016,7 +1070,7 @@ UTextAccess(UText *ut, int64_t nativeIndex, UBool forward); * be NUL-terminated if there is sufficient space in the destination buffer. * * @param ut the UText from which to extract data. - * @param nativeStart the native index of the first characer to extract. + * @param nativeStart the native index of the first character to extract. * @param nativeLimit the native string index of the position following the last * character to extract. * @param dest the UChar (UTF-16) buffer into which the extracted text is placed @@ -1173,7 +1227,7 @@ UTextClose(UText *ut); struct UTextFuncs { /** * (public) Function table size, sizeof(UTextFuncs) - * Intended for use should the table grow to accomodate added + * Intended for use should the table grow to accommodate added * functions in the future, to allow tests for older format * function tables that do not contain the extensions. * @@ -1272,8 +1326,8 @@ struct UTextFuncs { * (private) Spare function pointer * @internal */ - UTextClose *spare1; + /** * (private) Spare function pointer * @internal @@ -1307,7 +1361,7 @@ typedef struct UTextFuncs UTextFuncs; struct UText { /** * (private) Magic. Used to help detect when UText functions are handed - * invalid or unitialized UText structs. + * invalid or uninitialized UText structs. * utext_openXYZ() functions take an initialized, * but not necessarily open, UText struct as an * optional fill-in parameter. This magic field @@ -1329,7 +1383,7 @@ struct UText { /** - * Text provider properties. This set of flags is maintainted by the + * Text provider properties. This set of flags is maintained by the * text provider implementation. * @stable ICU 3.4 */ @@ -1414,7 +1468,7 @@ struct UText { void *pExtra; /** - * (protected) Pointer to string or text-containin object or similar. + * (protected) Pointer to string or text-containing object or similar. * This is the source of the text that this UText is wrapping, in a format * that is known to the text provider functions. * @stable ICU 3.4 @@ -1517,6 +1571,7 @@ struct UText { U_STABLE UText * U_EXPORT2 utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status); +// do not use #ifndef U_HIDE_INTERNAL_API around the following! /** * @internal * Value used to help identify correctly initialized UText structs.