-
-int32_t
-PropertyAliases::swap(const UDataSwapper *ds,
- const uint8_t *inBytes, int32_t length, uint8_t *outBytes,
- UErrorCode *pErrorCode) {
- const PropertyAliases *inAliases;
- PropertyAliases *outAliases;
- PropertyAliases aliases;
-
- const ValueMap *inValueMaps;
- ValueMap *outValueMaps;
- ValueMap valueMap;
-
- uint8_t *temp;
-
- int32_t i;
-
- inAliases=(const PropertyAliases *)inBytes;
- outAliases=(PropertyAliases *)outBytes;
-
- /* read the input PropertyAliases - all 16-bit values */
- for(i=0; i<(int32_t)sizeof(PropertyAliases)/2; ++i) {
- ((uint16_t *)&aliases)[i]=ds->readUInt16(((const uint16_t *)inBytes)[i]);
- }
-
- if(length>=0) {
- if(length<aliases.total_size) {
- udata_printError(ds, "upname_swap(): too few bytes (%d after header) for all of pnames.icu\n",
- length);
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- return 0;
- }
-
- /* copy the data for inaccessible bytes */
- if(inBytes!=outBytes) {
- uprv_memcpy(outBytes, inBytes, aliases.total_size);
- }
-
- /* swap the PropertyAliases class fields */
- ds->swapArray16(ds, inAliases, sizeof(PropertyAliases), outAliases, pErrorCode);
-
- /* swap the name groups */
- ds->swapArray16(ds, inBytes+aliases.nameGroupPool_offset,
- aliases.stringPool_offset-aliases.nameGroupPool_offset,
- outBytes+aliases.nameGroupPool_offset, pErrorCode);
-
- /* swap the strings */
- udata_swapInvStringBlock(ds, inBytes+aliases.stringPool_offset,
- aliases.total_size-aliases.stringPool_offset,
- outBytes+aliases.stringPool_offset, pErrorCode);
-
- /*
- * alloc uint8_t temp[total_size] and reset it
- * swap each top-level struct, put at least the count fields into temp
- * use subclass-specific swap() functions
- * enumerate value maps, for each
- * if temp does not have count!=0 yet
- * read count, put it into temp
- * swap the array(s)
- * resort strings in name->enum maps
- * swap value maps
- */
- temp=(uint8_t *)uprv_malloc(aliases.total_size);
- if(temp==NULL) {
- udata_printError(ds, "upname_swap(): unable to allocate temp memory (%d bytes)\n",
- aliases.total_size);
- *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
- return 0;
- }
- uprv_memset(temp, 0, aliases.total_size);
-
- /* swap properties->name groups map */
- NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
- temp, aliases.enumToName_offset, pErrorCode);
-
- /* swap name->properties map */
- NameToEnum::swap(ds, inBytes, length, outBytes,
- temp, aliases.nameToEnum_offset, pErrorCode);
-
- /* swap properties->value maps map */
- NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
- temp, aliases.enumToValue_offset, pErrorCode);
-
- /* enumerate all ValueMaps and swap them */
- inValueMaps=(const ValueMap *)(inBytes+aliases.valueMap_offset);
- outValueMaps=(ValueMap *)(outBytes+aliases.valueMap_offset);
-
- for(i=0; i<aliases.valueMap_count; ++i) {
- valueMap.enumToName_offset=udata_readInt16(ds, inValueMaps[i].enumToName_offset);
- valueMap.ncEnumToName_offset=udata_readInt16(ds, inValueMaps[i].ncEnumToName_offset);
- valueMap.nameToEnum_offset=udata_readInt16(ds, inValueMaps[i].nameToEnum_offset);
-
- if(valueMap.enumToName_offset!=0) {
- EnumToOffset::swap(ds, inBytes, length, outBytes,
- temp, valueMap.enumToName_offset,
- pErrorCode);
- } else if(valueMap.ncEnumToName_offset!=0) {
- NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
- temp, valueMap.ncEnumToName_offset,
- pErrorCode);
- }
- if(valueMap.nameToEnum_offset!=0) {
- NameToEnum::swap(ds, inBytes, length, outBytes,
- temp, valueMap.nameToEnum_offset,
- pErrorCode);
- }
- }
-
- /* swap the ValueMaps array itself */
- ds->swapArray16(ds, inValueMaps, aliases.valueMap_count*sizeof(ValueMap),
- outValueMaps, pErrorCode);
-
- /* name groups and strings were swapped above */
-
- /* release temp */
- uprv_free(temp);
- }
-
- return aliases.total_size;
-}
-
-U_CAPI int32_t U_EXPORT2
-upname_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;
-
- /* 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]==0x70 && /* dataFormat="pnam" */
- pInfo->dataFormat[1]==0x6e &&
- pInfo->dataFormat[2]==0x61 &&
- pInfo->dataFormat[3]==0x6d &&
- pInfo->formatVersion[0]==1
- )) {
- udata_printError(ds, "upname_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as pnames.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;
-
- if(length>=0) {
- length-=headerSize;
- if(length<(int32_t)sizeof(PropertyAliases)) {
- udata_printError(ds, "upname_swap(): too few bytes (%d after header) for pnames.icu\n",
- length);
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- return 0;
- }
- }
-
- return headerSize+PropertyAliases::swap(ds, inBytes, length, outBytes, pErrorCode);
-}
-
-//eof