0

The documentation for ICU states that

Starting with ICU 4.4, it is possible to set several data packages, one per call to this function. udata_open() will look for data in the multiple data packages in the order in which they were set.

However, I would like udata_open() to look for data in the reverse order, so that as soon as I add a new udata_setCommonData, I can overwrite any previous data with my new data. Obviously if an object which uses data has been instantiated, it will use the old set, but any new data should use the new data. I'm guessing that the answer is somewhere in udata.cpp near doLoadFromCommonData, hopefully it is not too complicated to make this change. In that function, I see

if (!isICUData) {
    return NULL;
} else if (pCommonData != NULL) {
    ++commonDataIndex;  /* try the next data package */
} else if ((!checkedExtendedICUData) && extendICUData(subErrorCode)) {
    checkedExtendedICUData = TRUE;
    /* try this data package slot again: it changed from NULL to non-NULL */
} else {
    return NULL;

I suspect I want to start at the top and use --commonDataIndex instead.

Update. I discovered that I can also swap out the contents as long as the pointer is the same and re-run udata_setCommonData. Perhaps this is a good solution that avoids having to modify the ICU code. Just need to allocate the maximum possible size I might encounter - which .. perhaps might be trickier.

Alternatively, a way to unsetCommonData might be good too.

Or, making storing a pointer to a pointer to the data instead of the pointer to the data in

for (i = 0; i < LENGTHOF(gCommonICUDataArray); ++i) {
    if (gCommonICUDataArray[i] == NULL) {
        gCommonICUDataArray[i] = newCommonData;
        ucln_common_registerCleanup(UCLN_COMMON_UDATA, udata_cleanup);
        didUpdate = TRUE;
        break;
    } else if (gCommonICUDataArray[i]->pHeader == pData->pHeader) {
        /* The same data pointer is already in the array. */
        break;
    }
tofutim
  • 22,664
  • 20
  • 87
  • 148

1 Answers1

0

The only safe (or sane) way to do this is to call u_cleanup() and start over. Otherwise this is not good usage of ICU at all, and highly un-recommended. Sorry.

If you want to dynamically update data, make a feature request, or better yet contribute the code for it.

Steven R. Loomis
  • 4,228
  • 28
  • 39