1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 1997-2010, International Business Machines 6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 8*0e209d39SAndroid Build Coastguard Worker * Date Name Description 9*0e209d39SAndroid Build Coastguard Worker * 06/23/00 aliu Creation. 10*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 11*0e209d39SAndroid Build Coastguard Worker */ 12*0e209d39SAndroid Build Coastguard Worker 13*0e209d39SAndroid Build Coastguard Worker #ifndef __UREP_H 14*0e209d39SAndroid Build Coastguard Worker #define __UREP_H 15*0e209d39SAndroid Build Coastguard Worker 16*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 17*0e209d39SAndroid Build Coastguard Worker 18*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN 19*0e209d39SAndroid Build Coastguard Worker 20*0e209d39SAndroid Build Coastguard Worker /******************************************************************** 21*0e209d39SAndroid Build Coastguard Worker * General Notes 22*0e209d39SAndroid Build Coastguard Worker ******************************************************************** 23*0e209d39SAndroid Build Coastguard Worker * TODO 24*0e209d39SAndroid Build Coastguard Worker * Add usage scenario 25*0e209d39SAndroid Build Coastguard Worker * Add test code 26*0e209d39SAndroid Build Coastguard Worker * Talk about pinning 27*0e209d39SAndroid Build Coastguard Worker * Talk about "can truncate result if out of memory" 28*0e209d39SAndroid Build Coastguard Worker */ 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker /******************************************************************** 31*0e209d39SAndroid Build Coastguard Worker * Data Structures 32*0e209d39SAndroid Build Coastguard Worker ********************************************************************/ 33*0e209d39SAndroid Build Coastguard Worker /** 34*0e209d39SAndroid Build Coastguard Worker * \file 35*0e209d39SAndroid Build Coastguard Worker * \brief C API: Callbacks for UReplaceable 36*0e209d39SAndroid Build Coastguard Worker */ 37*0e209d39SAndroid Build Coastguard Worker /** 38*0e209d39SAndroid Build Coastguard Worker * An opaque replaceable text object. This will be manipulated only 39*0e209d39SAndroid Build Coastguard Worker * through the caller-supplied UReplaceableFunctor struct. Related 40*0e209d39SAndroid Build Coastguard Worker * to the C++ class Replaceable. 41*0e209d39SAndroid Build Coastguard Worker * This is currently only used in the Transliterator C API, see utrans.h . 42*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 43*0e209d39SAndroid Build Coastguard Worker */ 44*0e209d39SAndroid Build Coastguard Worker typedef void* UReplaceable; 45*0e209d39SAndroid Build Coastguard Worker 46*0e209d39SAndroid Build Coastguard Worker /** 47*0e209d39SAndroid Build Coastguard Worker * A set of function pointers that transliterators use to manipulate a 48*0e209d39SAndroid Build Coastguard Worker * UReplaceable. The caller should supply the required functions to 49*0e209d39SAndroid Build Coastguard Worker * manipulate their text appropriately. Related to the C++ class 50*0e209d39SAndroid Build Coastguard Worker * Replaceable. 51*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 52*0e209d39SAndroid Build Coastguard Worker */ 53*0e209d39SAndroid Build Coastguard Worker typedef struct UReplaceableCallbacks { 54*0e209d39SAndroid Build Coastguard Worker 55*0e209d39SAndroid Build Coastguard Worker /** 56*0e209d39SAndroid Build Coastguard Worker * Function pointer that returns the number of UChar code units in 57*0e209d39SAndroid Build Coastguard Worker * this text. 58*0e209d39SAndroid Build Coastguard Worker * 59*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 60*0e209d39SAndroid Build Coastguard Worker * @return The length of the text. 61*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 62*0e209d39SAndroid Build Coastguard Worker */ 63*0e209d39SAndroid Build Coastguard Worker int32_t (*length)(const UReplaceable* rep); 64*0e209d39SAndroid Build Coastguard Worker 65*0e209d39SAndroid Build Coastguard Worker /** 66*0e209d39SAndroid Build Coastguard Worker * Function pointer that returns a UChar code units at the given 67*0e209d39SAndroid Build Coastguard Worker * offset into this text; 0 <= offset < n, where n is the value 68*0e209d39SAndroid Build Coastguard Worker * returned by (*length)(rep). See unistr.h for a description of 69*0e209d39SAndroid Build Coastguard Worker * charAt() vs. char32At(). 70*0e209d39SAndroid Build Coastguard Worker * 71*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 72*0e209d39SAndroid Build Coastguard Worker * @param offset The index at which to fetch the UChar (code unit). 73*0e209d39SAndroid Build Coastguard Worker * @return The UChar (code unit) at offset, or U+FFFF if the offset is out of bounds. 74*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 75*0e209d39SAndroid Build Coastguard Worker */ 76*0e209d39SAndroid Build Coastguard Worker UChar (*charAt)(const UReplaceable* rep, 77*0e209d39SAndroid Build Coastguard Worker int32_t offset); 78*0e209d39SAndroid Build Coastguard Worker 79*0e209d39SAndroid Build Coastguard Worker /** 80*0e209d39SAndroid Build Coastguard Worker * Function pointer that returns a UChar32 code point at the given 81*0e209d39SAndroid Build Coastguard Worker * offset into this text. See unistr.h for a description of 82*0e209d39SAndroid Build Coastguard Worker * charAt() vs. char32At(). 83*0e209d39SAndroid Build Coastguard Worker * 84*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 85*0e209d39SAndroid Build Coastguard Worker * @param offset The index at which to fetch the UChar32 (code point). 86*0e209d39SAndroid Build Coastguard Worker * @return The UChar32 (code point) at offset, or U+FFFF if the offset is out of bounds. 87*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 88*0e209d39SAndroid Build Coastguard Worker */ 89*0e209d39SAndroid Build Coastguard Worker UChar32 (*char32At)(const UReplaceable* rep, 90*0e209d39SAndroid Build Coastguard Worker int32_t offset); 91*0e209d39SAndroid Build Coastguard Worker 92*0e209d39SAndroid Build Coastguard Worker /** 93*0e209d39SAndroid Build Coastguard Worker * Function pointer that replaces text between start and limit in 94*0e209d39SAndroid Build Coastguard Worker * this text with the given text. Attributes (out of band info) 95*0e209d39SAndroid Build Coastguard Worker * should be retained. 96*0e209d39SAndroid Build Coastguard Worker * 97*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 98*0e209d39SAndroid Build Coastguard Worker * @param start the starting index of the text to be replaced, 99*0e209d39SAndroid Build Coastguard Worker * inclusive. 100*0e209d39SAndroid Build Coastguard Worker * @param limit the ending index of the text to be replaced, 101*0e209d39SAndroid Build Coastguard Worker * exclusive. 102*0e209d39SAndroid Build Coastguard Worker * @param text the new text to replace the UChars from 103*0e209d39SAndroid Build Coastguard Worker * start..limit-1. 104*0e209d39SAndroid Build Coastguard Worker * @param textLength the number of UChars at text, or -1 if text 105*0e209d39SAndroid Build Coastguard Worker * is null-terminated. 106*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 107*0e209d39SAndroid Build Coastguard Worker */ 108*0e209d39SAndroid Build Coastguard Worker void (*replace)(UReplaceable* rep, 109*0e209d39SAndroid Build Coastguard Worker int32_t start, 110*0e209d39SAndroid Build Coastguard Worker int32_t limit, 111*0e209d39SAndroid Build Coastguard Worker const UChar* text, 112*0e209d39SAndroid Build Coastguard Worker int32_t textLength); 113*0e209d39SAndroid Build Coastguard Worker 114*0e209d39SAndroid Build Coastguard Worker /** 115*0e209d39SAndroid Build Coastguard Worker * Function pointer that copies the characters in the range 116*0e209d39SAndroid Build Coastguard Worker * [<tt>start</tt>, <tt>limit</tt>) into the array <tt>dst</tt>. 117*0e209d39SAndroid Build Coastguard Worker * 118*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 119*0e209d39SAndroid Build Coastguard Worker * @param start offset of first character which will be copied 120*0e209d39SAndroid Build Coastguard Worker * into the array 121*0e209d39SAndroid Build Coastguard Worker * @param limit offset immediately following the last character to 122*0e209d39SAndroid Build Coastguard Worker * be copied 123*0e209d39SAndroid Build Coastguard Worker * @param dst array in which to copy characters. The length of 124*0e209d39SAndroid Build Coastguard Worker * <tt>dst</tt> must be at least <tt>(limit - start)</tt>. 125*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.1 126*0e209d39SAndroid Build Coastguard Worker */ 127*0e209d39SAndroid Build Coastguard Worker void (*extract)(UReplaceable* rep, 128*0e209d39SAndroid Build Coastguard Worker int32_t start, 129*0e209d39SAndroid Build Coastguard Worker int32_t limit, 130*0e209d39SAndroid Build Coastguard Worker UChar* dst); 131*0e209d39SAndroid Build Coastguard Worker 132*0e209d39SAndroid Build Coastguard Worker /** 133*0e209d39SAndroid Build Coastguard Worker * Function pointer that copies text between start and limit in 134*0e209d39SAndroid Build Coastguard Worker * this text to another index in the text. Attributes (out of 135*0e209d39SAndroid Build Coastguard Worker * band info) should be retained. After this call, there will be 136*0e209d39SAndroid Build Coastguard Worker * (at least) two copies of the characters originally located at 137*0e209d39SAndroid Build Coastguard Worker * start..limit-1. 138*0e209d39SAndroid Build Coastguard Worker * 139*0e209d39SAndroid Build Coastguard Worker * @param rep A pointer to "this" UReplaceable object. 140*0e209d39SAndroid Build Coastguard Worker * @param start the starting index of the text to be copied, 141*0e209d39SAndroid Build Coastguard Worker * inclusive. 142*0e209d39SAndroid Build Coastguard Worker * @param limit the ending index of the text to be copied, 143*0e209d39SAndroid Build Coastguard Worker * exclusive. 144*0e209d39SAndroid Build Coastguard Worker * @param dest the index at which the copy of the UChars should be 145*0e209d39SAndroid Build Coastguard Worker * inserted. 146*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 147*0e209d39SAndroid Build Coastguard Worker */ 148*0e209d39SAndroid Build Coastguard Worker void (*copy)(UReplaceable* rep, 149*0e209d39SAndroid Build Coastguard Worker int32_t start, 150*0e209d39SAndroid Build Coastguard Worker int32_t limit, 151*0e209d39SAndroid Build Coastguard Worker int32_t dest); 152*0e209d39SAndroid Build Coastguard Worker 153*0e209d39SAndroid Build Coastguard Worker } UReplaceableCallbacks; 154*0e209d39SAndroid Build Coastguard Worker 155*0e209d39SAndroid Build Coastguard Worker U_CDECL_END 156*0e209d39SAndroid Build Coastguard Worker 157*0e209d39SAndroid Build Coastguard Worker #endif 158