OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * * | 3 * Copyright (C) 1999-2015, International Business Machines |
4 * Copyright (C) 1999-2012, International Business Machines * | 4 * Corporation and others. All Rights Reserved. |
5 * Corporation and others. All Rights Reserved. * | |
6 * * | |
7 ****************************************************************************** | 5 ****************************************************************************** |
8 * file name: uresdata.h | 6 * file name: uresdata.h |
9 * encoding: US-ASCII | 7 * encoding: US-ASCII |
10 * tab size: 8 (not used) | 8 * tab size: 8 (not used) |
11 * indentation:4 | 9 * indentation:4 |
12 * | 10 * |
13 * created on: 1999dec08 | 11 * created on: 1999dec08 |
14 * created by: Markus W. Scherer | 12 * created by: Markus W. Scherer |
15 * 06/24/02 weiv Added support for resource sharing | 13 * 06/24/02 weiv Added support for resource sharing |
16 */ | 14 */ |
(...skipping 27 matching lines...) Expand all Loading... |
44 URES_TABLE16=5, | 42 URES_TABLE16=5, |
45 | 43 |
46 /** Resource type constant for 16-bit Unicode strings in formatVersion 2. */ | 44 /** Resource type constant for 16-bit Unicode strings in formatVersion 2. */ |
47 URES_STRING_V2=6, | 45 URES_STRING_V2=6, |
48 | 46 |
49 /** | 47 /** |
50 * Resource type constant for arrays with 16-bit count and values. | 48 * Resource type constant for arrays with 16-bit count and values. |
51 * All values are URES_STRING_V2 strings. | 49 * All values are URES_STRING_V2 strings. |
52 */ | 50 */ |
53 URES_ARRAY16=9 | 51 URES_ARRAY16=9 |
| 52 |
| 53 /* Resource type 15 is not defined but effectively used by RES_BOGUS=0xfffff
fff. */ |
54 } UResInternalType; | 54 } UResInternalType; |
55 | 55 |
56 /* | 56 /* |
57 * A Resource is a 32-bit value that has 2 bit fields: | 57 * A Resource is a 32-bit value that has 2 bit fields: |
58 * 31..28 4-bit type, see enum below | 58 * 31..28 4-bit type, see enum below |
59 * 27..0 28-bit four-byte-offset or value according to the type | 59 * 27..0 28-bit four-byte-offset or value according to the type |
60 */ | 60 */ |
61 typedef uint32_t Resource; | 61 typedef uint32_t Resource; |
62 | 62 |
63 #define RES_BOGUS 0xffffffff | 63 #define RES_BOGUS 0xffffffff |
| 64 #define RES_MAX_OFFSET 0x0fffffff |
64 | 65 |
65 #define RES_GET_TYPE(res) ((int32_t)((res)>>28UL)) | 66 #define RES_GET_TYPE(res) ((int32_t)((res)>>28UL)) |
66 #define RES_GET_OFFSET(res) ((res)&0x0fffffff) | 67 #define RES_GET_OFFSET(res) ((res)&0x0fffffff) |
67 #define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res)) | 68 #define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res)) |
68 | 69 |
69 /* get signed and unsigned integer values directly from the Resource handle */ | 70 /* get signed and unsigned integer values directly from the Resource handle */ |
70 #if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC | 71 #if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC |
71 # define RES_GET_INT(res) (((int32_t)((res)<<4L))>>4L) | 72 # define RES_GET_INT(res) (((int32_t)((res)<<4L))>>4L) |
72 #else | 73 #else |
73 # define RES_GET_INT(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (r
es)&0x07ffffff) | 74 # define RES_GET_INT(res) (int32_t)(((res)&0x08000000) ? (res)|0xf0000000 : (r
es)&0x07ffffff) |
74 #endif | 75 #endif |
75 | 76 |
76 #define RES_GET_UINT(res) ((res)&0x0fffffff) | 77 #define RES_GET_UINT(res) ((res)&0x0fffffff) |
77 | 78 |
78 #define URES_IS_ARRAY(type) ((int32_t)(type)==URES_ARRAY || (int32_t)(type)==URE
S_ARRAY16) | 79 #define URES_IS_ARRAY(type) ((int32_t)(type)==URES_ARRAY || (int32_t)(type)==URE
S_ARRAY16) |
79 #define URES_IS_TABLE(type) ((int32_t)(type)==URES_TABLE || (int32_t)(type)==URE
S_TABLE16 || (int32_t)(type)==URES_TABLE32) | 80 #define URES_IS_TABLE(type) ((int32_t)(type)==URES_TABLE || (int32_t)(type)==URE
S_TABLE16 || (int32_t)(type)==URES_TABLE32) |
80 #define URES_IS_CONTAINER(type) (URES_IS_TABLE(type) || URES_IS_ARRAY(type)) | 81 #define URES_IS_CONTAINER(type) (URES_IS_TABLE(type) || URES_IS_ARRAY(type)) |
81 | 82 |
82 #define URES_MAKE_RESOURCE(type, offset) (((Resource)(type)<<28)|(Resource)(offs
et)) | 83 #define URES_MAKE_RESOURCE(type, offset) (((Resource)(type)<<28)|(Resource)(offs
et)) |
83 #define URES_MAKE_EMPTY_RESOURCE(type) ((Resource)(type)<<28) | 84 #define URES_MAKE_EMPTY_RESOURCE(type) ((Resource)(type)<<28) |
84 | 85 |
85 /* indexes[] value names; indexes are generally 32-bit (Resource) indexes */ | 86 /* indexes[] value names; indexes are generally 32-bit (Resource) indexes */ |
86 enum { | 87 enum { |
87 URES_INDEX_LENGTH, /* [0] contains URES_INDEX_TOP==the length of in
dexes[]; | 88 /** |
88 * formatVersion==1: all bits contain the le
ngth of indexes[] | 89 * [0] contains the length of indexes[] |
89 * but the length is much less than 0xff; | 90 * which is at most URES_INDEX_TOP of the latest format version |
90 * formatVersion>1: | 91 * |
91 * only bits 7..0 contain the length of i
ndexes[], | 92 * formatVersion==1: all bits contain the length of indexes[] |
92 * bits 31..8 are reserved and set to
0 */ | 93 * but the length is much less than 0xff; |
93 URES_INDEX_KEYS_TOP, /* [1] contains the top of the key strings, */ | 94 * formatVersion>1: |
94 /* same as the bottom of resources or UTF-16
strings, rounded up */ | 95 * only bits 7..0 contain the length of indexes[], |
95 URES_INDEX_RESOURCES_TOP, /* [2] contains the top of all resources */ | 96 * bits 31..8 are reserved and set to 0 |
96 URES_INDEX_BUNDLE_TOP, /* [3] contains the top of the bundle, */ | 97 * formatVersion>=3: |
97 /* in case it were ever different from [2] *
/ | 98 * bits 31..8 poolStringIndexLimit bits 23..0 |
98 URES_INDEX_MAX_TABLE_LENGTH,/* [4] max. length of any table */ | 99 */ |
99 URES_INDEX_ATTRIBUTES, /* [5] attributes bit set, see URES_ATT_* (new i
n formatVersion 1.2) */ | 100 URES_INDEX_LENGTH, |
100 URES_INDEX_16BIT_TOP, /* [6] top of the 16-bit units (UTF-16 string v2
UChars, URES_TABLE16, URES_ARRAY16), | 101 /** |
101 * rounded up (new in formatVersion 2.0, ICU
4.4) */ | 102 * [1] contains the top of the key strings, |
102 URES_INDEX_POOL_CHECKSUM, /* [7] checksum of the pool bundle (new in forma
tVersion 2.0, ICU 4.4) */ | 103 * same as the bottom of resources or UTF-16 strings, rounded up |
| 104 */ |
| 105 URES_INDEX_KEYS_TOP, |
| 106 /** [2] contains the top of all resources */ |
| 107 URES_INDEX_RESOURCES_TOP, |
| 108 /** |
| 109 * [3] contains the top of the bundle, |
| 110 * in case it were ever different from [2] |
| 111 */ |
| 112 URES_INDEX_BUNDLE_TOP, |
| 113 /** [4] max. length of any table */ |
| 114 URES_INDEX_MAX_TABLE_LENGTH, |
| 115 /** |
| 116 * [5] attributes bit set, see URES_ATT_* (new in formatVersion 1.2) |
| 117 * |
| 118 * formatVersion>=3: |
| 119 * bits 31..16 poolStringIndex16Limit |
| 120 * bits 15..12 poolStringIndexLimit bits 27..24 |
| 121 */ |
| 122 URES_INDEX_ATTRIBUTES, |
| 123 /** |
| 124 * [6] top of the 16-bit units (UTF-16 string v2 UChars, URES_TABLE16, URES_
ARRAY16), |
| 125 * rounded up (new in formatVersion 2.0, ICU 4.4) |
| 126 */ |
| 127 URES_INDEX_16BIT_TOP, |
| 128 /** [7] checksum of the pool bundle (new in formatVersion 2.0, ICU 4.4) */ |
| 129 URES_INDEX_POOL_CHECKSUM, |
103 URES_INDEX_TOP | 130 URES_INDEX_TOP |
104 }; | 131 }; |
105 | 132 |
106 /* | 133 /* |
107 * Nofallback attribute, attribute bit 0 in indexes[URES_INDEX_ATTRIBUTES]. | 134 * Nofallback attribute, attribute bit 0 in indexes[URES_INDEX_ATTRIBUTES]. |
108 * New in formatVersion 1.2 (ICU 3.6). | 135 * New in formatVersion 1.2 (ICU 3.6). |
109 * | 136 * |
110 * If set, then this resource bundle is a standalone bundle. | 137 * If set, then this resource bundle is a standalone bundle. |
111 * If not set, then the bundle participates in locale fallback, eventually | 138 * If not set, then the bundle participates in locale fallback, eventually |
112 * all the way to the root bundle. | 139 * all the way to the root bundle. |
113 * If indexes[] is missing or too short, then the attribute cannot be determined | 140 * If indexes[] is missing or too short, then the attribute cannot be determined |
114 * reliably. Dependency checking should ignore such bundles, and loading should | 141 * reliably. Dependency checking should ignore such bundles, and loading should |
115 * use fallbacks. | 142 * use fallbacks. |
116 */ | 143 */ |
117 #define URES_ATT_NO_FALLBACK 1 | 144 #define URES_ATT_NO_FALLBACK 1 |
118 | 145 |
119 /* | 146 /* |
120 * Attributes for bundles that are, or use, a pool bundle. | 147 * Attributes for bundles that are, or use, a pool bundle. |
121 * A pool bundle provides key strings that are shared among several other bundle
s | 148 * A pool bundle provides key strings that are shared among several other bundle
s |
122 * to reduce their total size. | 149 * to reduce their total size. |
123 * New in formatVersion 2 (ICU 4.4). | 150 * New in formatVersion 2 (ICU 4.4). |
124 */ | 151 */ |
125 #define URES_ATT_IS_POOL_BUNDLE 2 | 152 #define URES_ATT_IS_POOL_BUNDLE 2 |
126 #define URES_ATT_USES_POOL_BUNDLE 4 | 153 #define URES_ATT_USES_POOL_BUNDLE 4 |
127 | 154 |
128 /* | 155 /* |
129 * File format for .res resource bundle files (formatVersion=2, ICU 4.4) | 156 * File format for .res resource bundle files |
130 * | 157 * |
131 * New in formatVersion 2 compared with 1.3: ------------- | 158 * ICU 56: New in formatVersion 3 compared with 2: ------------- |
| 159 * |
| 160 * Resource bundles can optionally use shared string-v2 values |
| 161 * stored in the pool bundle. |
| 162 * If so, then the indexes[] contain two new values |
| 163 * in previously-unused bits of existing indexes[] slots: |
| 164 * - poolStringIndexLimit: |
| 165 * String-v2 offsets (in 32-bit Resource words) below this limit |
| 166 * point to pool bundle string-v2 values. |
| 167 * - poolStringIndex16Limit: |
| 168 * Resource16 string-v2 offsets below this limit |
| 169 * point to pool bundle string-v2 values. |
| 170 * Guarantee: poolStringIndex16Limit <= poolStringIndexLimit |
| 171 * |
| 172 * The local bundle's poolStringIndexLimit is greater than |
| 173 * any pool bundle string index used in the local bundle. |
| 174 * The poolStringIndexLimit should not be greater than |
| 175 * the maximum possible pool bundle string index. |
| 176 * |
| 177 * The maximum possible pool bundle string index is the index to the last non-NU
L |
| 178 * pool string character, due to suffix sharing. |
| 179 * |
| 180 * In the pool bundle, there is no structure that lists the strings. |
| 181 * (The root resource is an empty Table.) |
| 182 * If the strings need to be enumerated (as genrb --usePoolBundle does), |
| 183 * then iterate through the pool bundle's 16-bit-units array from the beginning. |
| 184 * Stop at the end of the array, or when an explicit or implicit string length |
| 185 * would lead beyond the end of the array, |
| 186 * or when an apparent string is not NUL-terminated. |
| 187 * (Future genrb version might terminate the strings with |
| 188 * what looks like a large explicit string length.) |
| 189 * |
| 190 * ICU 4.4: New in formatVersion 2 compared with 1.3: ------------- |
132 * | 191 * |
133 * Three new resource types -- String-v2, Table16 and Array16 -- have their | 192 * Three new resource types -- String-v2, Table16 and Array16 -- have their |
134 * values stored in a new array of 16-bit units between the table key strings | 193 * values stored in a new array of 16-bit units between the table key strings |
135 * and the start of the other resources. | 194 * and the start of the other resources. |
136 * | 195 * |
137 * genrb eliminates duplicates among Unicode string-v2 values. | 196 * genrb eliminates duplicates among Unicode string-v2 values. |
138 * Multiple Unicode strings may use the same offset and string data, | 197 * Multiple Unicode strings may use the same offset and string data, |
139 * or a short string may point to the suffix of a longer string. ("Suffix sharin
g") | 198 * or a short string may point to the suffix of a longer string. ("Suffix sharin
g") |
140 * For example, one string "abc" may be reused for another string "bc" by pointi
ng | 199 * For example, one string "abc" may be reused for another string "bc" by pointi
ng |
141 * to the second character. (Short strings-v2 are NUL-terminated | 200 * to the second character. (Short strings-v2 are NUL-terminated |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 * | 322 * |
264 * Most resources have their values stored at four-byte offsets from the start | 323 * Most resources have their values stored at four-byte offsets from the start |
265 * of the resource data. These values are at least 4-aligned. | 324 * of the resource data. These values are at least 4-aligned. |
266 * Some resource values are stored directly in the offset field of the Resource
itself. | 325 * Some resource values are stored directly in the offset field of the Resource
itself. |
267 * See UResType in unicode/ures.h for enumeration constants for Resource types. | 326 * See UResType in unicode/ures.h for enumeration constants for Resource types. |
268 * | 327 * |
269 * Some resources have their values stored as sequences of 16-bit units, | 328 * Some resources have their values stored as sequences of 16-bit units, |
270 * at 2-byte offsets from the start of a contiguous 16-bit-unit array between | 329 * at 2-byte offsets from the start of a contiguous 16-bit-unit array between |
271 * the table key strings and the other resources. (new in formatVersion 2/ICU 4.
4) | 330 * the table key strings and the other resources. (new in formatVersion 2/ICU 4.
4) |
272 * At offset 0 of that array is a 16-bit zero value for empty 16-bit resources. | 331 * At offset 0 of that array is a 16-bit zero value for empty 16-bit resources. |
| 332 * |
273 * Resource16 values in Table16 and Array16 are 16-bit offsets to String-v2 | 333 * Resource16 values in Table16 and Array16 are 16-bit offsets to String-v2 |
274 * resources, with the offsets relative to the start of the 16-bit-units array. | 334 * resources, with the offsets relative to the start of the 16-bit-units array. |
| 335 * Starting with formatVersion 3/ICU 56, if offset<poolStringIndex16Limit |
| 336 * then use the pool bundle's 16-bit-units array, |
| 337 * otherwise subtract that limit and use the local 16-bit-units array. |
275 * | 338 * |
276 * Type Name Memory layout of values | 339 * Type Name Memory layout of values |
277 * (in parentheses: scalar, non-offset values) | 340 * (in parentheses: scalar, non-offset values) |
278 * | 341 * |
279 * 0 Unicode String: int32_t length, UChar[length], (UChar)0, (padding) | 342 * 0 Unicode String: int32_t length, UChar[length], (UChar)0, (padding) |
280 * or (empty string ("") if offset==0) | 343 * or (empty string ("") if offset==0) |
281 * 1 Binary: int32_t length, uint8_t[length], (padding) | 344 * 1 Binary: int32_t length, uint8_t[length], (padding) |
282 * - the start of the bytes is 16-aligned - | 345 * - the start of the bytes is 16-aligned - |
283 * 2 Table: uint16_t count, uint16_t keyStringOffsets[count], (uint1
6_t padding), Resource[count] | 346 * 2 Table: uint16_t count, uint16_t keyStringOffsets[count], (uint1
6_t padding), Resource[count] |
284 * 3 Alias: (physically same value layout as string, new in ICU 2.4) | 347 * 3 Alias: (physically same value layout as string, new in ICU 2.4) |
285 * 4 Table32: int32_t count, int32_t keyStringOffsets[count], Resource
[count] | 348 * 4 Table32: int32_t count, int32_t keyStringOffsets[count], Resource
[count] |
286 * (new in formatVersion 1.1/ICU 2.8) | 349 * (new in formatVersion 1.1/ICU 2.8) |
287 * 5 Table16: uint16_t count, uint16_t keyStringOffsets[count], Resour
ce16[count] | 350 * 5 Table16: uint16_t count, uint16_t keyStringOffsets[count], Resour
ce16[count] |
288 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) | 351 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) |
289 * 6 Unicode String-v2:UChar[length], (UChar)0; length determined by the first
UChar: | 352 * 6 Unicode String-v2:UChar[length], (UChar)0; length determined by the first
UChar: |
290 * - if first is not a trail surrogate, then the length is
implicit | 353 * - if first is not a trail surrogate, then the length is
implicit |
291 * and u_strlen() needs to be called | 354 * and u_strlen() needs to be called |
292 * - if first<0xdfef then length=first&0x3ff (and skip firs
t) | 355 * - if first<0xdfef then length=first&0x3ff (and skip firs
t) |
293 * - if first<0xdfff then length=((first-0xdfef)<<16) | sec
ond UChar | 356 * - if first<0xdfff then length=((first-0xdfef)<<16) | sec
ond UChar |
294 * - if first==0xdfff then length=((second UChar)<<16) | th
ird UChar | 357 * - if first==0xdfff then length=((second UChar)<<16) | th
ird UChar |
295 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) | 358 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) |
| 359 * |
| 360 * Starting with formatVersion 3/ICU 56, if offset<poolStri
ngIndexLimit |
| 361 * then use the pool bundle's 16-bit-units array, |
| 362 * otherwise subtract that limit and use the local 16-bit-u
nits array. |
| 363 * (Note different limits for Resource16 vs. Resource.) |
| 364 * |
296 * 7 Integer: (28-bit offset is integer value) | 365 * 7 Integer: (28-bit offset is integer value) |
297 * 8 Array: int32_t count, Resource[count] | 366 * 8 Array: int32_t count, Resource[count] |
298 * 9 Array16: uint16_t count, Resource16[count] | 367 * 9 Array16: uint16_t count, Resource16[count] |
299 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) | 368 * (stored in the 16-bit-units array; new in formatVersion
2/ICU 4.4) |
300 * 14 Integer Vector: int32_t length, int32_t[length] | 369 * 14 Integer Vector: int32_t length, int32_t[length] |
301 * 15 Reserved: This value denotes special purpose resources and is for
internal use. | 370 * 15 Reserved: This value denotes special purpose resources and is for
internal use. |
302 * | 371 * |
303 * Note that there are 3 types with data vector values: | 372 * Note that there are 3 types with data vector values: |
304 * - Vectors of 8-bit bytes stored as type Binary. | 373 * - Vectors of 8-bit bytes stored as type Binary. |
305 * - Vectors of 16-bit words stored as type Unicode String or Unicode String-v2 | 374 * - Vectors of 16-bit words stored as type Unicode String or Unicode String-v2 |
306 * (no value restrictions, all values 0..ffff allowed!). | 375 * (no value restrictions, all values 0..ffff allowed!). |
307 * - Vectors of 32-bit words stored as type Integer Vector. | 376 * - Vectors of 32-bit words stored as type Integer Vector. |
308 */ | 377 */ |
309 | 378 |
310 /* | 379 /* |
311 * Structure for a single, memory-mapped ResourceBundle. | 380 * Structure for a single, memory-mapped ResourceBundle. |
312 */ | 381 */ |
313 typedef struct { | 382 typedef struct { |
314 UDataMemory *data; | 383 UDataMemory *data; |
315 const int32_t *pRoot; | 384 const int32_t *pRoot; |
316 const uint16_t *p16BitUnits; | 385 const uint16_t *p16BitUnits; |
317 const char *poolBundleKeys; | 386 const char *poolBundleKeys; |
318 Resource rootRes; | 387 Resource rootRes; |
319 int32_t localKeyLimit; | 388 int32_t localKeyLimit; |
| 389 const uint16_t *poolBundleStrings; |
| 390 int32_t poolStringIndexLimit; |
| 391 int32_t poolStringIndex16Limit; |
320 UBool noFallback; /* see URES_ATT_NO_FALLBACK */ | 392 UBool noFallback; /* see URES_ATT_NO_FALLBACK */ |
321 UBool isPoolBundle; | 393 UBool isPoolBundle; |
322 UBool usesPoolBundle; | 394 UBool usesPoolBundle; |
323 UBool useNativeStrcmp; | 395 UBool useNativeStrcmp; |
324 } ResourceData; | 396 } ResourceData; |
325 | 397 |
326 /* | 398 /* |
327 * Read a resource bundle from memory. | 399 * Read a resource bundle from memory. |
328 */ | 400 */ |
329 U_INTERNAL void U_EXPORT2 | 401 U_INTERNAL void U_EXPORT2 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 /** | 462 /** |
391 * Swap an ICU resource bundle. See udataswp.h. | 463 * Swap an ICU resource bundle. See udataswp.h. |
392 * @internal | 464 * @internal |
393 */ | 465 */ |
394 U_CAPI int32_t U_EXPORT2 | 466 U_CAPI int32_t U_EXPORT2 |
395 ures_swap(const UDataSwapper *ds, | 467 ures_swap(const UDataSwapper *ds, |
396 const void *inData, int32_t length, void *outData, | 468 const void *inData, int32_t length, void *outData, |
397 UErrorCode *pErrorCode); | 469 UErrorCode *pErrorCode); |
398 | 470 |
399 #endif | 471 #endif |
OLD | NEW |