+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
***************************************************************************
* Copyright (C) 1999-2014 International Business Machines Corporation *
#include "unicode/utypes.h"
#include "rbbidata.h"
#include "rbbirb.h"
-#include "utrie.h"
+#include "utrie2.h"
#include "udatamem.h"
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
-//-----------------------------------------------------------------------------------
-//
-// Trie access folding function. Copied as-is from properties code in uchar.c
-//
-//-----------------------------------------------------------------------------------
-U_CDECL_BEGIN
-static int32_t U_CALLCONV
-getFoldingOffset(uint32_t data) {
- /* if bit 15 is set, then the folding offset is in bits 14..0 of the 16-bit trie result */
- if(data&0x8000) {
- return (int32_t)(data&0x7fff);
- } else {
- return 0;
- }
-}
-U_CDECL_END
-
U_NAMESPACE_BEGIN
//-----------------------------------------------------------------------------
dh->info.dataFormat[0] == 0x42 && // dataFormat="Brk "
dh->info.dataFormat[1] == 0x72 &&
dh->info.dataFormat[2] == 0x6b &&
- dh->info.dataFormat[3] == 0x20)
- // Note: info.fFormatVersion is duplicated in the RBBIDataHeader, and is
- // validated when checking that.
+ dh->info.dataFormat[3] == 0x20 &&
+ isDataVersionAcceptable(dh->info.formatVersion))
) {
status = U_INVALID_FORMAT_ERROR;
return;
fUDataMem = udm;
}
+UBool RBBIDataWrapper::isDataVersionAcceptable(const UVersionInfo version) {
+ return RBBI_DATA_FORMAT_VERSION[0] == version[0];
+}
+
+
//-----------------------------------------------------------------------------
//
// init(). Does most of the work of construction, shared between the
fHeader = NULL;
fForwardTable = NULL;
fReverseTable = NULL;
- fSafeFwdTable = NULL;
- fSafeRevTable = NULL;
- fRuleSource = NULL;
+ fRuleSource = NULL;
fRuleStatusTable = NULL;
- fUDataMem = NULL;
- fRefCount = 0;
+ fTrie = NULL;
+ fUDataMem = NULL;
+ fRefCount = 0;
fDontFreeData = TRUE;
}
return;
}
fHeader = data;
- if (fHeader->fMagic != 0xb1a0 || fHeader->fFormatVersion[0] != 3)
- {
+ if (fHeader->fMagic != 0xb1a0 || !isDataVersionAcceptable(fHeader->fFormatVersion)) {
status = U_INVALID_FORMAT_ERROR;
return;
}
if (data->fRTableLen != 0) {
fReverseTable = (RBBIStateTable *)((char *)data + fHeader->fRTable);
}
- if (data->fSFTableLen != 0) {
- fSafeFwdTable = (RBBIStateTable *)((char *)data + fHeader->fSFTable);
- }
- if (data->fSRTableLen != 0) {
- fSafeRevTable = (RBBIStateTable *)((char *)data + fHeader->fSRTable);
- }
-
- utrie_unserialize(&fTrie,
- (uint8_t *)data + fHeader->fTrie,
- fHeader->fTrieLen,
- &status);
+ fTrie = utrie2_openFromSerialized(UTRIE2_16_VALUE_BITS,
+ (uint8_t *)data + fHeader->fTrie,
+ fHeader->fTrieLen,
+ NULL, // *actual length
+ &status);
if (U_FAILURE(status)) {
return;
}
- fTrie.getFoldingOffset=getFoldingOffset;
-
fRuleSource = (UChar *)((char *)data + fHeader->fRuleSource);
fRuleString.setTo(TRUE, fRuleSource, -1);
//-----------------------------------------------------------------------------
RBBIDataWrapper::~RBBIDataWrapper() {
U_ASSERT(fRefCount == 0);
+ utrie2_close(fTrie);
+ fTrie = NULL;
if (fUDataMem) {
udata_close(fUDataMem);
} else if (!fDontFreeData) {
#endif
-#ifdef RBBI_DEBUG
void RBBIDataWrapper::printData() {
+#ifdef RBBI_DEBUG
RBBIDebugPrintf("RBBI Data at %p\n", (void *)fHeader);
RBBIDebugPrintf(" Version = {%d %d %d %d}\n", fHeader->fFormatVersion[0], fHeader->fFormatVersion[1],
fHeader->fFormatVersion[2], fHeader->fFormatVersion[3]);
printTable("Forward State Transition Table", fForwardTable);
printTable("Reverse State Transition Table", fReverseTable);
- printTable("Safe Forward State Transition Table", fSafeFwdTable);
- printTable("Safe Reverse State Transition Table", fSafeRevTable);
RBBIDebugPrintf("\nOrignal Rules source:\n");
for (int32_t c=0; fRuleSource[c] != 0; c++) {
RBBIDebugPrintf("%c", fRuleSource[c]);
}
RBBIDebugPrintf("\n\n");
-}
#endif
+}
U_NAMESPACE_END
pInfo->dataFormat[1]==0x72 &&
pInfo->dataFormat[2]==0x6b &&
pInfo->dataFormat[3]==0x20 &&
- pInfo->formatVersion[0]==3 )) {
+ RBBIDataWrapper::isDataVersionAcceptable(pInfo->formatVersion) )) {
udata_printError(ds, "ubrk_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized\n",
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3],
//
// Get the RRBI Data Header, and check that it appears to be OK.
//
- // Note: ICU 3.2 and earlier, RBBIDataHeader::fDataFormat was actually
- // an int32_t with a value of 1. Starting with ICU 3.4,
- // RBBI's fDataFormat matches the dataFormat field from the
- // UDataInfo header, four int8_t bytes. The value is {3,1,0,0}
- //
const uint8_t *inBytes =(const uint8_t *)inData+headerSize;
RBBIDataHeader *rbbiDH = (RBBIDataHeader *)inBytes;
if (ds->readUInt32(rbbiDH->fMagic) != 0xb1a0 ||
- rbbiDH->fFormatVersion[0] != 3 ||
- ds->readUInt32(rbbiDH->fLength) < sizeof(RBBIDataHeader))
- {
+ !RBBIDataWrapper::isDataVersionAcceptable(rbbiDH->fFormatVersion) ||
+ ds->readUInt32(rbbiDH->fLength) < sizeof(RBBIDataHeader)) {
udata_printError(ds, "ubrk_swap(): RBBI Data header is invalid.\n");
*status=U_UNSUPPORTED_ERROR;
return 0;
outBytes+tableStartOffset+topSize, status);
}
- // Safe Forward state table. Same layout as forward table, above.
- tableStartOffset = ds->readUInt32(rbbiDH->fSFTable);
- tableLength = ds->readUInt32(rbbiDH->fSFTableLen);
-
- if (tableLength > 0) {
- ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
- outBytes+tableStartOffset, status);
- ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
- outBytes+tableStartOffset+topSize, status);
- }
-
- // Safe Reverse state table. Same layout as forward table, above.
- tableStartOffset = ds->readUInt32(rbbiDH->fSRTable);
- tableLength = ds->readUInt32(rbbiDH->fSRTableLen);
-
- if (tableLength > 0) {
- ds->swapArray32(ds, inBytes+tableStartOffset, topSize,
- outBytes+tableStartOffset, status);
- ds->swapArray16(ds, inBytes+tableStartOffset+topSize, tableLength-topSize,
- outBytes+tableStartOffset+topSize, status);
- }
-
// Trie table for character categories
- utrie_swap(ds, inBytes+ds->readUInt32(rbbiDH->fTrie), ds->readUInt32(rbbiDH->fTrieLen),
- outBytes+ds->readUInt32(rbbiDH->fTrie), status);
+ utrie2_swap(ds, inBytes+ds->readUInt32(rbbiDH->fTrie), ds->readUInt32(rbbiDH->fTrieLen),
+ outBytes+ds->readUInt32(rbbiDH->fTrie), status);
// Source Rules Text. It's UChar data
ds->swapArray16(ds, inBytes+ds->readUInt32(rbbiDH->fRuleSource), ds->readUInt32(rbbiDH->fRuleSourceLen),