2 *******************************************************************************
3 * Copyright (C) 2013-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2013aug05
9 * created by: Markus W. Scherer
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_COLLATION
19 #include "collationdata.h"
20 #include "collationdatareader.h"
21 #include "collationinfo.h"
28 CollationInfo::printSizes(int32_t sizeWithHeader
, const int32_t indexes
[]) {
29 int32_t totalSize
= indexes
[CollationDataReader::IX_TOTAL_SIZE
];
30 if(sizeWithHeader
> totalSize
) {
31 printf(" header size: %6ld\n", (long)(sizeWithHeader
- totalSize
));
34 int32_t length
= indexes
[CollationDataReader::IX_INDEXES_LENGTH
];
35 printf(" indexes: %6ld *4 = %6ld\n", (long)length
, (long)length
* 4);
37 length
= getDataLength(indexes
, CollationDataReader::IX_REORDER_CODES_OFFSET
);
39 printf(" reorder codes: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
42 length
= getDataLength(indexes
, CollationDataReader::IX_REORDER_TABLE_OFFSET
);
44 U_ASSERT(length
>= 256);
45 printf(" reorder table: %6ld\n", (long)length
);
48 length
= getDataLength(indexes
, CollationDataReader::IX_TRIE_OFFSET
);
50 printf(" trie size: %6ld\n", (long)length
);
53 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED8_OFFSET
);
55 printf(" reserved (offset 8): %6ld\n", (long)length
);
58 length
= getDataLength(indexes
, CollationDataReader::IX_CES_OFFSET
);
60 printf(" CEs: %6ld *8 = %6ld\n", (long)length
/ 8, (long)length
);
63 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED10_OFFSET
);
65 printf(" reserved (offset 10): %6ld\n", (long)length
);
68 length
= getDataLength(indexes
, CollationDataReader::IX_CE32S_OFFSET
);
70 printf(" CE32s: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
73 length
= getDataLength(indexes
, CollationDataReader::IX_ROOT_ELEMENTS_OFFSET
);
75 printf(" rootElements: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
78 length
= getDataLength(indexes
, CollationDataReader::IX_CONTEXTS_OFFSET
);
80 printf(" contexts: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
83 length
= getDataLength(indexes
, CollationDataReader::IX_UNSAFE_BWD_OFFSET
);
85 printf(" unsafeBwdSet: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
88 length
= getDataLength(indexes
, CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET
);
90 printf(" fastLatin table: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
93 length
= getDataLength(indexes
, CollationDataReader::IX_SCRIPTS_OFFSET
);
95 printf(" scripts data: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
98 length
= getDataLength(indexes
, CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET
);
100 U_ASSERT(length
>= 256);
101 printf(" compressibleBytes: %6ld\n", (long)length
);
104 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED18_OFFSET
);
106 printf(" reserved (offset 18): %6ld\n", (long)length
);
109 printf(" collator binary total size: %6ld\n", (long)sizeWithHeader
);
113 CollationInfo::getDataLength(const int32_t indexes
[], int32_t startIndex
) {
114 return indexes
[startIndex
+ 1] - indexes
[startIndex
];
118 CollationInfo::printReorderRanges(const CollationData
&data
, const int32_t *codes
, int32_t length
) {
119 UErrorCode errorCode
= U_ZERO_ERROR
;
120 UVector32
ranges(errorCode
);
121 data
.makeReorderRanges(codes
, length
, ranges
, errorCode
);
122 if(U_FAILURE(errorCode
)) {
123 printf(" error building reorder ranges: %s\n", u_errorName(errorCode
));
128 for(int32_t i
= 0; i
< ranges
.size(); ++i
) {
129 int32_t pair
= ranges
.elementAti(i
);
130 int32_t limit
= (pair
>> 16) & 0xffff;
131 int16_t offset
= (int16_t)pair
;
133 // [inclusive-start, exclusive-limit[
134 printf(" [%04x, %04x[\n", start
, limit
);
135 } else if(offset
> 0) {
136 printf(" reorder [%04x, %04x[ by offset %02x to [%04x, %04x[\n",
137 start
, limit
, offset
,
138 start
+ (offset
<< 8), limit
+ (offset
<< 8));
139 } else /* offset < 0 */ {
140 printf(" reorder [%04x, %04x[ by offset -%02x to [%04x, %04x[\n",
141 start
, limit
, -offset
,
142 start
+ (offset
<< 8), limit
+ (offset
<< 8));
150 #endif // !UCONFIG_NO_COLLATION