Lines Matching full:bundle
30 * Align binary data at a 16-byte offset from the start of the resource bundle,
53 * for use in non-error cases when no resource is to be added to the bundle.
101 bundle_compactStrings(struct SRBRoot *bundle, UErrorCode *status);
110 res_write16(struct SRBRoot *bundle, struct SResource *res,
124 * before actually writing the bundle contents to the file,
129 struct SRBRoot *bundle, struct SResource *res,
139 struct SRBRoot *bundle, struct SResource *res,
143 reserve16BitUnits(struct SRBRoot *bundle, int32_t length, UErrorCode *status) {
147 if ((bundle->f16BitUnitsLength + length) > bundle->f16BitUnitsCapacity) {
149 int32_t capacity = 2 * bundle->f16BitUnitsCapacity + length + 1024;
156 if (bundle->f16BitUnitsLength > 0) {
157 uprv_memcpy(newUnits, bundle->f16BitUnits, bundle->f16BitUnitsLength * 2);
160 bundle->f16BitUnitsLength = 1;
162 uprv_free(bundle->f16BitUnits);
163 bundle->f16BitUnits = newUnits;
164 bundle->f16BitUnitsCapacity = capacity;
166 return bundle->f16BitUnits + bundle->f16BitUnitsLength;
184 mapKey(struct SRBRoot *bundle, int32_t oldpos) {
185 const KeyMapEntry *map = bundle->fKeyMap;
189 start = bundle->fPoolBundleKeysCount;
190 limit = start + bundle->fKeysCount;
204 makeKey16(struct SRBRoot *bundle, int32_t key) {
208 return (uint16_t)(key + bundle->fLocalKeyLimit); /* offset in the pool bundle */
218 string_write16(struct SRBRoot *bundle, struct SResource *res, UErrorCode *status) {
224 string_write16(bundle, same, status);
232 array_write16(struct SRBRoot *bundle, struct SResource *res,
246 res_write16(bundle, current, status);
250 uint16_t *p16 = reserve16BitUnits(bundle, 1 + res->u.fArray.fCount, status);
252 res->fRes = URES_MAKE_RESOURCE(URES_ARRAY16, bundle->f16BitUnitsLength);
257 bundle->f16BitUnitsLength += 1 + res->u.fArray.fCount;
264 table_write16(struct SRBRoot *bundle, struct SResource *res,
282 res_write16(bundle, current, status);
283 if (bundle->fKeyMap == NULL) {
286 key = current->fKey = mapKey(bundle, current->fKey);
304 if(res->u.fTable.fCount > (uint32_t)bundle->fMaxTableLength) {
305 bundle->fMaxTableLength = res->u.fTable.fCount;
309 (!hasLocalKeys || maxKey < bundle->fLocalKeyLimit) &&
310 (!hasPoolKeys || maxPoolKey < (0x10000 - bundle->fLocalKeyLimit))
313 uint16_t *p16 = reserve16BitUnits(bundle, 1 + res->u.fTable.fCount * 2, status);
316 res->fRes = URES_MAKE_RESOURCE(URES_TABLE16, bundle->f16BitUnitsLength);
319 *p16++ = makeKey16(bundle, current->fKey);
324 bundle->f16BitUnitsLength += 1 + res->u.fTable.fCount * 2;
338 res_write16(struct SRBRoot *bundle, struct SResource *res,
354 string_write16(bundle, res, status);
357 array_write16(bundle, res, status);
360 table_write16(bundle, res, status);
375 struct SRBRoot *bundle, struct SResource *res,
384 struct SRBRoot *bundle, struct SResource *res,
399 struct SRBRoot *bundle, struct SResource *res,
407 res_preWrite(byteOffset, bundle, current, status);
415 struct SRBRoot *bundle, struct SResource *res,
423 res_preWrite(byteOffset, bundle, current, status);
438 struct SRBRoot *bundle, struct SResource *res,
454 string_preWrite(byteOffset, bundle, res, status);
470 bin_preWrite(byteOffset, bundle, res, status);
475 array_preWrite(byteOffset, bundle, res, status);
478 table_preWrite(byteOffset, bundle, res, status);
492 struct SRBRoot *bundle, struct SResource *res,
503 struct SRBRoot *bundle, struct SResource *res,
512 struct SRBRoot *bundle, struct SResource *res,
522 res_write(mem, byteOffset, bundle, current, status);
534 struct SRBRoot *bundle, struct SResource *res,
545 struct SRBRoot *bundle, struct SResource *res,
564 struct SRBRoot *bundle, struct SResource *res,
574 res_write(mem, byteOffset, bundle, current, status);
581 udata_write16(mem, makeKey16(bundle, current->fKey));
603 struct SRBRoot *bundle, struct SResource *res,
616 string_write (mem, byteOffset, bundle, res, status);
619 alias_write (mem, byteOffset, bundle, res, status);
622 intvector_write (mem, byteOffset, bundle, res, status);
625 bin_write (mem, byteOffset, bundle, res, status);
630 array_write (mem, byteOffset, bundle, res, status);
633 table_write (mem, byteOffset, bundle, res, status);
647 void bundle_write(struct SRBRoot *bundle,
657 bundle_compactKeys(bundle, status);
662 while (bundle->fKeysTop & 3) {
663 bundle->fKeys[bundle->fKeysTop++] = (char)0xaa;
673 if (bundle->fKeysBottom < bundle->fKeysTop) {
674 if (bundle->fKeysTop <= 0x10000) {
675 bundle->fLocalKeyLimit = bundle->fKeysTop;
677 bundle->fLocalKeyLimit = 0x10000;
680 bundle->fLocalKeyLimit = 0;
683 bundle_compactStrings(bundle, status);
684 res_write16(bundle, bundle->fRoot, status);
685 if (bundle->f16BitUnitsLength & 1) {
686 bundle->f16BitUnits[bundle->f16BitUnitsLength++] = 0xaaaa; /* pad to multiple of 4 bytes */
689 uprv_free(bundle->fKeyMap);
690 bundle->fKeyMap = NULL;
692 byteOffset = bundle->fKeysTop + bundle->f16BitUnitsLength * 2;
693 res_preWrite(&byteOffset, bundle, bundle->fRoot, status);
728 len = (int32_t)uprv_strlen(bundle->fLocale);
732 uprv_strncpy(writtenFilename + off, bundle->fLocale, len);
749 uprv_strcat(dataName, bundle->fLocale);
753 uprv_strcpy(dataName, bundle->fLocale);
764 udata_write32(mem, bundle->fRoot->fRes);
772 indexes[URES_INDEX_LENGTH]= bundle->fIndexLength;
773 indexes[URES_INDEX_KEYS_TOP]= bundle->fKeysTop>>2;
776 indexes[URES_INDEX_MAX_TABLE_LENGTH]= bundle->fMaxTableLength;
783 if (bundle->noFallback) {
788 * more compact string value storage, optional pool bundle
790 if (URES_INDEX_16BIT_TOP < bundle->fIndexLength) {
791 indexes[URES_INDEX_16BIT_TOP] = (bundle->fKeysTop>>2) + (bundle->f16BitUnitsLength>>1);
793 if (URES_INDEX_POOL_CHECKSUM < bundle->fIndexLength) {
794 if (bundle->fIsPoolBundle) {
797 (int32_t)computeCRC((char *)(bundle->fKeys + bundle->fKeysBottom),
798 (uint32_t)(bundle->fKeysTop - bundle->fKeysBottom),
802 indexes[URES_INDEX_POOL_CHECKSUM] = bundle->fPoolChecksum;
807 udata_writeBlock(mem, indexes, bundle->fIndexLength*4);
810 udata_writeBlock(mem, bundle->fKeys+bundle->fKeysBottom,
811 bundle->fKeysTop-bundle->fKeysBottom);
814 udata_writeBlock(mem, bundle->f16BitUnits, bundle->f16BitUnitsLength*2);
816 /* write all of the bundle contents: the root item and its children */
817 byteOffset = bundle->fKeysTop + bundle->f16BitUnitsLength * 2;
818 res_write(mem, &byteOffset, bundle, bundle->fRoot, status);
832 struct SResource* res_open(struct SRBRoot *bundle, const char *tag,
835 struct SResource* res_open(struct SRBRoot *bundle, const char *tag,
838 int32_t key = bundle_addtag(bundle, tag, status);
867 struct SResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
868 struct SResource *res = res_open(bundle, tag, comment, status);
873 res->u.fTable.fRoot = bundle;
877 struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
878 struct SResource *res = res_open(bundle, tag, comment, status);
901 struct SResource *string_open(struct SRBRoot *bundle, char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) {
902 struct SResource *res = res_open(bundle, tag, comment, status);
920 if (bundle->fStringSet == NULL) {
922 bundle->fStringSet = uhash_open(string_hash, string_comp, string_comp, &localStatus);
924 res->u.fString.fSame = uhash_get(bundle->fStringSet, res);
939 if (bundle->fStringSet != NULL) {
941 uhash_put(bundle->fStringSet, res, res, status);
944 if (bundle->fStringsForm != STRINGS_UTF16_V1) {
958 bundle->f16BitUnitsLength += res->u.fString.fNumCharsForLength + len + 1; /* +1 for the NUL */
969 struct SResource *alias_open(struct SRBRoot *bundle
970 struct SResource *res = res_open(bundle, tag, comment, status);
994 struct SResource* intvector_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
995 struct SResource *res = res_open(bundle, tag, comment, status);
1011 struct SResource *int_open(struct SRBRoot *bundle, char *tag, int32_t value, const struct UString* comment, UErrorCode *status) {
1012 struct SResource *res = res_open(bundle, tag, comment, status);
1023 struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status) {
1024 struct SResource *res = res_open(bundle, tag, comment, status);
1059 struct SRBRoot *bundle;
1065 bundle = (struct SRBRoot *) uprv_malloc(sizeof(struct SRBRoot));
1066 if (bundle == NULL) {
1070 uprv_memset(bundle, 0, sizeof(struct SRBRoot));
1072 bundle->fKeys = (char *) uprv_malloc(sizeof(char) * KEY_SPACE_SIZE);
1073 bundle->fRoot = table_open(bundle, NULL, comment, status);
1074 if (bundle->fKeys == NULL || bundle->fRoot == NULL || U_FAILURE(*status)) {
1078 bundle_close(bundle, status);
1082 bundle->fLocale = NULL;
1083 bundle->fKeysCapacity = KEY_SPACE_SIZE;
1085 bundle->fIsPoolBundle = isPoolBundle;
1087 bundle->fIndexLength = URES_INDEX_POOL_CHECKSUM + 1;
1089 bundle->fIndexLength = URES_INDEX_16BIT_TOP + 1;
1091 bundle->fIndexLength = URES_INDEX_ATTRIBUTES + 1;
1093 bundle->fKeysBottom = (1 /* root */ + bundle->fIndexLength) * 4;
1094 uprv_memset(bundle->fKeys, 0, bundle->fKeysBottom);
1095 bundle->fKeysTop = bundle->fKeysBottom;
1098 bundle->fStringsForm = STRINGS_UTF16_V1;
1100 bundle->fStringsForm = STRINGS_UTF16_V2;
1103 return bundle;
1210 void bundle_close(struct SRBRoot *bundle, UErrorCode *status) {
1211 res_close(bundle->fRoot);
1212 uprv_free(bundle->fLocale);
1213 uprv_free(bundle->fKeys);
1214 uprv_free(bundle->fKeyMap);
1215 uhash_close(bundle->fStringSet);
1216 uprv_free(bundle->f16BitUnits);
1217 uprv_free(bundle);
1220 void bundle_closeString(struct SRBRoot *bundle, struct SResource *string) {
1221 if (bundle->fStringSet != NULL) {
1222 uhash_remove(bundle->fStringSet, string);
1326 void bundle_setlocale(struct SRBRoot *bundle, UChar *locale, UErrorCode *status) {
1332 if (bundle->fLocale!=NULL) {
1333 uprv_free(bundle->fLocale);
1336 bundle->fLocale= (char*) uprv_malloc(sizeof(char) * (u_strlen(locale)+1));
1338 if(bundle->fLocale == NULL) {
1343 /*u_strcpy(bundle->fLocale, locale);*/
1344 u_UCharsToChars(locale, bundle->fLocale, u_strlen(locale)+1);
1349 getKeyString(const struct SRBRoot *bundle, int32_t key) {
1351 return bundle->fPoolBundleKeys + (key & 0x7fffffff);
1353 return bundle->fKeys + key;
1358 res_getKeyString(const struct SRBRoot *bundle, const struct SResource *res, char temp[8]) {
1362 return getKeyString(bundle, res->fKey);
1366 bundle_getKeyBytes(struct SRBRoot *bundle, int32_t *pLength) {
1367 *pLength = bundle->fKeysTop - bundle->fKeysBottom;
1368 return bundle->fKeys + bundle->fKeysBottom;
1372 bundle_addKeyBytes(struct SRBRoot *bundle, const char *keyBytes, int32_t length, UErrorCode *status) {
1383 return bundle->fKeysTop;
1386 keypos = bundle->fKeysTop;
1387 bundle->fKeysTop += length;
1388 if (bundle->fKeysTop >= bundle->fKeysCapacity) {
1390 bundle->fKeysCapacity += KEY_SPACE_SIZE;
1391 bundle->fKeys = uprv_realloc(bundle->fKeys, bundle->fKeysCapacity);
1392 if(bundle->fKeys == NULL) {
1398 uprv_memcpy(bundle->fKeys + keypos, keyBytes, length);
1404 bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status) {
1416 keypos = bundle_addKeyBytes(bundle, tag, (int32_t)(uprv_strlen(tag) + 1), status);
1418 ++bundle->fKeysCount;
1440 const struct SRBRoot *bundle=(const struct SRBRoot *)context;
1443 const char *lStart = getKeyString(bundle, lPos);
1445 const char *rStart = getKeyString(bundle, rPos);
1462 /* Sort pool bundle keys first (negative oldpos), and otherwise keys in parsing order. */
1477 bundle_compactKeys(struct SRBRoot *bundle, UErrorCode *status) {
1481 int32_t keysCount = bundle->fPoolBundleKeysCount + bundle->fKeysCount;
1482 if (U_FAILURE(*status) || bundle->fKeysCount == 0 || bundle->fKeyMap != NULL) {
1490 keys = (char *)bundle->fPoolBundleKeys;
1491 for (i = 0; i < bundle->fPoolBundleKeysCount; ++i) {
1493 (int32_t)(keys - bundle->fPoolBundleKeys) | 0x80000000; /* negative oldpos */
1498 keys = bundle->fKeys + bundle->fKeysBottom;
1500 map[i].oldpos = (int32_t)(keys - bundle->fKeys);
1507 compareKeySuffixes, bundle, FALSE, status);
1513 keys = bundle->fKeys;
1525 /* Key string from the pool bundle, do not delete. */
1529 key = getKeyString(bundle, map[i].oldpos);
1563 oldpos = newpos = bundle->fKeysBottom;
1564 limit = bundle->fKeysTop;
1565 /* skip key offsets that point into the pool bundle rather than this new bundle */
1582 bundle->fKeysTop = newpos;
1588 bundle->fKeyMap = map;
1631 string_writeUTF16v2(struct SRBRoot *bundle, struct SResource *res, int32_t utf16Length) {
1639 bundle->f16BitUnits[utf16Length++] = (uint16_t)(0xdc00 + length);
1642 bundle->f16BitUnits[utf16Length] = (uint16_t)(0xdfef + (length >> 16));
1643 bundle->f16BitUnits[utf16Length + 1] = (uint16_t)length;
1647 bundle->f16BitUnits[utf16Length] = 0xdfff;
1648 bundle->f16BitUnits[utf16Length + 1] = (uint16_t)(length >> 16);
1649 bundle->f16BitUnits[utf16Length + 2] = (uint16_t)length;
1655 u_memcpy(bundle->f16BitUnits + utf16Length, res->u.fString.fChars, length + 1);
1660 bundle_compactStrings(struct SRBRoot *bundle, UErrorCode *status) {
1664 switch(bundle->fStringsForm) {
1666 if (bundle->f16BitUnitsLength > 0) {
1668 int32_t count = uhash_count(bundle->fStringSet);
1675 int32_t utf16Length = (bundle->f16BitUnitsLength + 20000) & ~1;
1676 bundle->f16BitUnits = (UChar *)uprv_malloc(utf16Length * U_SIZEOF_UCHAR);
1678 if (bundle->f16BitUnits == NULL || array == NULL) {
1679 uprv_free(bundle->f16BitUnits);
1680 bundle->f16BitUnits = NULL;
1685 bundle->f16BitUnitsCapacity = utf16Length;
1687 bundle->f16BitUnits[0] = 0;
1689 ++bundle->f16BitUnitsLength;
1691 array[i] = (struct SResource *)uhash_nextElement(bundle->fStringSet, &pos)->key.pointer;
1747 utf16Length = string_writeUTF16v2(bundle, array[i], utf16Length);
1758 assert(utf16Length <= bundle->f16BitUnitsLength);
1759 bundle->f16BitUnitsLength = utf16Length;