1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2013-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * created on: 2013aug05
11 * created by: Markus W. Scherer
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_COLLATION
21 #include "collationdata.h"
22 #include "collationdatareader.h"
23 #include "collationinfo.h"
30 CollationInfo::printSizes(int32_t sizeWithHeader
, const int32_t indexes
[]) {
31 int32_t totalSize
= indexes
[CollationDataReader::IX_TOTAL_SIZE
];
32 if(sizeWithHeader
> totalSize
) {
33 printf(" header size: %6ld\n", (long)(sizeWithHeader
- totalSize
));
36 int32_t length
= indexes
[CollationDataReader::IX_INDEXES_LENGTH
];
37 printf(" indexes: %6ld *4 = %6ld\n", (long)length
, (long)length
* 4);
39 length
= getDataLength(indexes
, CollationDataReader::IX_REORDER_CODES_OFFSET
);
41 printf(" reorder codes: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
44 length
= getDataLength(indexes
, CollationDataReader::IX_REORDER_TABLE_OFFSET
);
46 U_ASSERT(length
>= 256);
47 printf(" reorder table: %6ld\n", (long)length
);
50 length
= getDataLength(indexes
, CollationDataReader::IX_TRIE_OFFSET
);
52 printf(" trie size: %6ld\n", (long)length
);
55 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED8_OFFSET
);
57 printf(" reserved (offset 8): %6ld\n", (long)length
);
60 length
= getDataLength(indexes
, CollationDataReader::IX_CES_OFFSET
);
62 printf(" CEs: %6ld *8 = %6ld\n", (long)length
/ 8, (long)length
);
65 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED10_OFFSET
);
67 printf(" reserved (offset 10): %6ld\n", (long)length
);
70 length
= getDataLength(indexes
, CollationDataReader::IX_CE32S_OFFSET
);
72 printf(" CE32s: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
75 length
= getDataLength(indexes
, CollationDataReader::IX_ROOT_ELEMENTS_OFFSET
);
77 printf(" rootElements: %6ld *4 = %6ld\n", (long)length
/ 4, (long)length
);
80 length
= getDataLength(indexes
, CollationDataReader::IX_CONTEXTS_OFFSET
);
82 printf(" contexts: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
85 length
= getDataLength(indexes
, CollationDataReader::IX_UNSAFE_BWD_OFFSET
);
87 printf(" unsafeBwdSet: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
90 length
= getDataLength(indexes
, CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET
);
92 printf(" fastLatin table: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
95 length
= getDataLength(indexes
, CollationDataReader::IX_SCRIPTS_OFFSET
);
97 printf(" scripts data: %6ld *2 = %6ld\n", (long)length
/ 2, (long)length
);
100 length
= getDataLength(indexes
, CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET
);
102 U_ASSERT(length
>= 256);
103 printf(" compressibleBytes: %6ld\n", (long)length
);
106 length
= getDataLength(indexes
, CollationDataReader::IX_RESERVED18_OFFSET
);
108 printf(" reserved (offset 18): %6ld\n", (long)length
);
111 printf(" collator binary total size: %6ld\n", (long)sizeWithHeader
);
115 CollationInfo::getDataLength(const int32_t indexes
[], int32_t startIndex
) {
116 return indexes
[startIndex
+ 1] - indexes
[startIndex
];
120 CollationInfo::printReorderRanges(const CollationData
&data
, const int32_t *codes
, int32_t length
) {
121 UErrorCode errorCode
= U_ZERO_ERROR
;
122 UVector32
ranges(errorCode
);
123 data
.makeReorderRanges(codes
, length
, ranges
, errorCode
);
124 if(U_FAILURE(errorCode
)) {
125 printf(" error building reorder ranges: %s\n", u_errorName(errorCode
));
130 for(int32_t i
= 0; i
< ranges
.size(); ++i
) {
131 int32_t pair
= ranges
.elementAti(i
);
132 int32_t limit
= (pair
>> 16) & 0xffff;
133 int16_t offset
= (int16_t)pair
;
135 // [inclusive-start, exclusive-limit[
136 printf(" [%04x, %04x[\n", start
, limit
);
137 } else if(offset
> 0) {
138 printf(" reorder [%04x, %04x[ by offset %02x to [%04x, %04x[\n",
139 start
, limit
, offset
,
140 start
+ (offset
<< 8), limit
+ (offset
<< 8));
141 } else /* offset < 0 */ {
142 printf(" reorder [%04x, %04x[ by offset -%02x to [%04x, %04x[\n",
143 start
, limit
, -offset
,
144 start
+ (offset
<< 8), limit
+ (offset
<< 8));
152 #endif // !UCONFIG_NO_COLLATION