xref: /aosp_15_r20/external/icu/libicu/cts_headers/uresdata.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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) 1999-2016, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker *                Corporation and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker *   file name:  uresdata.h
9*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
10*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
11*0e209d39SAndroid Build Coastguard Worker *   indentation:4
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker *   created on: 1999dec08
14*0e209d39SAndroid Build Coastguard Worker *   created by: Markus W. Scherer
15*0e209d39SAndroid Build Coastguard Worker *   06/24/02    weiv        Added support for resource sharing
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker 
18*0e209d39SAndroid Build Coastguard Worker #ifndef __RESDATA_H__
19*0e209d39SAndroid Build Coastguard Worker #define __RESDATA_H__
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/udata.h"
23*0e209d39SAndroid Build Coastguard Worker #include "unicode/ures.h"
24*0e209d39SAndroid Build Coastguard Worker #include "putilimp.h"
25*0e209d39SAndroid Build Coastguard Worker #include "udataswp.h"
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker /**
28*0e209d39SAndroid Build Coastguard Worker  * Numeric constants for internal-only types of resource items.
29*0e209d39SAndroid Build Coastguard Worker  * These must use different numeric values than UResType constants
30*0e209d39SAndroid Build Coastguard Worker  * because they are used together.
31*0e209d39SAndroid Build Coastguard Worker  * Internal types are never returned by ures_getType().
32*0e209d39SAndroid Build Coastguard Worker  */
33*0e209d39SAndroid Build Coastguard Worker typedef enum {
34*0e209d39SAndroid Build Coastguard Worker     /** Include a negative value so that the compiler uses the same int type as for UResType. */
35*0e209d39SAndroid Build Coastguard Worker     URES_INTERNAL_NONE=-1,
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker     /** Resource type constant for tables with 32-bit count, key offsets and values. */
38*0e209d39SAndroid Build Coastguard Worker     URES_TABLE32=4,
39*0e209d39SAndroid Build Coastguard Worker 
40*0e209d39SAndroid Build Coastguard Worker     /**
41*0e209d39SAndroid Build Coastguard Worker      * Resource type constant for tables with 16-bit count, key offsets and values.
42*0e209d39SAndroid Build Coastguard Worker      * All values are URES_STRING_V2 strings.
43*0e209d39SAndroid Build Coastguard Worker      */
44*0e209d39SAndroid Build Coastguard Worker     URES_TABLE16=5,
45*0e209d39SAndroid Build Coastguard Worker 
46*0e209d39SAndroid Build Coastguard Worker     /** Resource type constant for 16-bit Unicode strings in formatVersion 2. */
47*0e209d39SAndroid Build Coastguard Worker     URES_STRING_V2=6,
48*0e209d39SAndroid Build Coastguard Worker 
49*0e209d39SAndroid Build Coastguard Worker     /**
50*0e209d39SAndroid Build Coastguard Worker      * Resource type constant for arrays with 16-bit count and values.
51*0e209d39SAndroid Build Coastguard Worker      * All values are URES_STRING_V2 strings.
52*0e209d39SAndroid Build Coastguard Worker      */
53*0e209d39SAndroid Build Coastguard Worker     URES_ARRAY16=9
54*0e209d39SAndroid Build Coastguard Worker 
55*0e209d39SAndroid Build Coastguard Worker     /* Resource type 15 is not defined but effectively used by RES_BOGUS=0xffffffff. */
56*0e209d39SAndroid Build Coastguard Worker } UResInternalType;
57*0e209d39SAndroid Build Coastguard Worker 
58*0e209d39SAndroid Build Coastguard Worker /*
59*0e209d39SAndroid Build Coastguard Worker  * A Resource is a 32-bit value that has 2 bit fields:
60*0e209d39SAndroid Build Coastguard Worker  * 31..28   4-bit type, see enum below
61*0e209d39SAndroid Build Coastguard Worker  * 27..0    28-bit four-byte-offset or value according to the type
62*0e209d39SAndroid Build Coastguard Worker  */
63*0e209d39SAndroid Build Coastguard Worker typedef uint32_t Resource;
64*0e209d39SAndroid Build Coastguard Worker 
65*0e209d39SAndroid Build Coastguard Worker #define RES_BOGUS 0xffffffff
66*0e209d39SAndroid Build Coastguard Worker #define RES_MAX_OFFSET 0x0fffffff
67*0e209d39SAndroid Build Coastguard Worker 
68*0e209d39SAndroid Build Coastguard Worker #define RES_GET_TYPE(res) ((int32_t)((res)>>28UL))
69*0e209d39SAndroid Build Coastguard Worker #define RES_GET_OFFSET(res) ((res)&0x0fffffff)
70*0e209d39SAndroid Build Coastguard Worker #define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res))
71*0e209d39SAndroid Build Coastguard Worker 
72*0e209d39SAndroid Build Coastguard Worker /* get signed and unsigned integer values directly from the Resource handle
73*0e209d39SAndroid Build Coastguard Worker  * NOTE: For proper logging, please use the res_getInt() constexpr
74*0e209d39SAndroid Build Coastguard Worker  */
75*0e209d39SAndroid Build Coastguard Worker #if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
76*0e209d39SAndroid Build Coastguard Worker #   define RES_GET_INT_NO_TRACE(res) (((int32_t)((res)<<4L))>>4L)
77*0e209d39SAndroid Build Coastguard Worker #else
78*0e209d39SAndroid Build Coastguard Worker #   define RES_GET_INT_NO_TRACE(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (res)&0x07ffffff)
79*0e209d39SAndroid Build Coastguard Worker #endif
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker #define RES_GET_UINT_NO_TRACE(res) ((res)&0x0fffffff)
82*0e209d39SAndroid Build Coastguard Worker 
83*0e209d39SAndroid Build Coastguard Worker #define URES_IS_ARRAY(type) ((int32_t)(type)==URES_ARRAY || (int32_t)(type)==URES_ARRAY16)
84*0e209d39SAndroid Build Coastguard Worker #define URES_IS_TABLE(type) ((int32_t)(type)==URES_TABLE || (int32_t)(type)==URES_TABLE16 || (int32_t)(type)==URES_TABLE32)
85*0e209d39SAndroid Build Coastguard Worker #define URES_IS_CONTAINER(type) (URES_IS_TABLE(type) || URES_IS_ARRAY(type))
86*0e209d39SAndroid Build Coastguard Worker 
87*0e209d39SAndroid Build Coastguard Worker #define URES_MAKE_RESOURCE(type, offset) (((Resource)(type)<<28)|(Resource)(offset))
88*0e209d39SAndroid Build Coastguard Worker #define URES_MAKE_EMPTY_RESOURCE(type) ((Resource)(type)<<28)
89*0e209d39SAndroid Build Coastguard Worker 
90*0e209d39SAndroid Build Coastguard Worker /* indexes[] value names; indexes are generally 32-bit (Resource) indexes */
91*0e209d39SAndroid Build Coastguard Worker enum {
92*0e209d39SAndroid Build Coastguard Worker     /**
93*0e209d39SAndroid Build Coastguard Worker      * [0] contains the length of indexes[]
94*0e209d39SAndroid Build Coastguard Worker      * which is at most URES_INDEX_TOP of the latest format version
95*0e209d39SAndroid Build Coastguard Worker      *
96*0e209d39SAndroid Build Coastguard Worker      * formatVersion==1: all bits contain the length of indexes[]
97*0e209d39SAndroid Build Coastguard Worker      *   but the length is much less than 0xff;
98*0e209d39SAndroid Build Coastguard Worker      * formatVersion>1:
99*0e209d39SAndroid Build Coastguard Worker      *   only bits  7..0 contain the length of indexes[],
100*0e209d39SAndroid Build Coastguard Worker      *        bits 31..8 are reserved and set to 0
101*0e209d39SAndroid Build Coastguard Worker      * formatVersion>=3:
102*0e209d39SAndroid Build Coastguard Worker      *        bits 31..8 poolStringIndexLimit bits 23..0
103*0e209d39SAndroid Build Coastguard Worker      */
104*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_LENGTH,
105*0e209d39SAndroid Build Coastguard Worker     /**
106*0e209d39SAndroid Build Coastguard Worker      * [1] contains the top of the key strings,
107*0e209d39SAndroid Build Coastguard Worker      *     same as the bottom of resources or UTF-16 strings, rounded up
108*0e209d39SAndroid Build Coastguard Worker      */
109*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_KEYS_TOP,
110*0e209d39SAndroid Build Coastguard Worker     /** [2] contains the top of all resources */
111*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_RESOURCES_TOP,
112*0e209d39SAndroid Build Coastguard Worker     /**
113*0e209d39SAndroid Build Coastguard Worker      * [3] contains the top of the bundle,
114*0e209d39SAndroid Build Coastguard Worker      *     in case it were ever different from [2]
115*0e209d39SAndroid Build Coastguard Worker      */
116*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_BUNDLE_TOP,
117*0e209d39SAndroid Build Coastguard Worker     /** [4] max. length of any table */
118*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_MAX_TABLE_LENGTH,
119*0e209d39SAndroid Build Coastguard Worker     /**
120*0e209d39SAndroid Build Coastguard Worker      * [5] attributes bit set, see URES_ATT_* (new in formatVersion 1.2)
121*0e209d39SAndroid Build Coastguard Worker      *
122*0e209d39SAndroid Build Coastguard Worker      * formatVersion>=3:
123*0e209d39SAndroid Build Coastguard Worker      *   bits 31..16 poolStringIndex16Limit
124*0e209d39SAndroid Build Coastguard Worker      *   bits 15..12 poolStringIndexLimit bits 27..24
125*0e209d39SAndroid Build Coastguard Worker      */
126*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_ATTRIBUTES,
127*0e209d39SAndroid Build Coastguard Worker     /**
128*0e209d39SAndroid Build Coastguard Worker      * [6] top of the 16-bit units (UTF-16 string v2 UChars, URES_TABLE16, URES_ARRAY16),
129*0e209d39SAndroid Build Coastguard Worker      *     rounded up (new in formatVersion 2.0, ICU 4.4)
130*0e209d39SAndroid Build Coastguard Worker      */
131*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_16BIT_TOP,
132*0e209d39SAndroid Build Coastguard Worker     /** [7] checksum of the pool bundle (new in formatVersion 2.0, ICU 4.4) */
133*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_POOL_CHECKSUM,
134*0e209d39SAndroid Build Coastguard Worker     URES_INDEX_TOP
135*0e209d39SAndroid Build Coastguard Worker };
136*0e209d39SAndroid Build Coastguard Worker 
137*0e209d39SAndroid Build Coastguard Worker /*
138*0e209d39SAndroid Build Coastguard Worker  * Nofallback attribute, attribute bit 0 in indexes[URES_INDEX_ATTRIBUTES].
139*0e209d39SAndroid Build Coastguard Worker  * New in formatVersion 1.2 (ICU 3.6).
140*0e209d39SAndroid Build Coastguard Worker  *
141*0e209d39SAndroid Build Coastguard Worker  * If set, then this resource bundle is a standalone bundle.
142*0e209d39SAndroid Build Coastguard Worker  * If not set, then the bundle participates in locale fallback, eventually
143*0e209d39SAndroid Build Coastguard Worker  * all the way to the root bundle.
144*0e209d39SAndroid Build Coastguard Worker  * If indexes[] is missing or too short, then the attribute cannot be determined
145*0e209d39SAndroid Build Coastguard Worker  * reliably. Dependency checking should ignore such bundles, and loading should
146*0e209d39SAndroid Build Coastguard Worker  * use fallbacks.
147*0e209d39SAndroid Build Coastguard Worker  */
148*0e209d39SAndroid Build Coastguard Worker #define URES_ATT_NO_FALLBACK 1
149*0e209d39SAndroid Build Coastguard Worker 
150*0e209d39SAndroid Build Coastguard Worker /*
151*0e209d39SAndroid Build Coastguard Worker  * Attributes for bundles that are, or use, a pool bundle.
152*0e209d39SAndroid Build Coastguard Worker  * A pool bundle provides key strings that are shared among several other bundles
153*0e209d39SAndroid Build Coastguard Worker  * to reduce their total size.
154*0e209d39SAndroid Build Coastguard Worker  * New in formatVersion 2 (ICU 4.4).
155*0e209d39SAndroid Build Coastguard Worker  */
156*0e209d39SAndroid Build Coastguard Worker #define URES_ATT_IS_POOL_BUNDLE 2
157*0e209d39SAndroid Build Coastguard Worker #define URES_ATT_USES_POOL_BUNDLE 4
158*0e209d39SAndroid Build Coastguard Worker 
159*0e209d39SAndroid Build Coastguard Worker /*
160*0e209d39SAndroid Build Coastguard Worker  * File format for .res resource bundle files
161*0e209d39SAndroid Build Coastguard Worker  *
162*0e209d39SAndroid Build Coastguard Worker  * ICU 56: New in formatVersion 3 compared with 2: -------------
163*0e209d39SAndroid Build Coastguard Worker  *
164*0e209d39SAndroid Build Coastguard Worker  * Resource bundles can optionally use shared string-v2 values
165*0e209d39SAndroid Build Coastguard Worker  * stored in the pool bundle.
166*0e209d39SAndroid Build Coastguard Worker  * If so, then the indexes[] contain two new values
167*0e209d39SAndroid Build Coastguard Worker  * in previously-unused bits of existing indexes[] slots:
168*0e209d39SAndroid Build Coastguard Worker  * - poolStringIndexLimit:
169*0e209d39SAndroid Build Coastguard Worker  *     String-v2 offsets (in 32-bit Resource words) below this limit
170*0e209d39SAndroid Build Coastguard Worker  *     point to pool bundle string-v2 values.
171*0e209d39SAndroid Build Coastguard Worker  * - poolStringIndex16Limit:
172*0e209d39SAndroid Build Coastguard Worker  *     Resource16 string-v2 offsets below this limit
173*0e209d39SAndroid Build Coastguard Worker  *     point to pool bundle string-v2 values.
174*0e209d39SAndroid Build Coastguard Worker  * Guarantee: poolStringIndex16Limit <= poolStringIndexLimit
175*0e209d39SAndroid Build Coastguard Worker  *
176*0e209d39SAndroid Build Coastguard Worker  * The local bundle's poolStringIndexLimit is greater than
177*0e209d39SAndroid Build Coastguard Worker  * any pool bundle string index used in the local bundle.
178*0e209d39SAndroid Build Coastguard Worker  * The poolStringIndexLimit should not be greater than
179*0e209d39SAndroid Build Coastguard Worker  * the maximum possible pool bundle string index.
180*0e209d39SAndroid Build Coastguard Worker  *
181*0e209d39SAndroid Build Coastguard Worker  * The maximum possible pool bundle string index is the index to the last non-NUL
182*0e209d39SAndroid Build Coastguard Worker  * pool string character, due to suffix sharing.
183*0e209d39SAndroid Build Coastguard Worker  *
184*0e209d39SAndroid Build Coastguard Worker  * In the pool bundle, there is no structure that lists the strings.
185*0e209d39SAndroid Build Coastguard Worker  * (The root resource is an empty Table.)
186*0e209d39SAndroid Build Coastguard Worker  * If the strings need to be enumerated (as genrb --usePoolBundle does),
187*0e209d39SAndroid Build Coastguard Worker  * then iterate through the pool bundle's 16-bit-units array from the beginning.
188*0e209d39SAndroid Build Coastguard Worker  * Stop at the end of the array, or when an explicit or implicit string length
189*0e209d39SAndroid Build Coastguard Worker  * would lead beyond the end of the array,
190*0e209d39SAndroid Build Coastguard Worker  * or when an apparent string is not NUL-terminated.
191*0e209d39SAndroid Build Coastguard Worker  * (Future genrb version might terminate the strings with
192*0e209d39SAndroid Build Coastguard Worker  * what looks like a large explicit string length.)
193*0e209d39SAndroid Build Coastguard Worker  *
194*0e209d39SAndroid Build Coastguard Worker  * ICU 4.4: New in formatVersion 2 compared with 1.3: -------------
195*0e209d39SAndroid Build Coastguard Worker  *
196*0e209d39SAndroid Build Coastguard Worker  * Three new resource types -- String-v2, Table16 and Array16 -- have their
197*0e209d39SAndroid Build Coastguard Worker  * values stored in a new array of 16-bit units between the table key strings
198*0e209d39SAndroid Build Coastguard Worker  * and the start of the other resources.
199*0e209d39SAndroid Build Coastguard Worker  *
200*0e209d39SAndroid Build Coastguard Worker  * genrb eliminates duplicates among Unicode string-v2 values.
201*0e209d39SAndroid Build Coastguard Worker  * Multiple Unicode strings may use the same offset and string data,
202*0e209d39SAndroid Build Coastguard Worker  * or a short string may point to the suffix of a longer string. ("Suffix sharing")
203*0e209d39SAndroid Build Coastguard Worker  * For example, one string "abc" may be reused for another string "bc" by pointing
204*0e209d39SAndroid Build Coastguard Worker  * to the second character. (Short strings-v2 are NUL-terminated
205*0e209d39SAndroid Build Coastguard Worker  * and not preceded by an explicit length value.)
206*0e209d39SAndroid Build Coastguard Worker  *
207*0e209d39SAndroid Build Coastguard Worker  * It is allowed for all resource types to share values.
208*0e209d39SAndroid Build Coastguard Worker  * The swapper code (ures_swap()) has been modified so that it swaps each item
209*0e209d39SAndroid Build Coastguard Worker  * exactly once.
210*0e209d39SAndroid Build Coastguard Worker  *
211*0e209d39SAndroid Build Coastguard Worker  * A resource bundle may use a special pool bundle. Some or all of the table key strings
212*0e209d39SAndroid Build Coastguard Worker  * of the using-bundle are omitted, and the key string offsets for such key strings refer
213*0e209d39SAndroid Build Coastguard Worker  * to offsets in the pool bundle.
214*0e209d39SAndroid Build Coastguard Worker  * The using-bundle's and the pool-bundle's indexes[URES_INDEX_POOL_CHECKSUM] values
215*0e209d39SAndroid Build Coastguard Worker  * must match.
216*0e209d39SAndroid Build Coastguard Worker  * Two bits in indexes[URES_INDEX_ATTRIBUTES] indicate whether a resource bundle
217*0e209d39SAndroid Build Coastguard Worker  * is or uses a pool bundle.
218*0e209d39SAndroid Build Coastguard Worker  *
219*0e209d39SAndroid Build Coastguard Worker  * Table key strings must be compared in ASCII order, even if they are not
220*0e209d39SAndroid Build Coastguard Worker  * stored in ASCII.
221*0e209d39SAndroid Build Coastguard Worker  *
222*0e209d39SAndroid Build Coastguard Worker  * New in formatVersion 1.3 compared with 1.2: -------------
223*0e209d39SAndroid Build Coastguard Worker  *
224*0e209d39SAndroid Build Coastguard Worker  * genrb eliminates duplicates among key strings.
225*0e209d39SAndroid Build Coastguard Worker  * Multiple table items may share one key string, or one item may point
226*0e209d39SAndroid Build Coastguard Worker  * to the suffix of another's key string. ("Suffix sharing")
227*0e209d39SAndroid Build Coastguard Worker  * For example, one key "abc" may be reused for another key "bc" by pointing
228*0e209d39SAndroid Build Coastguard Worker  * to the second character. (Key strings are NUL-terminated.)
229*0e209d39SAndroid Build Coastguard Worker  *
230*0e209d39SAndroid Build Coastguard Worker  * -------------
231*0e209d39SAndroid Build Coastguard Worker  *
232*0e209d39SAndroid Build Coastguard Worker  * An ICU4C resource bundle file (.res) is a binary, memory-mappable file
233*0e209d39SAndroid Build Coastguard Worker  * with nested, hierarchical data structures.
234*0e209d39SAndroid Build Coastguard Worker  * It physically contains the following:
235*0e209d39SAndroid Build Coastguard Worker  *
236*0e209d39SAndroid Build Coastguard Worker  *   Resource root; -- 32-bit Resource item, root item for this bundle's tree;
237*0e209d39SAndroid Build Coastguard Worker  *                     currently, the root item must be a table or table32 resource item
238*0e209d39SAndroid Build Coastguard Worker  *   int32_t indexes[indexes[0]]; -- array of indexes for friendly
239*0e209d39SAndroid Build Coastguard Worker  *                                   reading and swapping; see URES_INDEX_* above
240*0e209d39SAndroid Build Coastguard Worker  *                                   new in formatVersion 1.1 (ICU 2.8)
241*0e209d39SAndroid Build Coastguard Worker  *   char keys[]; -- characters for key strings
242*0e209d39SAndroid Build Coastguard Worker  *                   (formatVersion 1.0: up to 65k of characters; 1.1: <2G)
243*0e209d39SAndroid Build Coastguard Worker  *                   (minus the space for root and indexes[]),
244*0e209d39SAndroid Build Coastguard Worker  *                   which consist of invariant characters (ASCII/EBCDIC) and are NUL-terminated;
245*0e209d39SAndroid Build Coastguard Worker  *                   padded to multiple of 4 bytes for 4-alignment of the following data
246*0e209d39SAndroid Build Coastguard Worker  *   uint16_t 16BitUnits[]; -- resources that are stored entirely as sequences of 16-bit units
247*0e209d39SAndroid Build Coastguard Worker  *                             (new in formatVersion 2/ICU 4.4)
248*0e209d39SAndroid Build Coastguard Worker  *                             data is indexed by the offset values in 16-bit resource types,
249*0e209d39SAndroid Build Coastguard Worker  *                             with offset 0 pointing to the beginning of this array;
250*0e209d39SAndroid Build Coastguard Worker  *                             there is a 0 at offset 0, for empty resources;
251*0e209d39SAndroid Build Coastguard Worker  *                             padded to multiple of 4 bytes for 4-alignment of the following data
252*0e209d39SAndroid Build Coastguard Worker  *   data; -- data directly and indirectly indexed by the root item;
253*0e209d39SAndroid Build Coastguard Worker  *            the structure is determined by walking the tree
254*0e209d39SAndroid Build Coastguard Worker  *
255*0e209d39SAndroid Build Coastguard Worker  * Each resource bundle item has a 32-bit Resource handle (see typedef above)
256*0e209d39SAndroid Build Coastguard Worker  * which contains the item type number in its upper 4 bits (31..28) and either
257*0e209d39SAndroid Build Coastguard Worker  * an offset or a direct value in its lower 28 bits (27..0).
258*0e209d39SAndroid Build Coastguard Worker  * The order of items is undefined and only determined by walking the tree.
259*0e209d39SAndroid Build Coastguard Worker  * Leaves of the tree may be stored first or last or anywhere in between,
260*0e209d39SAndroid Build Coastguard Worker  * and it is in theory possible to have unreferenced holes in the file.
261*0e209d39SAndroid Build Coastguard Worker  *
262*0e209d39SAndroid Build Coastguard Worker  * 16-bit-unit values:
263*0e209d39SAndroid Build Coastguard Worker  * Starting with formatVersion 2/ICU 4.4, some resources are stored in a special
264*0e209d39SAndroid Build Coastguard Worker  * array of 16-bit units. Each resource value is a sequence of 16-bit units,
265*0e209d39SAndroid Build Coastguard Worker  * with no per-resource padding to a 4-byte boundary.
266*0e209d39SAndroid Build Coastguard Worker  * 16-bit container types (Table16 and Array16) contain Resource16 values
267*0e209d39SAndroid Build Coastguard Worker  * which are offsets to String-v2 resources in the same 16-bit-units array.
268*0e209d39SAndroid Build Coastguard Worker  *
269*0e209d39SAndroid Build Coastguard Worker  * Direct values:
270*0e209d39SAndroid Build Coastguard Worker  * - Empty Unicode strings have an offset value of 0 in the Resource handle itself.
271*0e209d39SAndroid Build Coastguard Worker  * - Starting with formatVersion 2/ICU 4.4, an offset value of 0 for
272*0e209d39SAndroid Build Coastguard Worker  *   _any_ resource type indicates an empty value.
273*0e209d39SAndroid Build Coastguard Worker  * - Integer values are 28-bit values stored in the Resource handle itself;
274*0e209d39SAndroid Build Coastguard Worker  *   the interpretation of unsigned vs. signed integers is up to the application.
275*0e209d39SAndroid Build Coastguard Worker  *
276*0e209d39SAndroid Build Coastguard Worker  * All other types and values use 28-bit offsets to point to the item's data.
277*0e209d39SAndroid Build Coastguard Worker  * The offset is an index to the first 32-bit word of the value, relative to the
278*0e209d39SAndroid Build Coastguard Worker  * start of the resource data (i.e., the root item handle is at offset 0).
279*0e209d39SAndroid Build Coastguard Worker  * To get byte offsets, the offset is multiplied by 4 (or shifted left by 2 bits).
280*0e209d39SAndroid Build Coastguard Worker  * All resource item values are 4-aligned.
281*0e209d39SAndroid Build Coastguard Worker  *
282*0e209d39SAndroid Build Coastguard Worker  * New in formatVersion 2/ICU 4.4: Some types use offsets into the 16-bit-units array,
283*0e209d39SAndroid Build Coastguard Worker  * indexing 16-bit units in that array.
284*0e209d39SAndroid Build Coastguard Worker  *
285*0e209d39SAndroid Build Coastguard Worker  * The structures (memory layouts) for the values for each item type are listed
286*0e209d39SAndroid Build Coastguard Worker  * in the table below.
287*0e209d39SAndroid Build Coastguard Worker  *
288*0e209d39SAndroid Build Coastguard Worker  * Nested, hierarchical structures: -------------
289*0e209d39SAndroid Build Coastguard Worker  *
290*0e209d39SAndroid Build Coastguard Worker  * Table items contain key-value pairs where the keys are offsets to char * key strings.
291*0e209d39SAndroid Build Coastguard Worker  * The values of these pairs are either Resource handles or
292*0e209d39SAndroid Build Coastguard Worker  * offsets into the 16-bit-units array, depending on the table type.
293*0e209d39SAndroid Build Coastguard Worker  *
294*0e209d39SAndroid Build Coastguard Worker  * Array items are simple vectors of Resource handles,
295*0e209d39SAndroid Build Coastguard Worker  * or of offsets into the 16-bit-units array, depending on the array type.
296*0e209d39SAndroid Build Coastguard Worker  *
297*0e209d39SAndroid Build Coastguard Worker  * Table key string offsets: -------
298*0e209d39SAndroid Build Coastguard Worker  *
299*0e209d39SAndroid Build Coastguard Worker  * Key string offsets are relative to the start of the resource data (of the root handle),
300*0e209d39SAndroid Build Coastguard Worker  * i.e., the first string has an offset of 4+sizeof(indexes).
301*0e209d39SAndroid Build Coastguard Worker  * (After the 4-byte root handle and after the indexes array.)
302*0e209d39SAndroid Build Coastguard Worker  *
303*0e209d39SAndroid Build Coastguard Worker  * If the resource bundle uses a pool bundle, then some key strings are stored
304*0e209d39SAndroid Build Coastguard Worker  * in the pool bundle rather than in the local bundle itself.
305*0e209d39SAndroid Build Coastguard Worker  * - In a Table or Table16, the 16-bit key string offset is local if it is
306*0e209d39SAndroid Build Coastguard Worker  *   less than indexes[URES_INDEX_KEYS_TOP]<<2.
307*0e209d39SAndroid Build Coastguard Worker  *   Otherwise, subtract indexes[URES_INDEX_KEYS_TOP]<<2 to get the offset into
308*0e209d39SAndroid Build Coastguard Worker  *   the pool bundle key strings.
309*0e209d39SAndroid Build Coastguard Worker  * - In a Table32, the 32-bit key string offset is local if it is non-negative.
310*0e209d39SAndroid Build Coastguard Worker  *   Otherwise, reset bit 31 to get the pool key string offset.
311*0e209d39SAndroid Build Coastguard Worker  *
312*0e209d39SAndroid Build Coastguard Worker  * Unlike the local offset, the pool key offset is relative to
313*0e209d39SAndroid Build Coastguard Worker  * the start of the key strings, not to the start of the bundle.
314*0e209d39SAndroid Build Coastguard Worker  *
315*0e209d39SAndroid Build Coastguard Worker  * An alias item is special (and new in ICU 2.4): --------------
316*0e209d39SAndroid Build Coastguard Worker  *
317*0e209d39SAndroid Build Coastguard Worker  * Its memory layout is just like for a UnicodeString, but at runtime it resolves to
318*0e209d39SAndroid Build Coastguard Worker  * another resource bundle's item according to the path in the string.
319*0e209d39SAndroid Build Coastguard Worker  * This is used to share items across bundles that are in different lookup/fallback
320*0e209d39SAndroid Build Coastguard Worker  * chains (e.g., large collation data among zh_TW and zh_HK).
321*0e209d39SAndroid Build Coastguard Worker  * This saves space (for large items) and maintenance effort (less duplication of data).
322*0e209d39SAndroid Build Coastguard Worker  *
323*0e209d39SAndroid Build Coastguard Worker  * --------------------------------------------------------------------------
324*0e209d39SAndroid Build Coastguard Worker  *
325*0e209d39SAndroid Build Coastguard Worker  * Resource types:
326*0e209d39SAndroid Build Coastguard Worker  *
327*0e209d39SAndroid Build Coastguard Worker  * Most resources have their values stored at four-byte offsets from the start
328*0e209d39SAndroid Build Coastguard Worker  * of the resource data. These values are at least 4-aligned.
329*0e209d39SAndroid Build Coastguard Worker  * Some resource values are stored directly in the offset field of the Resource itself.
330*0e209d39SAndroid Build Coastguard Worker  * See UResType in unicode/ures.h for enumeration constants for Resource types.
331*0e209d39SAndroid Build Coastguard Worker  *
332*0e209d39SAndroid Build Coastguard Worker  * Some resources have their values stored as sequences of 16-bit units,
333*0e209d39SAndroid Build Coastguard Worker  * at 2-byte offsets from the start of a contiguous 16-bit-unit array between
334*0e209d39SAndroid Build Coastguard Worker  * the table key strings and the other resources. (new in formatVersion 2/ICU 4.4)
335*0e209d39SAndroid Build Coastguard Worker  * At offset 0 of that array is a 16-bit zero value for empty 16-bit resources.
336*0e209d39SAndroid Build Coastguard Worker  *
337*0e209d39SAndroid Build Coastguard Worker  * Resource16 values in Table16 and Array16 are 16-bit offsets to String-v2
338*0e209d39SAndroid Build Coastguard Worker  * resources, with the offsets relative to the start of the 16-bit-units array.
339*0e209d39SAndroid Build Coastguard Worker  * Starting with formatVersion 3/ICU 56, if offset<poolStringIndex16Limit
340*0e209d39SAndroid Build Coastguard Worker  * then use the pool bundle's 16-bit-units array,
341*0e209d39SAndroid Build Coastguard Worker  * otherwise subtract that limit and use the local 16-bit-units array.
342*0e209d39SAndroid Build Coastguard Worker  *
343*0e209d39SAndroid Build Coastguard Worker  * Type Name            Memory layout of values
344*0e209d39SAndroid Build Coastguard Worker  *                      (in parentheses: scalar, non-offset values)
345*0e209d39SAndroid Build Coastguard Worker  *
346*0e209d39SAndroid Build Coastguard Worker  * 0  Unicode String:   int32_t length, UChar[length], (UChar)0, (padding)
347*0e209d39SAndroid Build Coastguard Worker  *                  or  (empty string ("") if offset==0)
348*0e209d39SAndroid Build Coastguard Worker  * 1  Binary:           int32_t length, uint8_t[length], (padding)
349*0e209d39SAndroid Build Coastguard Worker  *                      - the start of the bytes is 16-aligned -
350*0e209d39SAndroid Build Coastguard Worker  * 2  Table:            uint16_t count, uint16_t keyStringOffsets[count], (uint16_t padding), Resource[count]
351*0e209d39SAndroid Build Coastguard Worker  * 3  Alias:            (physically same value layout as string, new in ICU 2.4)
352*0e209d39SAndroid Build Coastguard Worker  * 4  Table32:          int32_t count, int32_t keyStringOffsets[count], Resource[count]
353*0e209d39SAndroid Build Coastguard Worker  *                      (new in formatVersion 1.1/ICU 2.8)
354*0e209d39SAndroid Build Coastguard Worker  * 5  Table16:          uint16_t count, uint16_t keyStringOffsets[count], Resource16[count]
355*0e209d39SAndroid Build Coastguard Worker  *                      (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
356*0e209d39SAndroid Build Coastguard Worker  * 6  Unicode String-v2:UChar[length], (UChar)0; length determined by the first UChar:
357*0e209d39SAndroid Build Coastguard Worker  *                      - if first is not a trail surrogate, then the length is implicit
358*0e209d39SAndroid Build Coastguard Worker  *                        and u_strlen() needs to be called
359*0e209d39SAndroid Build Coastguard Worker  *                      - if first<0xdfef then length=first&0x3ff (and skip first)
360*0e209d39SAndroid Build Coastguard Worker  *                      - if first<0xdfff then length=((first-0xdfef)<<16) | second UChar
361*0e209d39SAndroid Build Coastguard Worker  *                      - if first==0xdfff then length=((second UChar)<<16) | third UChar
362*0e209d39SAndroid Build Coastguard Worker  *                      (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
363*0e209d39SAndroid Build Coastguard Worker  *
364*0e209d39SAndroid Build Coastguard Worker  *                      Starting with formatVersion 3/ICU 56, if offset<poolStringIndexLimit
365*0e209d39SAndroid Build Coastguard Worker  *                      then use the pool bundle's 16-bit-units array,
366*0e209d39SAndroid Build Coastguard Worker  *                      otherwise subtract that limit and use the local 16-bit-units array.
367*0e209d39SAndroid Build Coastguard Worker  *                      (Note different limits for Resource16 vs. Resource.)
368*0e209d39SAndroid Build Coastguard Worker  *
369*0e209d39SAndroid Build Coastguard Worker  * 7  Integer:          (28-bit offset is integer value)
370*0e209d39SAndroid Build Coastguard Worker  * 8  Array:            int32_t count, Resource[count]
371*0e209d39SAndroid Build Coastguard Worker  * 9  Array16:          uint16_t count, Resource16[count]
372*0e209d39SAndroid Build Coastguard Worker  *                      (stored in the 16-bit-units array; new in formatVersion 2/ICU 4.4)
373*0e209d39SAndroid Build Coastguard Worker  * 14 Integer Vector:   int32_t length, int32_t[length]
374*0e209d39SAndroid Build Coastguard Worker  * 15 Reserved:         This value denotes special purpose resources and is for internal use.
375*0e209d39SAndroid Build Coastguard Worker  *
376*0e209d39SAndroid Build Coastguard Worker  * Note that there are 3 types with data vector values:
377*0e209d39SAndroid Build Coastguard Worker  * - Vectors of 8-bit bytes stored as type Binary.
378*0e209d39SAndroid Build Coastguard Worker  * - Vectors of 16-bit words stored as type Unicode String or Unicode String-v2
379*0e209d39SAndroid Build Coastguard Worker  *                     (no value restrictions, all values 0..ffff allowed!).
380*0e209d39SAndroid Build Coastguard Worker  * - Vectors of 32-bit words stored as type Integer Vector.
381*0e209d39SAndroid Build Coastguard Worker  */
382*0e209d39SAndroid Build Coastguard Worker 
383*0e209d39SAndroid Build Coastguard Worker /*
384*0e209d39SAndroid Build Coastguard Worker  * Structure for a single, memory-mapped ResourceBundle.
385*0e209d39SAndroid Build Coastguard Worker  */
386*0e209d39SAndroid Build Coastguard Worker typedef struct ResourceData {
387*0e209d39SAndroid Build Coastguard Worker     UDataMemory *data;
388*0e209d39SAndroid Build Coastguard Worker     const int32_t *pRoot;
389*0e209d39SAndroid Build Coastguard Worker     const uint16_t *p16BitUnits;
390*0e209d39SAndroid Build Coastguard Worker     const char *poolBundleKeys;
391*0e209d39SAndroid Build Coastguard Worker     Resource rootRes;
392*0e209d39SAndroid Build Coastguard Worker     int32_t localKeyLimit;
393*0e209d39SAndroid Build Coastguard Worker     const uint16_t *poolBundleStrings;
394*0e209d39SAndroid Build Coastguard Worker     int32_t poolStringIndexLimit;
395*0e209d39SAndroid Build Coastguard Worker     int32_t poolStringIndex16Limit;
396*0e209d39SAndroid Build Coastguard Worker     UBool noFallback; /* see URES_ATT_NO_FALLBACK */
397*0e209d39SAndroid Build Coastguard Worker     UBool isPoolBundle;
398*0e209d39SAndroid Build Coastguard Worker     UBool usesPoolBundle;
399*0e209d39SAndroid Build Coastguard Worker     UBool useNativeStrcmp;
400*0e209d39SAndroid Build Coastguard Worker } ResourceData;
401*0e209d39SAndroid Build Coastguard Worker 
402*0e209d39SAndroid Build Coastguard Worker struct UResourceDataEntry;   // forward declared for ResoureDataValue below; actually defined in uresimp.h
403*0e209d39SAndroid Build Coastguard Worker 
404*0e209d39SAndroid Build Coastguard Worker /*
405*0e209d39SAndroid Build Coastguard Worker  * Read a resource bundle from memory.
406*0e209d39SAndroid Build Coastguard Worker  */
407*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
408*0e209d39SAndroid Build Coastguard Worker res_read(ResourceData *pResData,
409*0e209d39SAndroid Build Coastguard Worker          const UDataInfo *pInfo, const void *inBytes, int32_t length,
410*0e209d39SAndroid Build Coastguard Worker          UErrorCode *errorCode);
411*0e209d39SAndroid Build Coastguard Worker 
412*0e209d39SAndroid Build Coastguard Worker /*
413*0e209d39SAndroid Build Coastguard Worker  * Load a resource bundle file.
414*0e209d39SAndroid Build Coastguard Worker  * The ResourceData structure must be allocated externally.
415*0e209d39SAndroid Build Coastguard Worker  */
416*0e209d39SAndroid Build Coastguard Worker U_CFUNC void
417*0e209d39SAndroid Build Coastguard Worker res_load(ResourceData *pResData,
418*0e209d39SAndroid Build Coastguard Worker          const char *path, const char *name, UErrorCode *errorCode);
419*0e209d39SAndroid Build Coastguard Worker 
420*0e209d39SAndroid Build Coastguard Worker /*
421*0e209d39SAndroid Build Coastguard Worker  * Release a resource bundle file.
422*0e209d39SAndroid Build Coastguard Worker  * This does not release the ResourceData structure itself.
423*0e209d39SAndroid Build Coastguard Worker  */
424*0e209d39SAndroid Build Coastguard Worker U_CFUNC void
425*0e209d39SAndroid Build Coastguard Worker res_unload(ResourceData *pResData);
426*0e209d39SAndroid Build Coastguard Worker 
427*0e209d39SAndroid Build Coastguard Worker U_CAPI UResType U_EXPORT2
428*0e209d39SAndroid Build Coastguard Worker res_getPublicType(Resource res);
429*0e209d39SAndroid Build Coastguard Worker 
430*0e209d39SAndroid Build Coastguard Worker ///////////////////////////////////////////////////////////////////////////
431*0e209d39SAndroid Build Coastguard Worker // To enable tracing, use the inline versions of the res_get* functions. //
432*0e209d39SAndroid Build Coastguard Worker ///////////////////////////////////////////////////////////////////////////
433*0e209d39SAndroid Build Coastguard Worker 
434*0e209d39SAndroid Build Coastguard Worker /*
435*0e209d39SAndroid Build Coastguard Worker  * Return a pointer to a zero-terminated, const UChar* string
436*0e209d39SAndroid Build Coastguard Worker  * and set its length in *pLength.
437*0e209d39SAndroid Build Coastguard Worker  * Returns NULL if not found.
438*0e209d39SAndroid Build Coastguard Worker  */
439*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar * U_EXPORT2
440*0e209d39SAndroid Build Coastguard Worker res_getStringNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
441*0e209d39SAndroid Build Coastguard Worker 
442*0e209d39SAndroid Build Coastguard Worker U_CAPI const uint8_t * U_EXPORT2
443*0e209d39SAndroid Build Coastguard Worker res_getBinaryNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
444*0e209d39SAndroid Build Coastguard Worker 
445*0e209d39SAndroid Build Coastguard Worker U_CAPI const int32_t * U_EXPORT2
446*0e209d39SAndroid Build Coastguard Worker res_getIntVectorNoTrace(const ResourceData *pResData, Resource res, int32_t *pLength);
447*0e209d39SAndroid Build Coastguard Worker 
448*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar * U_EXPORT2
449*0e209d39SAndroid Build Coastguard Worker res_getAlias(const ResourceData *pResData, Resource res, int32_t *pLength);
450*0e209d39SAndroid Build Coastguard Worker 
451*0e209d39SAndroid Build Coastguard Worker U_CAPI Resource U_EXPORT2
452*0e209d39SAndroid Build Coastguard Worker res_getResource(const ResourceData *pResData, const char *key);
453*0e209d39SAndroid Build Coastguard Worker 
454*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
455*0e209d39SAndroid Build Coastguard Worker res_countArrayItems(const ResourceData *pResData, Resource res);
456*0e209d39SAndroid Build Coastguard Worker 
457*0e209d39SAndroid Build Coastguard Worker U_CAPI Resource U_EXPORT2
458*0e209d39SAndroid Build Coastguard Worker res_getArrayItem(const ResourceData *pResData, Resource array, int32_t indexS);
459*0e209d39SAndroid Build Coastguard Worker 
460*0e209d39SAndroid Build Coastguard Worker U_CAPI Resource U_EXPORT2
461*0e209d39SAndroid Build Coastguard Worker res_getTableItemByIndex(const ResourceData *pResData, Resource table, int32_t indexS, const char ** key);
462*0e209d39SAndroid Build Coastguard Worker 
463*0e209d39SAndroid Build Coastguard Worker U_CAPI Resource U_EXPORT2
464*0e209d39SAndroid Build Coastguard Worker res_getTableItemByKey(const ResourceData *pResData, Resource table, int32_t *indexS, const char* * key);
465*0e209d39SAndroid Build Coastguard Worker 
466*0e209d39SAndroid Build Coastguard Worker /**
467*0e209d39SAndroid Build Coastguard Worker  * Iterates over the path and stops when a scalar resource is found.
468*0e209d39SAndroid Build Coastguard Worker  * Follows aliases.
469*0e209d39SAndroid Build Coastguard Worker  * Modifies the contents of *path (replacing separators with NULs),
470*0e209d39SAndroid Build Coastguard Worker  * and also moves *path forward while it finds items.
471*0e209d39SAndroid Build Coastguard Worker  *
472*0e209d39SAndroid Build Coastguard Worker  * @param path input: "CollationElements/Sequence" or "zoneStrings/3/2" etc.;
473*0e209d39SAndroid Build Coastguard Worker  *             output: points to the part that has not yet been processed
474*0e209d39SAndroid Build Coastguard Worker  */
475*0e209d39SAndroid Build Coastguard Worker U_CFUNC Resource res_findResource(const ResourceData *pResData, Resource r,
476*0e209d39SAndroid Build Coastguard Worker                                   char** path, const char** key);
477*0e209d39SAndroid Build Coastguard Worker 
478*0e209d39SAndroid Build Coastguard Worker #ifdef __cplusplus
479*0e209d39SAndroid Build Coastguard Worker 
480*0e209d39SAndroid Build Coastguard Worker #include "resource.h"
481*0e209d39SAndroid Build Coastguard Worker #include "restrace.h"
482*0e209d39SAndroid Build Coastguard Worker 
483*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
484*0e209d39SAndroid Build Coastguard Worker 
res_getString(const ResourceTracer & traceInfo,const ResourceData * pResData,Resource res,int32_t * pLength)485*0e209d39SAndroid Build Coastguard Worker inline const char16_t* res_getString(const ResourceTracer& traceInfo,
486*0e209d39SAndroid Build Coastguard Worker         const ResourceData *pResData, Resource res, int32_t *pLength) {
487*0e209d39SAndroid Build Coastguard Worker     traceInfo.trace("string");
488*0e209d39SAndroid Build Coastguard Worker     return res_getStringNoTrace(pResData, res, pLength);
489*0e209d39SAndroid Build Coastguard Worker }
490*0e209d39SAndroid Build Coastguard Worker 
res_getBinary(const ResourceTracer & traceInfo,const ResourceData * pResData,Resource res,int32_t * pLength)491*0e209d39SAndroid Build Coastguard Worker inline const uint8_t* res_getBinary(const ResourceTracer& traceInfo,
492*0e209d39SAndroid Build Coastguard Worker         const ResourceData *pResData, Resource res, int32_t *pLength) {
493*0e209d39SAndroid Build Coastguard Worker     traceInfo.trace("binary");
494*0e209d39SAndroid Build Coastguard Worker     return res_getBinaryNoTrace(pResData, res, pLength);
495*0e209d39SAndroid Build Coastguard Worker }
496*0e209d39SAndroid Build Coastguard Worker 
res_getIntVector(const ResourceTracer & traceInfo,const ResourceData * pResData,Resource res,int32_t * pLength)497*0e209d39SAndroid Build Coastguard Worker inline const int32_t* res_getIntVector(const ResourceTracer& traceInfo,
498*0e209d39SAndroid Build Coastguard Worker         const ResourceData *pResData, Resource res, int32_t *pLength) {
499*0e209d39SAndroid Build Coastguard Worker     traceInfo.trace("intvector");
500*0e209d39SAndroid Build Coastguard Worker     return res_getIntVectorNoTrace(pResData, res, pLength);
501*0e209d39SAndroid Build Coastguard Worker }
502*0e209d39SAndroid Build Coastguard Worker 
res_getInt(const ResourceTracer & traceInfo,Resource res)503*0e209d39SAndroid Build Coastguard Worker inline int32_t res_getInt(const ResourceTracer& traceInfo, Resource res) {
504*0e209d39SAndroid Build Coastguard Worker     traceInfo.trace("int");
505*0e209d39SAndroid Build Coastguard Worker     return RES_GET_INT_NO_TRACE(res);
506*0e209d39SAndroid Build Coastguard Worker }
507*0e209d39SAndroid Build Coastguard Worker 
res_getUInt(const ResourceTracer & traceInfo,Resource res)508*0e209d39SAndroid Build Coastguard Worker inline uint32_t res_getUInt(const ResourceTracer& traceInfo, Resource res) {
509*0e209d39SAndroid Build Coastguard Worker     traceInfo.trace("uint");
510*0e209d39SAndroid Build Coastguard Worker     return RES_GET_UINT_NO_TRACE(res);
511*0e209d39SAndroid Build Coastguard Worker }
512*0e209d39SAndroid Build Coastguard Worker 
513*0e209d39SAndroid Build Coastguard Worker class ResourceDataValue : public ResourceValue {
514*0e209d39SAndroid Build Coastguard Worker public:
ResourceDataValue()515*0e209d39SAndroid Build Coastguard Worker     ResourceDataValue() :
516*0e209d39SAndroid Build Coastguard Worker         pResData(nullptr),
517*0e209d39SAndroid Build Coastguard Worker         validLocaleDataEntry(nullptr),
518*0e209d39SAndroid Build Coastguard Worker         res(static_cast<Resource>(URES_NONE)),
519*0e209d39SAndroid Build Coastguard Worker         fTraceInfo() {}
520*0e209d39SAndroid Build Coastguard Worker     virtual ~ResourceDataValue();
521*0e209d39SAndroid Build Coastguard Worker 
setData(const ResourceData & data)522*0e209d39SAndroid Build Coastguard Worker     void setData(const ResourceData &data) {
523*0e209d39SAndroid Build Coastguard Worker         pResData = &data;
524*0e209d39SAndroid Build Coastguard Worker     }
525*0e209d39SAndroid Build Coastguard Worker 
setValidLocaleDataEntry(UResourceDataEntry * entry)526*0e209d39SAndroid Build Coastguard Worker     void setValidLocaleDataEntry(UResourceDataEntry *entry) {
527*0e209d39SAndroid Build Coastguard Worker         validLocaleDataEntry = entry;
528*0e209d39SAndroid Build Coastguard Worker     }
529*0e209d39SAndroid Build Coastguard Worker 
setResource(Resource r,ResourceTracer && traceInfo)530*0e209d39SAndroid Build Coastguard Worker     void setResource(Resource r, ResourceTracer&& traceInfo) {
531*0e209d39SAndroid Build Coastguard Worker         res = r;
532*0e209d39SAndroid Build Coastguard Worker         fTraceInfo = traceInfo;
533*0e209d39SAndroid Build Coastguard Worker     }
534*0e209d39SAndroid Build Coastguard Worker 
getData()535*0e209d39SAndroid Build Coastguard Worker     const ResourceData &getData() const { return *pResData; }
getValidLocaleDataEntry()536*0e209d39SAndroid Build Coastguard Worker     UResourceDataEntry *getValidLocaleDataEntry() const { return validLocaleDataEntry; }
getResource()537*0e209d39SAndroid Build Coastguard Worker     Resource getResource() const { return res; }
538*0e209d39SAndroid Build Coastguard Worker     virtual UResType getType() const override;
539*0e209d39SAndroid Build Coastguard Worker     virtual const char16_t *getString(int32_t &length, UErrorCode &errorCode) const override;
540*0e209d39SAndroid Build Coastguard Worker     virtual const char16_t *getAliasString(int32_t &length, UErrorCode &errorCode) const override;
541*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getInt(UErrorCode &errorCode) const override;
542*0e209d39SAndroid Build Coastguard Worker     virtual uint32_t getUInt(UErrorCode &errorCode) const override;
543*0e209d39SAndroid Build Coastguard Worker     virtual const int32_t *getIntVector(int32_t &length, UErrorCode &errorCode) const override;
544*0e209d39SAndroid Build Coastguard Worker     virtual const uint8_t *getBinary(int32_t &length, UErrorCode &errorCode) const override;
545*0e209d39SAndroid Build Coastguard Worker     virtual ResourceArray getArray(UErrorCode &errorCode) const override;
546*0e209d39SAndroid Build Coastguard Worker     virtual ResourceTable getTable(UErrorCode &errorCode) const override;
547*0e209d39SAndroid Build Coastguard Worker     virtual UBool isNoInheritanceMarker() const override;
548*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getStringArray(UnicodeString *dest, int32_t capacity,
549*0e209d39SAndroid Build Coastguard Worker                                    UErrorCode &errorCode) const override;
550*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getStringArrayOrStringAsArray(UnicodeString *dest, int32_t capacity,
551*0e209d39SAndroid Build Coastguard Worker                                                   UErrorCode &errorCode) const override;
552*0e209d39SAndroid Build Coastguard Worker     virtual UnicodeString getStringOrFirstOfArray(UErrorCode &errorCode) const override;
553*0e209d39SAndroid Build Coastguard Worker 
554*0e209d39SAndroid Build Coastguard Worker private:
555*0e209d39SAndroid Build Coastguard Worker     const ResourceData *pResData;
556*0e209d39SAndroid Build Coastguard Worker     UResourceDataEntry *validLocaleDataEntry;
557*0e209d39SAndroid Build Coastguard Worker     Resource res;
558*0e209d39SAndroid Build Coastguard Worker     ResourceTracer fTraceInfo;
559*0e209d39SAndroid Build Coastguard Worker };
560*0e209d39SAndroid Build Coastguard Worker 
561*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
562*0e209d39SAndroid Build Coastguard Worker 
563*0e209d39SAndroid Build Coastguard Worker #endif  /* __cplusplus */
564*0e209d39SAndroid Build Coastguard Worker 
565*0e209d39SAndroid Build Coastguard Worker /**
566*0e209d39SAndroid Build Coastguard Worker  * Swap an ICU resource bundle. See udataswp.h.
567*0e209d39SAndroid Build Coastguard Worker  * @internal
568*0e209d39SAndroid Build Coastguard Worker  */
569*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
570*0e209d39SAndroid Build Coastguard Worker ures_swap(const UDataSwapper *ds,
571*0e209d39SAndroid Build Coastguard Worker           const void *inData, int32_t length, void *outData,
572*0e209d39SAndroid Build Coastguard Worker           UErrorCode *pErrorCode);
573*0e209d39SAndroid Build Coastguard Worker 
574*0e209d39SAndroid Build Coastguard Worker #endif
575