#ifndef UNISTR_FROM_CHAR_EXPLICIT
# define UNISTR_FROM_CHAR_EXPLICIT explicit
#endif
#ifndef UNISTR_FROM_STRING_EXPLICIT
# define UNISTR_FROM_STRING_EXPLICIT explicit
#endif
#include <assert.h>
#include <iostream>
#include <set>
#include <stdio.h>
#include "unicode/localpointer.h"
#include "reslist.h"
#include "unewdata.h"
#include "unicode/ures.h"
#include "unicode/putil.h"
#include "errmsg.h"
#include "filterrb.h"
#include "uarrsort.h"
#include "uelement.h"
#include "uhash.h"
#include "uinvchar.h"
#include "ustr_imp.h"
#include "unicode/utf16.h"
#include "uassert.h"
#define BIN_ALIGNMENT 16
#ifndef GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING
# define GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING 10
#endif
U_NAMESPACE_USE
static UBool gIncludeCopyright = FALSE;
static UBool gUsePoolBundle = FALSE;
static UBool gIsDefaultFormatVersion = TRUE;
static int32_t gFormatVersion = 3;
enum {
STRINGS_UTF16_V1,
STRINGS_UTF16_V2
};
static const int32_t MAX_IMPLICIT_STRING_LENGTH = 40;
static const ResFile kNoPoolBundle;
static SResource kNoResource;
static UDataInfo dataInfo= {
sizeof(UDataInfo),
0,
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
sizeof(UChar),
0,
{0x52, 0x65, 0x73, 0x42},
{1, 3, 0, 0},
{1, 4, 0, 0}
};
static const UVersionInfo gFormatVersions[4] = {
{ 0, 0, 0, 0 },
{ 1, 3, 0, 0 },
{ 2, 0, 0, 0 },
{ 3, 0, 0, 0 }
};
static uint8_t calcPadding(uint32_t size) {
return (uint8_t) ((size % sizeof(uint32_t)) ? (sizeof(uint32_t) - (size % sizeof(uint32_t))) : 0);
}
void setIncludeCopyright(UBool val){
gIncludeCopyright=val;
}
UBool getIncludeCopyright(void){
return gIncludeCopyright;
}
void setFormatVersion(int32_t formatVersion) {
gIsDefaultFormatVersion = FALSE;
gFormatVersion = formatVersion;
}
int32_t getFormatVersion() {
return gFormatVersion;
}
void setUsePoolBundle(UBool use) {
gUsePoolBundle = use;
}
struct SResource* res_none() {
return &kNoResource;
}
SResource::SResource()
: fType(URES_NONE), fWritten(FALSE), fRes(RES_BOGUS), fRes16(-1), fKey(-1), fKey16(-1),
line(0), fNext(NULL) {
ustr_init(&fComment);
}
SResource::SResource(SRBRoot *bundle, const char *tag, int8_t type, const UString* comment,
UErrorCode &errorCode)
: fType(type), fWritten(FALSE), fRes(RES_BOGUS), fRes16(-1),
fKey(bundle != NULL ? bundle->addTag(tag, errorCode) : -1), fKey16(-1),
line(0), fNext(NULL) {
ustr_init(&fComment);
if(comment != NULL) {
ustr_cpy(&fComment, comment, &errorCode);
}
}
SResource::~SResource() {
ustr_deinit(&fComment);
}
ContainerResource::~ContainerResource() {
SResource *current = fFirst;
while (current != NULL) {
SResource *next = current->fNext;
delete current;
current = next;
}
}
TableResource::~TableResource() {}
void TableResource::add(SResource *res, int linenumber, UErrorCode &errorCode) {
if (U_FAILURE(errorCode) || res == NULL || res == &kNoResource) {
return;
}
res->line = linenumber;
++fCount;
if (fFirst == NULL) {
fFirst = res;
res->fNext = NULL;
return;
}
const char *resKeyString = fRoot->fKeys + res->fKey;
SResource *current = fFirst;
SResource *prev = NULL;
while (current != NULL) {
const char *currentKeyString = fRoot->fKeys + current->fKey;
int diff;
if (gFormatVersion == 1 || U_CHARSET_FAMILY == U_ASCII_FAMILY) {
diff = uprv_strcmp(currentKeyString, resKeyString);
} else {
diff = uprv_compareInvCharsAsAscii(currentKeyString, resKeyString);
}
if (diff < 0) {
prev = current;
current = current->fNext;
} else if (diff > 0) {
if (prev == NULL) {
fFirst = res;
} else {
prev->fNext = res;
}
res->fNext = current;
return;
} else {
error(linenumber, "duplicate key '%s' in table, first appeared at line %d", currentKeyString, current->line);
errorCode = U_UNSUPPORTED_ERROR;
return;
}
}
prev->fNext = res;
res->fNext = NULL;
}
ArrayResource::~ArrayResource() {}
void ArrayResource::add(SResource *res) {
if (res != NULL && res != &kNoResource) {
if (fFirst == NULL) {
fFirst = res;
} else {
fLast->fNext = res;
}
fLast = res;
++fCount;
}
}
PseudoListResource::~PseudoListResource() {}
void PseudoListResource::add(SResource *res) {
if (res != NULL && res != &kNoResource) {
res->fNext = fFirst;
fFirst = res;
++fCount;
}
}
StringBaseResource::StringBaseResource(SRBRoot *bundle, const char *tag, int8_t type,
const UChar *value, int32_t len,
const UString* comment, UErrorCode &errorCode)
: SResource(bundle, tag, type, comment, errorCode) {
if (len == 0 && gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(type);
fWritten = TRUE;
return;
}
fString.setTo(ConstChar16Ptr(value), len);
fString.getTerminatedBuffer(); if (U_SUCCESS(errorCode) && fString.isBogus()) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
}
}
StringBaseResource::StringBaseResource(SRBRoot *bundle, int8_t type,
const icu::UnicodeString &value, UErrorCode &errorCode)
: SResource(bundle, NULL, type, NULL, errorCode), fString(value) {
if (value.isEmpty() && gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(type);
fWritten = TRUE;
return;
}
fString.getTerminatedBuffer(); if (U_SUCCESS(errorCode) && fString.isBogus()) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
}
}
StringBaseResource::StringBaseResource(int8_t type, const UChar *value, int32_t len,
UErrorCode &errorCode)
: SResource(NULL, NULL, type, NULL, errorCode), fString(TRUE, value, len) {
assert(len > 0);
assert(!fString.isBogus());
}
StringBaseResource::~StringBaseResource() {}
static int32_t U_CALLCONV
string_hash(const UElement key) {
const StringResource *res = static_cast<const StringResource *>(key.pointer);
return res->fString.hashCode();
}
static UBool U_CALLCONV
string_comp(const UElement key1, const UElement key2) {
const StringResource *res1 = static_cast<const StringResource *>(key1.pointer);
const StringResource *res2 = static_cast<const StringResource *>(key2.pointer);
return res1->fString == res2->fString;
}
StringResource::~StringResource() {}
AliasResource::~AliasResource() {}
IntResource::IntResource(SRBRoot *bundle, const char *tag, int32_t value,
const UString* comment, UErrorCode &errorCode)
: SResource(bundle, tag, URES_INT, comment, errorCode) {
fValue = value;
fRes = URES_MAKE_RESOURCE(URES_INT, value & RES_MAX_OFFSET);
fWritten = TRUE;
}
IntResource::~IntResource() {}
IntVectorResource::IntVectorResource(SRBRoot *bundle, const char *tag,
const UString* comment, UErrorCode &errorCode)
: SResource(bundle, tag, URES_INT_VECTOR, comment, errorCode),
fCount(0), fArray(new uint32_t[RESLIST_MAX_INT_VECTOR]) {
if (fArray == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
IntVectorResource::~IntVectorResource() {
delete[] fArray;
}
void IntVectorResource::add(int32_t value, UErrorCode &errorCode) {
if (U_SUCCESS(errorCode)) {
fArray[fCount++] = value;
}
}
BinaryResource::BinaryResource(SRBRoot *bundle, const char *tag,
uint32_t length, uint8_t *data, const char* fileName,
const UString* comment, UErrorCode &errorCode)
: SResource(bundle, tag, URES_BINARY, comment, errorCode),
fLength(length), fData(NULL), fFileName(NULL) {
if (U_FAILURE(errorCode)) {
return;
}
if (fileName != NULL && *fileName != 0){
fFileName = new char[uprv_strlen(fileName)+1];
if (fFileName == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_strcpy(fFileName, fileName);
}
if (length > 0) {
fData = new uint8_t[length];
if (fData == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_memcpy(fData, data, length);
} else {
if (gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(URES_BINARY);
fWritten = TRUE;
}
}
}
BinaryResource::~BinaryResource() {
delete[] fData;
delete[] fFileName;
}
void
StringResource::handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet,
UErrorCode &errorCode) {
assert(fSame == NULL);
fSame = static_cast<StringResource *>(uhash_get(stringSet, this));
if (fSame != NULL) {
if (++fSame->fNumCopies == 1) {
assert(fSame->fWritten);
int32_t poolStringIndex = (int32_t)RES_GET_OFFSET(fSame->fRes);
if (poolStringIndex >= bundle->fPoolStringIndexLimit) {
bundle->fPoolStringIndexLimit = poolStringIndex + 1;
}
}
return;
}
fNumCopies = 1;
uhash_put(stringSet, this, this, &errorCode);
if (bundle->fStringsForm != STRINGS_UTF16_V1) {
int32_t len = length();
if (len <= MAX_IMPLICIT_STRING_LENGTH &&
!U16_IS_TRAIL(fString[0]) && fString.indexOf((UChar)0) < 0) {
fNumCharsForLength = 0;
} else if (len <= 0x3ee) {
fNumCharsForLength = 1;
} else if (len <= 0xfffff) {
fNumCharsForLength = 2;
} else {
fNumCharsForLength = 3;
}
bundle->f16BitStringsLength += fNumCharsForLength + len + 1;
}
}
void
ContainerResource::handlePreflightStrings(SRBRoot *bundle, UHashtable *stringSet,
UErrorCode &errorCode) {
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
current->preflightStrings(bundle, stringSet, errorCode);
}
}
void
SResource::preflightStrings(SRBRoot *bundle, UHashtable *stringSet, UErrorCode &errorCode) {
if (U_FAILURE(errorCode)) {
return;
}
if (fRes != RES_BOGUS) {
return;
}
handlePreflightStrings(bundle, stringSet, errorCode);
}
void
SResource::handlePreflightStrings(SRBRoot * , UHashtable * ,
UErrorCode & ) {
}
int32_t
SRBRoot::makeRes16(uint32_t resWord) const {
if (resWord == 0) {
return 0;
}
uint32_t type = RES_GET_TYPE(resWord);
int32_t offset = (int32_t)RES_GET_OFFSET(resWord);
if (type == URES_STRING_V2) {
assert(offset > 0);
if (offset < fPoolStringIndexLimit) {
if (offset < fPoolStringIndex16Limit) {
return offset;
}
} else {
offset = offset - fPoolStringIndexLimit + fPoolStringIndex16Limit;
if (offset <= 0xffff) {
return offset;
}
}
}
return -1;
}
int32_t
SRBRoot::mapKey(int32_t oldpos) const {
const KeyMapEntry *map = fKeyMap;
if (map == NULL) {
return oldpos;
}
int32_t i, start, limit;
start = fUsePoolBundle->fKeysCount;
limit = start + fKeysCount;
while (start < limit - 1) {
i = (start + limit) / 2;
if (oldpos < map[i].oldpos) {
limit = i;
} else {
start = i;
}
}
assert(oldpos == map[start].oldpos);
return map[start].newpos;
}
void
StringResource::handleWrite16(SRBRoot * ) {
SResource *same;
if ((same = fSame) != NULL) {
assert(same->fRes != RES_BOGUS && same->fWritten);
fRes = same->fRes;
fWritten = same->fWritten;
}
}
void
ContainerResource::writeAllRes16(SRBRoot *bundle) {
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
bundle->f16BitUnits.append((UChar)current->fRes16);
}
fWritten = TRUE;
}
void
ArrayResource::handleWrite16(SRBRoot *bundle) {
if (fCount == 0 && gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(URES_ARRAY);
fWritten = TRUE;
return;
}
int32_t res16 = 0;
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
current->write16(bundle);
res16 |= current->fRes16;
}
if (fCount <= 0xffff && res16 >= 0 && gFormatVersion > 1) {
fRes = URES_MAKE_RESOURCE(URES_ARRAY16, bundle->f16BitUnits.length());
bundle->f16BitUnits.append((UChar)fCount);
writeAllRes16(bundle);
}
}
void
TableResource::handleWrite16(SRBRoot *bundle) {
if (fCount == 0 && gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(URES_TABLE);
fWritten = TRUE;
return;
}
int32_t key16 = 0;
int32_t res16 = 0;
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
current->write16(bundle);
key16 |= current->fKey16;
res16 |= current->fRes16;
}
if(fCount > (uint32_t)bundle->fMaxTableLength) {
bundle->fMaxTableLength = fCount;
}
if (fCount <= 0xffff && key16 >= 0) {
if (res16 >= 0 && gFormatVersion > 1) {
fRes = URES_MAKE_RESOURCE(URES_TABLE16, bundle->f16BitUnits.length());
bundle->f16BitUnits.append((UChar)fCount);
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
bundle->f16BitUnits.append((UChar)current->fKey16);
}
writeAllRes16(bundle);
} else {
fTableType = URES_TABLE;
}
} else {
fTableType = URES_TABLE32;
}
}
void
PseudoListResource::handleWrite16(SRBRoot * ) {
fRes = URES_MAKE_EMPTY_RESOURCE(URES_TABLE);
fWritten = TRUE;
}
void
SResource::write16(SRBRoot *bundle) {
if (fKey >= 0) {
fKey = bundle->mapKey(fKey);
if (fKey >= 0) {
if (fKey < bundle->fLocalKeyLimit) {
fKey16 = fKey;
}
} else {
int32_t poolKeyIndex = fKey & 0x7fffffff;
if (poolKeyIndex <= 0xffff) {
poolKeyIndex += bundle->fLocalKeyLimit;
if (poolKeyIndex <= 0xffff) {
fKey16 = poolKeyIndex;
}
}
}
}
if (fRes == RES_BOGUS) {
handleWrite16(bundle);
}
fRes16 = bundle->makeRes16(fRes);
}
void
SResource::handleWrite16(SRBRoot * ) {
}
void
StringBaseResource::handlePreWrite(uint32_t *byteOffset) {
fRes = URES_MAKE_RESOURCE(fType, *byteOffset >> 2);
*byteOffset += 4 + (length() + 1) * U_SIZEOF_UCHAR;
}
void
IntVectorResource::handlePreWrite(uint32_t *byteOffset) {
if (fCount == 0 && gFormatVersion > 1) {
fRes = URES_MAKE_EMPTY_RESOURCE(URES_INT_VECTOR);
fWritten = TRUE;
} else {
fRes = URES_MAKE_RESOURCE(URES_INT_VECTOR, *byteOffset >> 2);
*byteOffset += (1 + fCount) * 4;
}
}
void
BinaryResource::handlePreWrite(uint32_t *byteOffset) {
uint32_t pad = 0;
uint32_t dataStart = *byteOffset + sizeof(fLength);
if (dataStart % BIN_ALIGNMENT) {
pad = (BIN_ALIGNMENT - dataStart % BIN_ALIGNMENT);
*byteOffset += pad;
}
fRes = URES_MAKE_RESOURCE(URES_BINARY, *byteOffset >> 2);
*byteOffset += 4 + fLength;
}
void
ContainerResource::preWriteAllRes(uint32_t *byteOffset) {
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
current->preWrite(byteOffset);
}
}
void
ArrayResource::handlePreWrite(uint32_t *byteOffset) {
preWriteAllRes(byteOffset);
fRes = URES_MAKE_RESOURCE(URES_ARRAY, *byteOffset >> 2);
*byteOffset += (1 + fCount) * 4;
}
void
TableResource::handlePreWrite(uint32_t *byteOffset) {
preWriteAllRes(byteOffset);
if (fTableType == URES_TABLE) {
fRes = URES_MAKE_RESOURCE(URES_TABLE, *byteOffset >> 2);
*byteOffset += 2 + fCount * 6;
} else {
fRes = URES_MAKE_RESOURCE(URES_TABLE32, *byteOffset >> 2);
*byteOffset += 4 + fCount * 8;
}
}
void
SResource::preWrite(uint32_t *byteOffset) {
if (fRes != RES_BOGUS) {
return;
}
handlePreWrite(byteOffset);
*byteOffset += calcPadding(*byteOffset);
}
void
SResource::handlePreWrite(uint32_t * ) {
assert(FALSE);
}
void
StringBaseResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) {
int32_t len = length();
udata_write32(mem, len);
udata_writeUString(mem, getBuffer(), len + 1);
*byteOffset += 4 + (len + 1) * U_SIZEOF_UCHAR;
fWritten = TRUE;
}
void
ContainerResource::writeAllRes(UNewDataMemory *mem, uint32_t *byteOffset) {
uint32_t i = 0;
for (SResource *current = fFirst; current != NULL; ++i, current = current->fNext) {
current->write(mem, byteOffset);
}
assert(i == fCount);
}
void
ContainerResource::writeAllRes32(UNewDataMemory *mem, uint32_t *byteOffset) {
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
udata_write32(mem, current->fRes);
}
*byteOffset += fCount * 4;
}
void
ArrayResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) {
writeAllRes(mem, byteOffset);
udata_write32(mem, fCount);
*byteOffset += 4;
writeAllRes32(mem, byteOffset);
}
void
IntVectorResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) {
udata_write32(mem, fCount);
for(uint32_t i = 0; i < fCount; ++i) {
udata_write32(mem, fArray[i]);
}
*byteOffset += (1 + fCount) * 4;
}
void
BinaryResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) {
uint32_t pad = 0;
uint32_t dataStart = *byteOffset + sizeof(fLength);
if (dataStart % BIN_ALIGNMENT) {
pad = (BIN_ALIGNMENT - dataStart % BIN_ALIGNMENT);
udata_writePadding(mem, pad);
*byteOffset += pad;
}
udata_write32(mem, fLength);
if (fLength > 0) {
udata_writeBlock(mem, fData, fLength);
}
*byteOffset += 4 + fLength;
}
void
TableResource::handleWrite(UNewDataMemory *mem, uint32_t *byteOffset) {
writeAllRes(mem, byteOffset);
if(fTableType == URES_TABLE) {
udata_write16(mem, (uint16_t)fCount);
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
udata_write16(mem, current->fKey16);
}
*byteOffset += (1 + fCount)* 2;
if ((fCount & 1) == 0) {
udata_writePadding(mem, 2);
*byteOffset += 2;
}
} else {
udata_write32(mem, fCount);
for (SResource *current = fFirst; current != NULL; current = current->fNext) {
udata_write32(mem, (uint32_t)current->fKey);
}
*byteOffset += (1 + fCount)* 4;
}
writeAllRes32(mem, byteOffset);
}
void
SResource::write(UNewDataMemory *mem, uint32_t *byteOffset) {
if (fWritten) {
assert(fRes != RES_BOGUS);
return;
}
handleWrite(mem, byteOffset);
uint8_t paddingSize = calcPadding(*byteOffset);
if (paddingSize > 0) {
udata_writePadding(mem, paddingSize);
*byteOffset += paddingSize;
}
fWritten = TRUE;
}
void
SResource::handleWrite(UNewDataMemory * , uint32_t * ) {
assert(FALSE);
}
void SRBRoot::write(const char *outputDir, const char *outputPkg,
char *writtenFilename, int writtenFilenameLen,
UErrorCode &errorCode) {
UNewDataMemory *mem = NULL;
uint32_t byteOffset = 0;
uint32_t top, size;
char dataName[1024];
int32_t indexes[URES_INDEX_TOP];
compactKeys(errorCode);
while (fKeysTop & 3) {
fKeys[fKeysTop++] = (char)0xaa;
}
if (fKeysBottom < fKeysTop) {
if (fKeysTop <= 0x10000) {
fLocalKeyLimit = fKeysTop;
} else {
fLocalKeyLimit = 0x10000;
}
} else {
fLocalKeyLimit = 0;
}
UHashtable *stringSet;
if (gFormatVersion > 1) {
stringSet = uhash_open(string_hash, string_comp, string_comp, &errorCode);
if (U_SUCCESS(errorCode) &&
fUsePoolBundle != NULL && fUsePoolBundle->fStrings != NULL) {
for (SResource *current = fUsePoolBundle->fStrings->fFirst;
current != NULL;
current = current->fNext) {
StringResource *sr = static_cast<StringResource *>(current);
sr->fNumCopies = 0;
sr->fNumUnitsSaved = 0;
uhash_put(stringSet, sr, sr, &errorCode);
}
}
fRoot->preflightStrings(this, stringSet, errorCode);
} else {
stringSet = NULL;
}
if (fStringsForm == STRINGS_UTF16_V2 && f16BitStringsLength > 0) {
compactStringsV2(stringSet, errorCode);
}
uhash_close(stringSet);
if (U_FAILURE(errorCode)) {
return;
}
int32_t formatVersion = gFormatVersion;
if (fPoolStringIndexLimit != 0) {
int32_t sum = fPoolStringIndexLimit + fLocalStringIndexLimit;
if ((sum - 1) > RES_MAX_OFFSET) {
errorCode = U_BUFFER_OVERFLOW_ERROR;
return;
}
if (fPoolStringIndexLimit < 0x10000 && sum <= 0x10000) {
fPoolStringIndex16Limit = fPoolStringIndexLimit;
} else {
fPoolStringIndex16Limit = (int32_t)(
((int64_t)fPoolStringIndexLimit * 0xffff) / sum);
}
} else if (gIsDefaultFormatVersion && formatVersion == 3 && !fIsPoolBundle) {
formatVersion = 2;
}
fRoot->write16(this);
if (f16BitUnits.isBogus()) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (f16BitUnits.length() & 1) {
f16BitUnits.append((UChar)0xaaaa);
}
byteOffset = fKeysTop + f16BitUnits.length() * 2;
fRoot->preWrite(&byteOffset);
top = byteOffset;
if (writtenFilename && writtenFilenameLen) {
*writtenFilename = 0;
}
if (writtenFilename) {
int32_t off = 0, len = 0;
if (outputDir) {
len = (int32_t)uprv_strlen(outputDir);
if (len > writtenFilenameLen) {
len = writtenFilenameLen;
}
uprv_strncpy(writtenFilename, outputDir, len);
}
if (writtenFilenameLen -= len) {
off += len;
writtenFilename[off] = U_FILE_SEP_CHAR;
if (--writtenFilenameLen) {
++off;
if(outputPkg != NULL)
{
uprv_strcpy(writtenFilename+off, outputPkg);
off += (int32_t)uprv_strlen(outputPkg);
writtenFilename[off] = '_';
++off;
}
len = (int32_t)uprv_strlen(fLocale);
if (len > writtenFilenameLen) {
len = writtenFilenameLen;
}
uprv_strncpy(writtenFilename + off, fLocale, len);
if (writtenFilenameLen -= len) {
off += len;
len = 5;
if (len > writtenFilenameLen) {
len = writtenFilenameLen;
}
uprv_strncpy(writtenFilename + off, ".res", len);
}
}
}
}
if(outputPkg)
{
uprv_strcpy(dataName, outputPkg);
uprv_strcat(dataName, "_");
uprv_strcat(dataName, fLocale);
}
else
{
uprv_strcpy(dataName, fLocale);
}
uprv_memcpy(dataInfo.formatVersion, gFormatVersions + formatVersion, sizeof(UVersionInfo));
mem = udata_create(outputDir, "res", dataName,
&dataInfo, (gIncludeCopyright==TRUE)? U_COPYRIGHT_STRING:NULL, &errorCode);
if(U_FAILURE(errorCode)){
return;
}
udata_write32(mem, fRoot->fRes);
uprv_memset(indexes, 0, sizeof(indexes));
indexes[URES_INDEX_LENGTH]= fIndexLength;
indexes[URES_INDEX_KEYS_TOP]= fKeysTop>>2;
indexes[URES_INDEX_RESOURCES_TOP]= (int32_t)(top>>2);
indexes[URES_INDEX_BUNDLE_TOP]= indexes[URES_INDEX_RESOURCES_TOP];
indexes[URES_INDEX_MAX_TABLE_LENGTH]= fMaxTableLength;
if (fNoFallback) {
indexes[URES_INDEX_ATTRIBUTES]=URES_ATT_NO_FALLBACK;
}
if (URES_INDEX_16BIT_TOP < fIndexLength) {
indexes[URES_INDEX_16BIT_TOP] = (fKeysTop>>2) + (f16BitUnits.length()>>1);
}
if (URES_INDEX_POOL_CHECKSUM < fIndexLength) {
if (fIsPoolBundle) {
indexes[URES_INDEX_ATTRIBUTES] |= URES_ATT_IS_POOL_BUNDLE | URES_ATT_NO_FALLBACK;
uint32_t checksum = computeCRC((const char *)(fKeys + fKeysBottom),
(uint32_t)(fKeysTop - fKeysBottom), 0);
if (f16BitUnits.length() <= 1) {
} else if (U_IS_BIG_ENDIAN) {
checksum = computeCRC(reinterpret_cast<const char *>(f16BitUnits.getBuffer()),
(uint32_t)f16BitUnits.length() * 2, checksum);
} else {
UnicodeString s(f16BitUnits);
assert(!s.isBogus());
char16_t* p = s.getBuffer(f16BitUnits.length());
for (int32_t count = f16BitUnits.length(); count > 0; --count) {
uint16_t x = *p;
*p++ = (uint16_t)((x << 8) | (x >> 8));
}
s.releaseBuffer(f16BitUnits.length());
checksum = computeCRC((const char *)s.getBuffer(),
(uint32_t)f16BitUnits.length() * 2, checksum);
}
indexes[URES_INDEX_POOL_CHECKSUM] = (int32_t)checksum;
} else if (gUsePoolBundle) {
indexes[URES_INDEX_ATTRIBUTES] |= URES_ATT_USES_POOL_BUNDLE;
indexes[URES_INDEX_POOL_CHECKSUM] = fUsePoolBundle->fChecksum;
}
}
indexes[URES_INDEX_LENGTH] |= fPoolStringIndexLimit << 8; indexes[URES_INDEX_ATTRIBUTES] |= (fPoolStringIndexLimit >> 12) & 0xf000; indexes[URES_INDEX_ATTRIBUTES] |= fPoolStringIndex16Limit << 16;
udata_writeBlock(mem, indexes, fIndexLength*4);
udata_writeBlock(mem, fKeys+fKeysBottom,
fKeysTop-fKeysBottom);
udata_writeBlock(mem, f16BitUnits.getBuffer(), f16BitUnits.length()*2);
byteOffset = fKeysTop + f16BitUnits.length() * 2;
fRoot->write(mem, &byteOffset);
assert(byteOffset == top);
size = udata_finish(mem, &errorCode);
if(top != size) {
fprintf(stderr, "genrb error: wrote %u bytes but counted %u\n",
(int)size, (int)top);
errorCode = U_INTERNAL_PROGRAM_ERROR;
}
}
TableResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
LocalPointer<TableResource> res(new TableResource(bundle, tag, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
ArrayResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
LocalPointer<ArrayResource> res(new ArrayResource(bundle, tag, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) {
LocalPointer<SResource> res(
new StringResource(bundle, tag, value, len, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) {
LocalPointer<SResource> res(
new AliasResource(bundle, tag, value, len, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
IntVectorResource *intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
LocalPointer<IntVectorResource> res(
new IntVectorResource(bundle, tag, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status) {
LocalPointer<SResource> res(new IntResource(bundle, tag, value, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
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) {
LocalPointer<SResource> res(
new BinaryResource(bundle, tag, length, data, fileName, comment, *status), *status);
return U_SUCCESS(*status) ? res.orphan() : NULL;
}
SRBRoot::SRBRoot(const UString *comment, UBool isPoolBundle, UErrorCode &errorCode)
: fRoot(NULL), fLocale(NULL), fIndexLength(0), fMaxTableLength(0), fNoFallback(FALSE),
fStringsForm(STRINGS_UTF16_V1), fIsPoolBundle(isPoolBundle),
fKeys(NULL), fKeyMap(NULL),
fKeysBottom(0), fKeysTop(0), fKeysCapacity(0),
fKeysCount(0), fLocalKeyLimit(0),
f16BitUnits(), f16BitStringsLength(0),
fUsePoolBundle(&kNoPoolBundle),
fPoolStringIndexLimit(0), fPoolStringIndex16Limit(0), fLocalStringIndexLimit(0),
fWritePoolBundle(NULL) {
if (U_FAILURE(errorCode)) {
return;
}
if (gFormatVersion > 1) {
f16BitUnits.append((UChar)0);
}
fKeys = (char *) uprv_malloc(sizeof(char) * KEY_SPACE_SIZE);
if (isPoolBundle) {
fRoot = new PseudoListResource(this, errorCode);
} else {
fRoot = new TableResource(this, NULL, comment, errorCode);
}
if (fKeys == NULL || fRoot == NULL || U_FAILURE(errorCode)) {
if (U_SUCCESS(errorCode)) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
}
return;
}
fKeysCapacity = KEY_SPACE_SIZE;
if (gUsePoolBundle || isPoolBundle) {
fIndexLength = URES_INDEX_POOL_CHECKSUM + 1;
} else if (gFormatVersion >= 2) {
fIndexLength = URES_INDEX_16BIT_TOP + 1;
} else {
fIndexLength = URES_INDEX_ATTRIBUTES + 1;
}
fKeysBottom = (1 + fIndexLength) * 4;
uprv_memset(fKeys, 0, fKeysBottom);
fKeysTop = fKeysBottom;
if (gFormatVersion == 1) {
fStringsForm = STRINGS_UTF16_V1;
} else {
fStringsForm = STRINGS_UTF16_V2;
}
}
void res_close(struct SResource *res) {
delete res;
}
SRBRoot::~SRBRoot() {
delete fRoot;
uprv_free(fLocale);
uprv_free(fKeys);
uprv_free(fKeyMap);
}
void SRBRoot::setLocale(UChar *locale, UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) {
return;
}
uprv_free(fLocale);
fLocale = (char*) uprv_malloc(sizeof(char) * (u_strlen(locale)+1));
if(fLocale == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
u_UCharsToChars(locale, fLocale, u_strlen(locale)+1);
}
const char *
SRBRoot::getKeyString(int32_t key) const {
if (key < 0) {
return fUsePoolBundle->fKeys + (key & 0x7fffffff);
} else {
return fKeys + key;
}
}
const char *
SResource::getKeyString(const SRBRoot *bundle) const {
if (fKey == -1) {
return NULL;
}
return bundle->getKeyString(fKey);
}
const char *
SRBRoot::getKeyBytes(int32_t *pLength) const {
*pLength = fKeysTop - fKeysBottom;
return fKeys + fKeysBottom;
}
int32_t
SRBRoot::addKeyBytes(const char *keyBytes, int32_t length, UErrorCode &errorCode) {
int32_t keypos;
U_ASSERT(fKeyMap == nullptr);
if (U_FAILURE(errorCode)) {
return -1;
}
if (length < 0 || (keyBytes == NULL && length != 0)) {
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return -1;
}
if (length == 0) {
return fKeysTop;
}
keypos = fKeysTop;
fKeysTop += length;
if (fKeysTop >= fKeysCapacity) {
fKeysCapacity += KEY_SPACE_SIZE;
fKeys = static_cast<char *>(uprv_realloc(fKeys, fKeysCapacity));
if(fKeys == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return -1;
}
}
uprv_memcpy(fKeys + keypos, keyBytes, length);
return keypos;
}
int32_t
SRBRoot::addTag(const char *tag, UErrorCode &errorCode) {
int32_t keypos;
if (U_FAILURE(errorCode)) {
return -1;
}
if (tag == NULL) {
return -1;
}
keypos = addKeyBytes(tag, (int32_t)(uprv_strlen(tag) + 1), errorCode);
if (U_SUCCESS(errorCode)) {
++fKeysCount;
}
return keypos;
}
static int32_t
compareInt32(int32_t lPos, int32_t rPos) {
if (lPos < rPos) {
return -1;
} else if (lPos > rPos) {
return 1;
} else {
return 0;
}
}
static int32_t U_CALLCONV
compareKeySuffixes(const void *context, const void *l, const void *r) {
const struct SRBRoot *bundle=(const struct SRBRoot *)context;
int32_t lPos = ((const KeyMapEntry *)l)->oldpos;
int32_t rPos = ((const KeyMapEntry *)r)->oldpos;
const char *lStart = bundle->getKeyString(lPos);
const char *lLimit = lStart;
const char *rStart = bundle->getKeyString(rPos);
const char *rLimit = rStart;
int32_t diff;
while (*lLimit != 0) { ++lLimit; }
while (*rLimit != 0) { ++rLimit; }
while (lStart < lLimit && rStart < rLimit) {
diff = (int32_t)(uint8_t)*--lLimit - (int32_t)(uint8_t)*--rLimit;
if (diff != 0) {
return diff;
}
}
diff = (int32_t)(rLimit - rStart) - (int32_t)(lLimit - lStart);
if (diff != 0) {
return diff;
}
return compareInt32(lPos, rPos);
}
static int32_t U_CALLCONV
compareKeyNewpos(const void * , const void *l, const void *r) {
return compareInt32(((const KeyMapEntry *)l)->newpos, ((const KeyMapEntry *)r)->newpos);
}
static int32_t U_CALLCONV
compareKeyOldpos(const void * , const void *l, const void *r) {
return compareInt32(((const KeyMapEntry *)l)->oldpos, ((const KeyMapEntry *)r)->oldpos);
}
void SResource::collectKeys(std::function<void(int32_t)> collector) const {
collector(fKey);
}
void ContainerResource::collectKeys(std::function<void(int32_t)> collector) const {
collector(fKey);
for (SResource* curr = fFirst; curr != NULL; curr = curr->fNext) {
curr->collectKeys(collector);
}
}
void
SRBRoot::compactKeys(UErrorCode &errorCode) {
KeyMapEntry *map;
char *keys;
int32_t i;
std::set<int32_t> keysInUse;
if (!fIsPoolBundle) {
fRoot->collectKeys([&keysInUse](int32_t key) {
if (key >= 0) {
keysInUse.insert(key);
}
});
fKeysCount = static_cast<int32_t>(keysInUse.size());
}
int32_t keysCount = fUsePoolBundle->fKeysCount + fKeysCount;
if (U_FAILURE(errorCode) || fKeyMap != NULL) {
return;
}
map = (KeyMapEntry *)uprv_malloc(keysCount * sizeof(KeyMapEntry));
if (map == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
keys = (char *)fUsePoolBundle->fKeys;
for (i = 0; i < fUsePoolBundle->fKeysCount; ++i) {
map[i].oldpos =
(int32_t)(keys - fUsePoolBundle->fKeys) | 0x80000000;
map[i].newpos = 0;
while (*keys != 0) { ++keys; }
++keys;
}
keys = fKeys + fKeysBottom;
while (i < keysCount) {
int32_t keyOffset = static_cast<int32_t>(keys - fKeys);
if (!fIsPoolBundle && keysInUse.count(keyOffset) == 0) {
while (*keys != 0) { *keys++ = 1; }
*keys++ = 1;
} else {
map[i].oldpos = keyOffset;
map[i].newpos = 0;
while (*keys != 0) { ++keys; }
++keys;
i++;
}
}
if (keys != fKeys + fKeysTop) {
fKeysTop = static_cast<int32_t>(keys - fKeys);
}
uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry),
compareKeySuffixes, this, FALSE, &errorCode);
if (U_SUCCESS(errorCode)) {
keys = fKeys;
for (i = 0; i < keysCount;) {
const char *key;
const char *keyLimit;
int32_t j = i + 1;
map[i].newpos = map[i].oldpos;
if (j < keysCount && map[j].oldpos < 0) {
i = j;
continue;
}
key = getKeyString(map[i].oldpos);
for (keyLimit = key; *keyLimit != 0; ++keyLimit) {}
for (; j < keysCount && map[j].oldpos >= 0; ++j) {
const char *k;
char *suffix;
const char *suffixLimit;
int32_t offset;
suffix = keys + map[j].oldpos;
for (suffixLimit = suffix; *suffixLimit != 0; ++suffixLimit) {}
offset = static_cast<int32_t>((keyLimit - key) - (suffixLimit - suffix));
if (offset < 0) {
break;
}
for (k = keyLimit; suffix < suffixLimit && *--k == *--suffixLimit;) {}
if (suffix == suffixLimit && *k == *suffixLimit) {
map[j].newpos = map[i].oldpos + offset;
while (*suffix != 0) { *suffix++ = 1; }
*suffix = 1;
} else {
break;
}
}
i = j;
}
uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry),
compareKeyNewpos, NULL, FALSE, &errorCode);
if (U_SUCCESS(errorCode)) {
int32_t oldpos, newpos, limit;
oldpos = newpos = fKeysBottom;
limit = fKeysTop;
for (i = 0; i < keysCount && map[i].newpos < 0; ++i) {}
if (i < keysCount) {
while (oldpos < limit) {
if (keys[oldpos] == 1) {
++oldpos;
} else {
while (i < keysCount && map[i].newpos == oldpos) {
map[i++].newpos = newpos;
}
keys[newpos++] = keys[oldpos++];
}
}
U_ASSERT(i == keysCount);
}
fKeysTop = newpos;
uprv_sortArray(map, keysCount, (int32_t)sizeof(KeyMapEntry),
compareKeyOldpos, NULL, FALSE, &errorCode);
if (U_SUCCESS(errorCode)) {
fKeyMap = map;
map = NULL;
}
}
}
uprv_free(map);
}
static int32_t U_CALLCONV
compareStringSuffixes(const void * , const void *l, const void *r) {
const StringResource *left = *((const StringResource **)l);
const StringResource *right = *((const StringResource **)r);
const UChar *lStart = left->getBuffer();
const UChar *lLimit = lStart + left->length();
const UChar *rStart = right->getBuffer();
const UChar *rLimit = rStart + right->length();
int32_t diff;
while (lStart < lLimit && rStart < rLimit) {
diff = (int32_t)*--lLimit - (int32_t)*--rLimit;
if (diff != 0) {
return diff;
}
}
return right->length() - left->length();
}
static int32_t U_CALLCONV
compareStringLengths(const void * , const void *l, const void *r) {
const StringResource *left = *((const StringResource **)l);
const StringResource *right = *((const StringResource **)r);
int32_t diff;
diff = (int)(left->fSame != NULL) - (int)(right->fSame != NULL);
if (diff != 0) {
return diff;
}
diff = left->length() - right->length();
if (diff != 0) {
return diff;
}
diff = right->fNumUnitsSaved - left->fNumUnitsSaved;
if (diff != 0) {
return diff;
}
return left->fString.compare(right->fString);
}
void
StringResource::writeUTF16v2(int32_t base, UnicodeString &dest) {
int32_t len = length();
fRes = URES_MAKE_RESOURCE(URES_STRING_V2, base + dest.length());
fWritten = TRUE;
switch(fNumCharsForLength) {
case 0:
break;
case 1:
dest.append((UChar)(0xdc00 + len));
break;
case 2:
dest.append((UChar)(0xdfef + (len >> 16)));
dest.append((UChar)len);
break;
case 3:
dest.append((UChar)0xdfff);
dest.append((UChar)(len >> 16));
dest.append((UChar)len);
break;
default:
break;
}
dest.append(fString);
dest.append((UChar)0);
}
void
SRBRoot::compactStringsV2(UHashtable *stringSet, UErrorCode &errorCode) {
if (U_FAILURE(errorCode)) {
return;
}
int32_t count = uhash_count(stringSet);
LocalArray<StringResource *> array(new StringResource *[count], errorCode);
if (U_FAILURE(errorCode)) {
return;
}
for (int32_t pos = UHASH_FIRST, i = 0; i < count; ++i) {
array[i] = (StringResource *)uhash_nextElement(stringSet, &pos)->key.pointer;
}
uprv_sortArray(array.getAlias(), count, (int32_t)sizeof(struct SResource **),
compareStringSuffixes, NULL, FALSE, &errorCode);
if (U_FAILURE(errorCode)) {
return;
}
for (int32_t i = 0; i < count;) {
StringResource *res = array[i];
res->fNumUnitsSaved = (res->fNumCopies - 1) * res->get16BitStringsLength();
int32_t j;
for (j = i + 1; j < count; ++j) {
StringResource *suffixRes = array[j];
if (res->fString.endsWith(suffixRes->fString)) {
assert(res->length() != suffixRes->length()); if (suffixRes->fWritten) {
} else if (suffixRes->fNumCharsForLength == 0) {
suffixRes->fSame = res;
suffixRes->fSuffixOffset = res->length() - suffixRes->length();
if (res->fWritten) {
suffixRes->fRes =
res->fRes + res->fNumCharsForLength + suffixRes->fSuffixOffset;
int32_t poolStringIndex = (int32_t)RES_GET_OFFSET(suffixRes->fRes);
if (poolStringIndex >= fPoolStringIndexLimit) {
fPoolStringIndexLimit = poolStringIndex + 1;
}
suffixRes->fWritten = TRUE;
}
res->fNumUnitsSaved += suffixRes->fNumCopies * suffixRes->get16BitStringsLength();
} else {
}
} else {
break;
}
}
i = j;
}
uprv_sortArray(array.getAlias(), count, (int32_t)sizeof(struct SResource **),
compareStringLengths, NULL, FALSE, &errorCode);
if (U_FAILURE(errorCode)) {
return;
}
if (fIsPoolBundle) {
int32_t numStringsWritten = 0;
int32_t numUnitsSaved = 0;
int32_t numUnitsNotSaved = 0;
for (int32_t i = 0; i < count; ++i) {
StringResource *res = array[i];
int32_t maxStringIndex =
f16BitUnits.length() + res->fNumCharsForLength + res->length() - 1;
if (res->fNumUnitsSaved >= GENRB_MIN_16BIT_UNITS_SAVED_FOR_POOL_STRING &&
maxStringIndex < RES_MAX_OFFSET) {
res->writeUTF16v2(0, f16BitUnits);
++numStringsWritten;
numUnitsSaved += res->fNumUnitsSaved;
} else {
numUnitsNotSaved += res->fNumUnitsSaved;
res->fRes = URES_MAKE_EMPTY_RESOURCE(URES_STRING);
res->fWritten = TRUE;
}
}
if (f16BitUnits.isBogus()) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
}
if (getShowWarning()) { printf("number of shared strings: %d\n", (int)numStringsWritten);
printf("16-bit units for strings: %6d = %6d bytes\n",
(int)f16BitUnits.length(), (int)f16BitUnits.length() * 2);
printf("16-bit units saved: %6d = %6d bytes\n",
(int)numUnitsSaved, (int)numUnitsSaved * 2);
printf("16-bit units not saved: %6d = %6d bytes\n",
(int)numUnitsNotSaved, (int)numUnitsNotSaved * 2);
}
} else {
assert(fPoolStringIndexLimit <= fUsePoolBundle->fStringIndexLimit);
int32_t i;
for (i = 0; i < count && array[i]->fSame == NULL; ++i) {
StringResource *res = array[i];
if (!res->fWritten) {
int32_t localStringIndex = f16BitUnits.length();
if (localStringIndex >= fLocalStringIndexLimit) {
fLocalStringIndexLimit = localStringIndex + 1;
}
res->writeUTF16v2(fPoolStringIndexLimit, f16BitUnits);
}
}
if (f16BitUnits.isBogus()) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
if (fWritePoolBundle != NULL && gFormatVersion >= 3) {
PseudoListResource *poolStrings =
static_cast<PseudoListResource *>(fWritePoolBundle->fRoot);
for (i = 0; i < count && array[i]->fSame == NULL; ++i) {
assert(!array[i]->fString.isEmpty());
StringResource *poolString =
new StringResource(fWritePoolBundle, array[i]->fString, errorCode);
if (poolString == NULL) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
break;
}
poolStrings->add(poolString);
}
}
for (; i < count; ++i) {
StringResource *res = array[i];
if (res->fWritten) {
continue;
}
StringResource *same = res->fSame;
assert(res->length() != same->length()); res->fRes = same->fRes + same->fNumCharsForLength + res->fSuffixOffset;
int32_t localStringIndex = (int32_t)RES_GET_OFFSET(res->fRes) - fPoolStringIndexLimit;
assert(localStringIndex >= 0);
if (localStringIndex >= fLocalStringIndexLimit) {
fLocalStringIndexLimit = localStringIndex + 1;
}
res->fWritten = TRUE;
}
}
assert(f16BitUnits.length() <= (f16BitStringsLength + 1));
}
void SResource::applyFilter(
const PathFilter& ,
ResKeyPath& ,
const SRBRoot* ) {
}
void TableResource::applyFilter(
const PathFilter& filter,
ResKeyPath& path,
const SRBRoot* bundle) {
SResource* prev = nullptr;
SResource* curr = fFirst;
for (; curr != nullptr;) {
path.push(curr->getKeyString(bundle));
auto inclusion = filter.match(path);
if (inclusion == PathFilter::EInclusion::INCLUDE) {
if (isVerbose()) {
std::cout << "genrb subtree: " << bundle->fLocale << ": INCLUDE: " << path << std::endl;
}
} else if (inclusion == PathFilter::EInclusion::EXCLUDE) {
if (isVerbose()) {
std::cout << "genrb subtree: " << bundle->fLocale << ": DELETE: " << path << std::endl;
}
if (prev == nullptr) {
fFirst = curr->fNext;
} else {
prev->fNext = curr->fNext;
}
fCount--;
delete curr;
curr = prev;
} else {
U_ASSERT(inclusion == PathFilter::EInclusion::PARTIAL);
curr->applyFilter(filter, path, bundle);
}
path.pop();
prev = curr;
if (curr == nullptr) {
curr = fFirst;
} else {
curr = curr->fNext;
}
}
}