mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-4497 move swap functions for core Unicode properties data from the common library to the icuswap tool, disable _openBinary() functions, disable tests accordingly
X-SVN-Rev: 17558
This commit is contained in:
parent
54fbbdec50
commit
681fbba869
9 changed files with 570 additions and 19 deletions
|
@ -47,7 +47,7 @@ struct UBiDiProps {
|
|||
/* ubidi_props_data.c is machine-generated by genbidi --csource */
|
||||
#include "ubidi_props_data.c"
|
||||
|
||||
#endif
|
||||
#else
|
||||
|
||||
static UBool U_CALLCONV
|
||||
isAcceptable(void *context,
|
||||
|
@ -129,8 +129,6 @@ ubidi_openData(UBiDiProps *bdpProto,
|
|||
}
|
||||
}
|
||||
|
||||
#if !UBIDI_HARDCODE_DATA
|
||||
|
||||
U_CAPI UBiDiProps * U_EXPORT2
|
||||
ubidi_openProps(UErrorCode *pErrorCode) {
|
||||
UBiDiProps bdpProto={ NULL }, *bdp;
|
||||
|
@ -153,8 +151,6 @@ ubidi_openProps(UErrorCode *pErrorCode) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
U_CAPI UBiDiProps * U_EXPORT2
|
||||
ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
|
||||
UBiDiProps bdpProto={ NULL };
|
||||
|
@ -190,6 +186,8 @@ ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
|
|||
return ubidi_openData(&bdpProto, bin, length, pErrorCode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
ubidi_closeProps(UBiDiProps *bdp) {
|
||||
if(bdp!=NULL) {
|
||||
|
@ -210,7 +208,7 @@ ubidi_cleanup(void) {
|
|||
gBdp=NULL;
|
||||
gErrorCode=U_ZERO_ERROR;
|
||||
gHaveData=0;
|
||||
uprv_free(gBdpDummy);
|
||||
ubidi_closeProps(gBdpDummy);
|
||||
gBdpDummy=NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -315,7 +313,10 @@ ubidi_getDummy(UErrorCode *pErrorCode) {
|
|||
}
|
||||
}
|
||||
|
||||
#if !UBIDI_HARDCODE_DATA
|
||||
|
||||
/* Unicode bidi/shaping data swapping --------------------------------------- */
|
||||
/* moved to the icuswap tool */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ubidi_swap(const UDataSwapper *ds,
|
||||
|
@ -420,6 +421,8 @@ ubidi_swap(const UDataSwapper *ds,
|
|||
return headerSize+size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* set of property starts for UnicodeSet ------------------------------------ */
|
||||
|
||||
static UBool U_CALLCONV
|
||||
|
|
|
@ -48,7 +48,7 @@ struct UCaseProps {
|
|||
/* ucase_props_data.c is machine-generated by gencase --csource */
|
||||
#include "ucase_props_data.c"
|
||||
|
||||
#endif
|
||||
#else
|
||||
|
||||
static UBool U_CALLCONV
|
||||
isAcceptable(void *context,
|
||||
|
@ -134,8 +134,6 @@ ucase_openData(UCaseProps *cspProto,
|
|||
}
|
||||
}
|
||||
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
|
||||
U_CAPI UCaseProps * U_EXPORT2
|
||||
ucase_open(UErrorCode *pErrorCode) {
|
||||
UCaseProps cspProto={ NULL }, *csp;
|
||||
|
@ -158,8 +156,6 @@ ucase_open(UErrorCode *pErrorCode) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
U_CAPI UCaseProps * U_EXPORT2
|
||||
ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
|
||||
UCaseProps cspProto={ NULL };
|
||||
|
@ -195,6 +191,8 @@ ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
|
|||
return ucase_openData(&cspProto, bin, length, pErrorCode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
U_CAPI void U_EXPORT2
|
||||
ucase_close(UCaseProps *csp) {
|
||||
if(csp!=NULL) {
|
||||
|
@ -214,7 +212,7 @@ static UBool U_CALLCONV ucase_cleanup(void) {
|
|||
gCsp=NULL;
|
||||
gErrorCode=U_ZERO_ERROR;
|
||||
gHaveData=0;
|
||||
uprv_free(gCspDummy);
|
||||
ucase_close(gCspDummy);
|
||||
gCspDummy=NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -319,7 +317,10 @@ ucase_getDummy(UErrorCode *pErrorCode) {
|
|||
}
|
||||
}
|
||||
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
|
||||
/* Unicode case mapping data swapping --------------------------------------- */
|
||||
/* moved to the icuswap tool */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ucase_swap(const UDataSwapper *ds,
|
||||
|
@ -420,6 +421,8 @@ ucase_swap(const UDataSwapper *ds,
|
|||
return headerSize+size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* set of property starts for UnicodeSet ------------------------------------ */
|
||||
|
||||
static UBool U_CALLCONV
|
||||
|
|
|
@ -225,9 +225,8 @@ loadPropsData(void) {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Unicode properties data swapping ----------------------------------------- */
|
||||
/* moved to the icuswap tool */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
uprops_swap(const UDataSwapper *ds,
|
||||
|
@ -358,6 +357,8 @@ uprops_swap(const UDataSwapper *ds,
|
|||
return headerSize+4*dataIndexes[UPROPS_RESERVED_INDEX];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* constants and macros for access to the data ------------------------------ */
|
||||
|
||||
/* getting a uint32_t properties word from the data */
|
||||
|
|
|
@ -4073,7 +4073,10 @@ unorm_concatenate(const UChar *left, int32_t leftLength,
|
|||
return u_terminateUChars(dest, destCapacity, destLength, pErrorCode);
|
||||
}
|
||||
|
||||
#if !UNORM_HARDCODE_DATA
|
||||
|
||||
/* data swapping ------------------------------------------------------------ */
|
||||
/* moved to the icuswap tool */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
unorm_swap(const UDataSwapper *ds,
|
||||
|
@ -4196,4 +4199,6 @@ unorm_swap(const UDataSwapper *ds,
|
|||
return headerSize+size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* #if !UCONFIG_NO_NORMALIZATION */
|
||||
|
|
|
@ -2910,13 +2910,28 @@ TestConsistency() {
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Starting with ICU4C 3.4, the core Unicode properties files
|
||||
* (uprops.icu, ucase.icu, ubidi.icu, unorm.icu)
|
||||
* are hardcoded in the common DLL and therefore not included
|
||||
* in the data package any more.
|
||||
* Test requiring these files are disabled so that
|
||||
* we need not jump through hoops (like adding snapshots of these files
|
||||
* to testdata).
|
||||
* See Jitterbug 4497.
|
||||
*/
|
||||
#define HARDCODED_DATA_4497 1
|
||||
|
||||
/* API coverage for ucase.c */
|
||||
static void TestUCase() {
|
||||
#if !HARDCODED_DATA_4497
|
||||
UDataMemory *pData;
|
||||
UCaseProps *csp;
|
||||
#endif
|
||||
const UCaseProps *ccsp;
|
||||
UErrorCode errorCode;
|
||||
|
||||
#if !HARDCODED_DATA_4497
|
||||
/* coverage for ucase_openBinary() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
pData=udata_open(NULL, UCASE_DATA_TYPE, UCASE_DATA_NAME, &errorCode);
|
||||
|
@ -2940,6 +2955,7 @@ static void TestUCase() {
|
|||
|
||||
ucase_close(csp);
|
||||
udata_close(pData);
|
||||
#endif
|
||||
|
||||
/* coverage for ucase_getDummy() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
|
@ -2951,11 +2967,14 @@ static void TestUCase() {
|
|||
|
||||
/* API coverage for ubidi_props.c */
|
||||
static void TestUBiDiProps() {
|
||||
#if !HARDCODED_DATA_4497
|
||||
UDataMemory *pData;
|
||||
UBiDiProps *bdp;
|
||||
#endif
|
||||
const UBiDiProps *cbdp;
|
||||
UErrorCode errorCode;
|
||||
|
||||
#if !HARDCODED_DATA_4497
|
||||
/* coverage for ubidi_openBinary() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
pData=udata_open(NULL, UBIDI_DATA_TYPE, UBIDI_DATA_NAME, &errorCode);
|
||||
|
@ -2979,6 +2998,7 @@ static void TestUBiDiProps() {
|
|||
|
||||
ubidi_closeProps(bdp);
|
||||
udata_close(pData);
|
||||
#endif
|
||||
|
||||
/* coverage for ubidi_getDummy() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
|
|
|
@ -108,7 +108,7 @@ static void TestUDataOpen(){
|
|||
UErrorCode status=U_ZERO_ERROR;
|
||||
const char* memMap[][2]={
|
||||
{"root", "res"},
|
||||
{"unorm", "icu"},
|
||||
{"pnames", "icu"},
|
||||
{"cnvalias", "icu"},
|
||||
{"unames", "icu"},
|
||||
{"ibm-37_P100-1995", "cnv"}
|
||||
|
@ -1100,14 +1100,26 @@ static const struct {
|
|||
/* the last item should not be #if'ed so that it can reliably omit the last comma */
|
||||
|
||||
/* Unicode properties */
|
||||
{"unames", "icu", uchar_swapNames},
|
||||
{"pnames", "icu", upname_swap},
|
||||
#if 0
|
||||
/*
|
||||
* Starting with ICU4C 3.4, the core Unicode properties files
|
||||
* (uprops.icu, ucase.icu, ubidi.icu, unorm.icu)
|
||||
* are hardcoded in the common DLL and therefore not included
|
||||
* in the data package any more.
|
||||
* Their swapping code is moved from the common DLL to the icuswap tool so that
|
||||
* we need not jump through hoops (like adding snapshots of these files
|
||||
* to testdata) for code coverage in tests.
|
||||
* See Jitterbug 4497.
|
||||
*/
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
{"unorm", "icu", unorm_swap},
|
||||
#endif
|
||||
{"uprops", "icu", uprops_swap},
|
||||
{"ucase", "icu", ucase_swap},
|
||||
{"ubidi", "icu", ubidi_swap}
|
||||
{"ubidi", "icu", ubidi_swap},
|
||||
#endif
|
||||
{"unames", "icu", uchar_swapNames}
|
||||
};
|
||||
|
||||
#define SWAP_BUFFER_SIZE 1000000
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
## Makefile.in for ICU - tools/icuswap
|
||||
## Copyright (c) 1999-2004, International Business Machines Corporation and
|
||||
## Copyright (c) 1999-2005, International Business Machines Corporation and
|
||||
## others. All Rights Reserved.
|
||||
## Steven R. Loomis
|
||||
|
||||
|
@ -33,7 +33,7 @@ TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT)
|
|||
CPPFLAGS += -I$(top_builddir)/common -I$(top_srcdir)/common -I$(srcdir)/../toolutil $(BIR_CPPFLAGS)
|
||||
LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M)
|
||||
|
||||
OBJECTS = icuswap.o
|
||||
OBJECTS = icuswap.o swapimpl.o
|
||||
|
||||
DEPS = $(OBJECTS:.o=.d)
|
||||
|
||||
|
|
|
@ -144,6 +144,9 @@
|
|||
<File
|
||||
RelativePath=".\icuswap.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\swapimpl.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
|
504
icu4c/source/tools/icuswap/swapimpl.cpp
Normal file
504
icu4c/source/tools/icuswap/swapimpl.cpp
Normal file
|
@ -0,0 +1,504 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2005, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: swapimpl.cpp
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2005may05
|
||||
* created by: Markus W. Scherer
|
||||
*
|
||||
* Data file swapping functions moved here from the common library
|
||||
* because some data is hardcoded in ICU4C and needs not be swapped any more.
|
||||
* Moving the functions here simplifies testing (for code coverage) because
|
||||
* we need not jump through hoops (like adding snapshots of these files
|
||||
* to testdata).
|
||||
*
|
||||
* The declarations for these functions remain in the internal header files
|
||||
* in icu/source/common/
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/putil.h"
|
||||
#include "unicode/udata.h"
|
||||
#include "cmemory.h"
|
||||
#include "cstring.h"
|
||||
#include "uinvchar.h"
|
||||
#include "uassert.h"
|
||||
#include "uarrsort.h"
|
||||
#include "ucmndata.h"
|
||||
#include "udataswp.h"
|
||||
|
||||
#include "uprops.h"
|
||||
#include "ucase.h"
|
||||
#include "ubidi_props.h"
|
||||
#include "unormimp.h"
|
||||
|
||||
/* Unicode properties data swapping ----------------------------------------- */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
uprops_swap(const UDataSwapper *ds,
|
||||
const void *inData, int32_t length, void *outData,
|
||||
UErrorCode *pErrorCode) {
|
||||
const UDataInfo *pInfo;
|
||||
int32_t headerSize, i;
|
||||
|
||||
int32_t dataIndexes[UPROPS_INDEX_COUNT];
|
||||
const int32_t *inData32;
|
||||
|
||||
/* udata_swapDataHeader checks the arguments */
|
||||
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
||||
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check data format and format version */
|
||||
pInfo=(const UDataInfo *)((const char *)inData+4);
|
||||
if(!(
|
||||
pInfo->dataFormat[0]==0x55 && /* dataFormat="UPro" */
|
||||
pInfo->dataFormat[1]==0x50 &&
|
||||
pInfo->dataFormat[2]==0x72 &&
|
||||
pInfo->dataFormat[3]==0x6f &&
|
||||
(pInfo->formatVersion[0]==3 || pInfo->formatVersion[0]==4) &&
|
||||
pInfo->formatVersion[2]==UTRIE_SHIFT &&
|
||||
pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
|
||||
)) {
|
||||
udata_printError(ds, "uprops_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not a Unicode properties file\n",
|
||||
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
||||
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
||||
pInfo->formatVersion[0]);
|
||||
*pErrorCode=U_UNSUPPORTED_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the properties file must contain at least the indexes array */
|
||||
if(length>=0 && (length-headerSize)<sizeof(dataIndexes)) {
|
||||
udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n",
|
||||
length-headerSize);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read the indexes */
|
||||
inData32=(const int32_t *)((const char *)inData+headerSize);
|
||||
for(i=0; i<UPROPS_INDEX_COUNT; ++i) {
|
||||
dataIndexes[i]=udata_readInt32(ds, inData32[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* comments are copied from the data format description in genprops/store.c
|
||||
* indexes[] constants are in uprops.h
|
||||
*/
|
||||
if(length>=0) {
|
||||
int32_t *outData32;
|
||||
|
||||
if((length-headerSize)<(4*dataIndexes[UPROPS_RESERVED_INDEX])) {
|
||||
udata_printError(ds, "uprops_swap(): too few bytes (%d after header) for a Unicode properties file\n",
|
||||
length-headerSize);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
outData32=(int32_t *)((char *)outData+headerSize);
|
||||
|
||||
/* copy everything for inaccessible data (padding) */
|
||||
if(inData32!=outData32) {
|
||||
uprv_memcpy(outData32, inData32, 4*dataIndexes[UPROPS_RESERVED_INDEX]);
|
||||
}
|
||||
|
||||
/* swap the indexes[16] */
|
||||
ds->swapArray32(ds, inData32, 4*UPROPS_INDEX_COUNT, outData32, pErrorCode);
|
||||
|
||||
/*
|
||||
* swap the main properties UTrie
|
||||
* PT serialized properties trie, see utrie.h (byte size: 4*(i0-16))
|
||||
*/
|
||||
utrie_swap(ds,
|
||||
inData32+UPROPS_INDEX_COUNT,
|
||||
4*(dataIndexes[UPROPS_PROPS32_INDEX]-UPROPS_INDEX_COUNT),
|
||||
outData32+UPROPS_INDEX_COUNT,
|
||||
pErrorCode);
|
||||
|
||||
/*
|
||||
* swap the properties and exceptions words
|
||||
* P const uint32_t props32[i1-i0];
|
||||
* E const uint32_t exceptions[i2-i1];
|
||||
*/
|
||||
ds->swapArray32(ds,
|
||||
inData32+dataIndexes[UPROPS_PROPS32_INDEX],
|
||||
4*(dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]-dataIndexes[UPROPS_PROPS32_INDEX]),
|
||||
outData32+dataIndexes[UPROPS_PROPS32_INDEX],
|
||||
pErrorCode);
|
||||
|
||||
/*
|
||||
* swap the UChars
|
||||
* U const UChar uchars[2*(i3-i2)];
|
||||
*/
|
||||
ds->swapArray16(ds,
|
||||
inData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX],
|
||||
4*(dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]-dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX]),
|
||||
outData32+dataIndexes[UPROPS_EXCEPTIONS_TOP_INDEX],
|
||||
pErrorCode);
|
||||
|
||||
/*
|
||||
* swap the additional UTrie
|
||||
* i3 additionalTrieIndex; -- 32-bit unit index to the additional trie for more properties
|
||||
*/
|
||||
utrie_swap(ds,
|
||||
inData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX],
|
||||
4*(dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]-dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX]),
|
||||
outData32+dataIndexes[UPROPS_ADDITIONAL_TRIE_INDEX],
|
||||
pErrorCode);
|
||||
|
||||
/*
|
||||
* swap the properties vectors
|
||||
* PV const uint32_t propsVectors[(i6-i4)/i5][i5]==uint32_t propsVectors[i6-i4];
|
||||
*/
|
||||
ds->swapArray32(ds,
|
||||
inData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
|
||||
4*(dataIndexes[UPROPS_RESERVED_INDEX]-dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX]),
|
||||
outData32+dataIndexes[UPROPS_ADDITIONAL_VECTORS_INDEX],
|
||||
pErrorCode);
|
||||
}
|
||||
|
||||
/* i6 reservedItemIndex; -- 32-bit unit index to the top of the properties vectors table */
|
||||
return headerSize+4*dataIndexes[UPROPS_RESERVED_INDEX];
|
||||
}
|
||||
|
||||
/* Unicode case mapping data swapping --------------------------------------- */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ucase_swap(const UDataSwapper *ds,
|
||||
const void *inData, int32_t length, void *outData,
|
||||
UErrorCode *pErrorCode) {
|
||||
const UDataInfo *pInfo;
|
||||
int32_t headerSize;
|
||||
|
||||
const uint8_t *inBytes;
|
||||
uint8_t *outBytes;
|
||||
|
||||
const int32_t *inIndexes;
|
||||
int32_t indexes[16];
|
||||
|
||||
int32_t i, offset, count, size;
|
||||
|
||||
/* udata_swapDataHeader checks the arguments */
|
||||
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
||||
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check data format and format version */
|
||||
pInfo=(const UDataInfo *)((const char *)inData+4);
|
||||
if(!(
|
||||
pInfo->dataFormat[0]==UCASE_FMT_0 && /* dataFormat="cAsE" */
|
||||
pInfo->dataFormat[1]==UCASE_FMT_1 &&
|
||||
pInfo->dataFormat[2]==UCASE_FMT_2 &&
|
||||
pInfo->dataFormat[3]==UCASE_FMT_3 &&
|
||||
pInfo->formatVersion[0]==1 &&
|
||||
pInfo->formatVersion[2]==UTRIE_SHIFT &&
|
||||
pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
|
||||
)) {
|
||||
udata_printError(ds, "ucase_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as case mapping data\n",
|
||||
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
||||
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
||||
pInfo->formatVersion[0]);
|
||||
*pErrorCode=U_UNSUPPORTED_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inBytes=(const uint8_t *)inData+headerSize;
|
||||
outBytes=(uint8_t *)outData+headerSize;
|
||||
|
||||
inIndexes=(const int32_t *)inBytes;
|
||||
|
||||
if(length>=0) {
|
||||
length-=headerSize;
|
||||
if(length<16*4) {
|
||||
udata_printError(ds, "ucase_swap(): too few bytes (%d after header) for case mapping data\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* read the first 16 indexes (ICU 3.2/format version 1: UCASE_IX_TOP==16, might grow) */
|
||||
for(i=0; i<16; ++i) {
|
||||
indexes[i]=udata_readInt32(ds, inIndexes[i]);
|
||||
}
|
||||
|
||||
/* get the total length of the data */
|
||||
size=indexes[UCASE_IX_LENGTH];
|
||||
|
||||
if(length>=0) {
|
||||
if(length<size) {
|
||||
udata_printError(ds, "ucase_swap(): too few bytes (%d after header) for all of case mapping data\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy the data for inaccessible bytes */
|
||||
if(inBytes!=outBytes) {
|
||||
uprv_memcpy(outBytes, inBytes, size);
|
||||
}
|
||||
|
||||
offset=0;
|
||||
|
||||
/* swap the int32_t indexes[] */
|
||||
count=indexes[UCASE_IX_INDEX_TOP]*4;
|
||||
ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the UTrie */
|
||||
count=indexes[UCASE_IX_TRIE_SIZE];
|
||||
utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the uint16_t exceptions[] and unfold[] */
|
||||
count=(indexes[UCASE_IX_EXC_LENGTH]+indexes[UCASE_IX_UNFOLD_LENGTH])*2;
|
||||
ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
U_ASSERT(offset==size);
|
||||
}
|
||||
|
||||
return headerSize+size;
|
||||
}
|
||||
|
||||
/* Unicode bidi/shaping data swapping --------------------------------------- */
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ubidi_swap(const UDataSwapper *ds,
|
||||
const void *inData, int32_t length, void *outData,
|
||||
UErrorCode *pErrorCode) {
|
||||
const UDataInfo *pInfo;
|
||||
int32_t headerSize;
|
||||
|
||||
const uint8_t *inBytes;
|
||||
uint8_t *outBytes;
|
||||
|
||||
const int32_t *inIndexes;
|
||||
int32_t indexes[16];
|
||||
|
||||
int32_t i, offset, count, size;
|
||||
|
||||
/* udata_swapDataHeader checks the arguments */
|
||||
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
||||
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check data format and format version */
|
||||
pInfo=(const UDataInfo *)((const char *)inData+4);
|
||||
if(!(
|
||||
pInfo->dataFormat[0]==UBIDI_FMT_0 && /* dataFormat="BiDi" */
|
||||
pInfo->dataFormat[1]==UBIDI_FMT_1 &&
|
||||
pInfo->dataFormat[2]==UBIDI_FMT_2 &&
|
||||
pInfo->dataFormat[3]==UBIDI_FMT_3 &&
|
||||
pInfo->formatVersion[0]==1 &&
|
||||
pInfo->formatVersion[2]==UTRIE_SHIFT &&
|
||||
pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT
|
||||
)) {
|
||||
udata_printError(ds, "ubidi_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as bidi/shaping data\n",
|
||||
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
||||
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
||||
pInfo->formatVersion[0]);
|
||||
*pErrorCode=U_UNSUPPORTED_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inBytes=(const uint8_t *)inData+headerSize;
|
||||
outBytes=(uint8_t *)outData+headerSize;
|
||||
|
||||
inIndexes=(const int32_t *)inBytes;
|
||||
|
||||
if(length>=0) {
|
||||
length-=headerSize;
|
||||
if(length<16*4) {
|
||||
udata_printError(ds, "ubidi_swap(): too few bytes (%d after header) for bidi/shaping data\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* read the first 16 indexes (ICU 3.4/format version 1: UBIDI_IX_TOP==16, might grow) */
|
||||
for(i=0; i<16; ++i) {
|
||||
indexes[i]=udata_readInt32(ds, inIndexes[i]);
|
||||
}
|
||||
|
||||
/* get the total length of the data */
|
||||
size=indexes[UBIDI_IX_LENGTH];
|
||||
|
||||
if(length>=0) {
|
||||
if(length<size) {
|
||||
udata_printError(ds, "ubidi_swap(): too few bytes (%d after header) for all of bidi/shaping data\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy the data for inaccessible bytes */
|
||||
if(inBytes!=outBytes) {
|
||||
uprv_memcpy(outBytes, inBytes, size);
|
||||
}
|
||||
|
||||
offset=0;
|
||||
|
||||
/* swap the int32_t indexes[] */
|
||||
count=indexes[UBIDI_IX_INDEX_TOP]*4;
|
||||
ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the UTrie */
|
||||
count=indexes[UBIDI_IX_TRIE_SIZE];
|
||||
utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the uint32_t mirrors[] */
|
||||
count=indexes[UBIDI_IX_MIRROR_LENGTH]*4;
|
||||
ds->swapArray32(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* just skip the uint8_t jgArray[] */
|
||||
count=indexes[UBIDI_IX_JG_LIMIT]-indexes[UBIDI_IX_JG_START];
|
||||
offset+=count;
|
||||
|
||||
U_ASSERT(offset==size);
|
||||
}
|
||||
|
||||
return headerSize+size;
|
||||
}
|
||||
|
||||
/* Unicode normalization data swapping -------------------------------------- */
|
||||
|
||||
#if !UCONFIG_NO_NORMALIZATION
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
unorm_swap(const UDataSwapper *ds,
|
||||
const void *inData, int32_t length, void *outData,
|
||||
UErrorCode *pErrorCode) {
|
||||
const UDataInfo *pInfo;
|
||||
int32_t headerSize;
|
||||
|
||||
const uint8_t *inBytes;
|
||||
uint8_t *outBytes;
|
||||
|
||||
const int32_t *inIndexes;
|
||||
int32_t indexes[32];
|
||||
|
||||
int32_t i, offset, count, size;
|
||||
|
||||
/* udata_swapDataHeader checks the arguments */
|
||||
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
||||
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check data format and format version */
|
||||
pInfo=(const UDataInfo *)((const char *)inData+4);
|
||||
if(!(
|
||||
pInfo->dataFormat[0]==0x4e && /* dataFormat="Norm" */
|
||||
pInfo->dataFormat[1]==0x6f &&
|
||||
pInfo->dataFormat[2]==0x72 &&
|
||||
pInfo->dataFormat[3]==0x6d &&
|
||||
pInfo->formatVersion[0]==2
|
||||
)) {
|
||||
udata_printError(ds, "unorm_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as unorm.icu\n",
|
||||
pInfo->dataFormat[0], pInfo->dataFormat[1],
|
||||
pInfo->dataFormat[2], pInfo->dataFormat[3],
|
||||
pInfo->formatVersion[0]);
|
||||
*pErrorCode=U_UNSUPPORTED_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inBytes=(const uint8_t *)inData+headerSize;
|
||||
outBytes=(uint8_t *)outData+headerSize;
|
||||
|
||||
inIndexes=(const int32_t *)inBytes;
|
||||
|
||||
if(length>=0) {
|
||||
length-=headerSize;
|
||||
if(length<32*4) {
|
||||
udata_printError(ds, "unorm_swap(): too few bytes (%d after header) for unorm.icu\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* read the first 32 indexes (ICU 2.8/format version 2.2: _NORM_INDEX_TOP==32, might grow) */
|
||||
for(i=0; i<32; ++i) {
|
||||
indexes[i]=udata_readInt32(ds, inIndexes[i]);
|
||||
}
|
||||
|
||||
/* calculate the total length of the data */
|
||||
size=
|
||||
32*4+ /* size of indexes[] */
|
||||
indexes[_NORM_INDEX_TRIE_SIZE]+
|
||||
indexes[_NORM_INDEX_UCHAR_COUNT]*2+
|
||||
indexes[_NORM_INDEX_COMBINE_DATA_COUNT]*2+
|
||||
indexes[_NORM_INDEX_FCD_TRIE_SIZE]+
|
||||
indexes[_NORM_INDEX_AUX_TRIE_SIZE]+
|
||||
indexes[_NORM_INDEX_CANON_SET_COUNT]*2;
|
||||
|
||||
if(length>=0) {
|
||||
if(length<size) {
|
||||
udata_printError(ds, "unorm_swap(): too few bytes (%d after header) for all of unorm.icu\n",
|
||||
length);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* copy the data for inaccessible bytes */
|
||||
if(inBytes!=outBytes) {
|
||||
uprv_memcpy(outBytes, inBytes, size);
|
||||
}
|
||||
|
||||
offset=0;
|
||||
|
||||
/* swap the indexes[] */
|
||||
count=32*4;
|
||||
ds->swapArray32(ds, inBytes, count, outBytes, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the main UTrie */
|
||||
count=indexes[_NORM_INDEX_TRIE_SIZE];
|
||||
utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the uint16_t extraData[] and the uint16_t combiningTable[] */
|
||||
count=(indexes[_NORM_INDEX_UCHAR_COUNT]+indexes[_NORM_INDEX_COMBINE_DATA_COUNT])*2;
|
||||
ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
|
||||
/* swap the FCD UTrie */
|
||||
count=indexes[_NORM_INDEX_FCD_TRIE_SIZE];
|
||||
if(count!=0) {
|
||||
utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
}
|
||||
|
||||
/* swap the aux UTrie */
|
||||
count=indexes[_NORM_INDEX_AUX_TRIE_SIZE];
|
||||
if(count!=0) {
|
||||
utrie_swap(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
}
|
||||
|
||||
/* swap the uint16_t combiningTable[] */
|
||||
count=indexes[_NORM_INDEX_CANON_SET_COUNT]*2;
|
||||
ds->swapArray16(ds, inBytes+offset, count, outBytes+offset, pErrorCode);
|
||||
offset+=count;
|
||||
}
|
||||
|
||||
return headerSize+size;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue