-#else
-
-static UBool U_CALLCONV
-isAcceptable(void *context,
- const char *type, const char *name,
- const UDataInfo *pInfo) {
- if(
- pInfo->size>=20 &&
- pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
- pInfo->charsetFamily==U_CHARSET_FAMILY &&
- 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
- ) {
- UBiDiProps *bdp=(UBiDiProps *)context;
- uprv_memcpy(bdp->formatVersion, pInfo->formatVersion, 4);
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-static UBiDiProps *
-ubidi_openData(UBiDiProps *bdpProto,
- const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
- UBiDiProps *bdp;
- int32_t size;
-
- bdpProto->indexes=(const int32_t *)bin;
- if( (length>=0 && length<16*4) ||
- bdpProto->indexes[UBIDI_IX_INDEX_TOP]<16
- ) {
- /* length or indexes[] too short for minimum indexes[] length of 16 */
- *pErrorCode=U_INVALID_FORMAT_ERROR;
- return NULL;
- }
- size=bdpProto->indexes[UBIDI_IX_INDEX_TOP]*4;
- if(length>=0) {
- if(length>=size && length>=bdpProto->indexes[UBIDI_IX_LENGTH]) {
- length-=size;
- } else {
- /* length too short for indexes[] or for the whole data length */
- *pErrorCode=U_INVALID_FORMAT_ERROR;
- return NULL;
- }
- }
- bin+=size;
- /* from here on, assume that the sizes of the items fit into the total length */
-
- /* unserialize the trie, after indexes[] */
- size=bdpProto->indexes[UBIDI_IX_TRIE_SIZE];
- utrie_unserialize(&bdpProto->trie, bin, size, pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- return NULL;
- }
- bin+=size;
-
- /* get mirrors[] */
- size=4*bdpProto->indexes[UBIDI_IX_MIRROR_LENGTH];
- bdpProto->mirrors=(const uint32_t *)bin;
- bin+=size;
-
- /* get jgArray[] */
- size=bdpProto->indexes[UBIDI_IX_JG_LIMIT]-bdpProto->indexes[UBIDI_IX_JG_START];
- bdpProto->jgArray=bin;
- bin+=size;
-
- /* allocate, copy, and return the new UBiDiProps */
- bdp=(UBiDiProps *)uprv_malloc(sizeof(UBiDiProps));
- if(bdp==NULL) {
- *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
- return NULL;
- } else {
- uprv_memcpy(bdp, bdpProto, sizeof(UBiDiProps));
- return bdp;
- }
-}
-
-U_CAPI UBiDiProps * U_EXPORT2
-ubidi_openProps(UErrorCode *pErrorCode) {
- UBiDiProps bdpProto={ NULL }, *bdp;
-
- bdpProto.mem=udata_openChoice(NULL, UBIDI_DATA_TYPE, UBIDI_DATA_NAME, isAcceptable, &bdpProto, pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- return NULL;
- }
-
- bdp=ubidi_openData(
- &bdpProto,
- udata_getMemory(bdpProto.mem),
- udata_getLength(bdpProto.mem),
- pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- udata_close(bdpProto.mem);
- return NULL;
- } else {
- return bdp;
- }
-}
-
-U_CAPI UBiDiProps * U_EXPORT2
-ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode) {
- UBiDiProps bdpProto={ NULL };
- const DataHeader *hdr;
-
- if(U_FAILURE(*pErrorCode)) {
- return NULL;
- }
- if(bin==NULL) {
- *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
- }
-
- /* check the header */
- if(length>=0 && length<20) {
- *pErrorCode=U_INVALID_FORMAT_ERROR;
- return NULL;
- }
- hdr=(const DataHeader *)bin;
- if(
- !(hdr->dataHeader.magic1==0xda && hdr->dataHeader.magic2==0x27 &&
- hdr->info.isBigEndian==U_IS_BIG_ENDIAN &&
- isAcceptable(&bdpProto, UBIDI_DATA_TYPE, UBIDI_DATA_NAME, &hdr->info))
- ) {
- *pErrorCode=U_INVALID_FORMAT_ERROR;
- return NULL;
- }
-
- bin+=hdr->dataHeader.headerSize;
- if(length>=0) {
- length-=hdr->dataHeader.headerSize;
- }
- return ubidi_openData(&bdpProto, bin, length, pErrorCode);
-}
-
-#endif
-
-U_CAPI void U_EXPORT2
-ubidi_closeProps(UBiDiProps *bdp) {
- if(bdp!=NULL) {
-#if !UBIDI_HARDCODE_DATA
- udata_close(bdp->mem);
-#endif
- uprv_free(bdp);
- }
-}
-