1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Copyright (C) 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2013-2015, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* collationinfo.cpp
*
* created on: 2013aug05
* created by: Markus W. Scherer
*/
#include <stdio.h>
#include <string.h>
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
#include "collationdata.h"
#include "collationdatareader.h"
#include "collationinfo.h"
#include "uassert.h"
#include "uvectr32.h"
U_NAMESPACE_BEGIN
void
CollationInfo::printSizes(int32_t sizeWithHeader, const int32_t indexes[]) {
int32_t totalSize = indexes[CollationDataReader::IX_TOTAL_SIZE];
if(sizeWithHeader > totalSize) {
printf(" header size: %6ld\n", (long)(sizeWithHeader - totalSize));
}
int32_t length = indexes[CollationDataReader::IX_INDEXES_LENGTH];
printf(" indexes: %6ld *4 = %6ld\n", (long)length, (long)length * 4);
length = getDataLength(indexes, CollationDataReader::IX_REORDER_CODES_OFFSET);
if(length != 0) {
printf(" reorder codes: %6ld *4 = %6ld\n", (long)length / 4, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_REORDER_TABLE_OFFSET);
if(length != 0) {
U_ASSERT(length >= 256);
printf(" reorder table: %6ld\n", (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_TRIE_OFFSET);
if(length != 0) {
printf(" trie size: %6ld\n", (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_RESERVED8_OFFSET);
if(length != 0) {
printf(" reserved (offset 8): %6ld\n", (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_CES_OFFSET);
if(length != 0) {
printf(" CEs: %6ld *8 = %6ld\n", (long)length / 8, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_RESERVED10_OFFSET);
if(length != 0) {
printf(" reserved (offset 10): %6ld\n", (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_CE32S_OFFSET);
if(length != 0) {
printf(" CE32s: %6ld *4 = %6ld\n", (long)length / 4, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_ROOT_ELEMENTS_OFFSET);
if(length != 0) {
printf(" rootElements: %6ld *4 = %6ld\n", (long)length / 4, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_CONTEXTS_OFFSET);
if(length != 0) {
printf(" contexts: %6ld *2 = %6ld\n", (long)length / 2, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_UNSAFE_BWD_OFFSET);
if(length != 0) {
printf(" unsafeBwdSet: %6ld *2 = %6ld\n", (long)length / 2, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_FAST_LATIN_TABLE_OFFSET);
if(length != 0) {
printf(" fastLatin table: %6ld *2 = %6ld\n", (long)length / 2, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_SCRIPTS_OFFSET);
if(length != 0) {
printf(" scripts data: %6ld *2 = %6ld\n", (long)length / 2, (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_COMPRESSIBLE_BYTES_OFFSET);
if(length != 0) {
U_ASSERT(length >= 256);
printf(" compressibleBytes: %6ld\n", (long)length);
}
length = getDataLength(indexes, CollationDataReader::IX_RESERVED18_OFFSET);
if(length != 0) {
printf(" reserved (offset 18): %6ld\n", (long)length);
}
printf(" collator binary total size: %6ld\n", (long)sizeWithHeader);
}
int32_t
CollationInfo::getDataLength(const int32_t indexes[], int32_t startIndex) {
return indexes[startIndex + 1] - indexes[startIndex];
}
void
CollationInfo::printReorderRanges(const CollationData &data, const int32_t *codes, int32_t length) {
UErrorCode errorCode = U_ZERO_ERROR;
UVector32 ranges(errorCode);
data.makeReorderRanges(codes, length, ranges, errorCode);
if(U_FAILURE(errorCode)) {
printf(" error building reorder ranges: %s\n", u_errorName(errorCode));
return;
}
int32_t start = 0;
for(int32_t i = 0; i < ranges.size(); ++i) {
int32_t pair = ranges.elementAti(i);
int32_t limit = (pair >> 16) & 0xffff;
int16_t offset = (int16_t)pair;
if(offset == 0) {
// [inclusive-start, exclusive-limit[
printf(" [%04x, %04x[\n", start, limit);
} else if(offset > 0) {
printf(" reorder [%04x, %04x[ by offset %02x to [%04x, %04x[\n",
start, limit, offset,
start + (offset << 8), limit + (offset << 8));
} else /* offset < 0 */ {
printf(" reorder [%04x, %04x[ by offset -%02x to [%04x, %04x[\n",
start, limit, -offset,
start + (offset << 8), limit + (offset << 8));
}
start = limit;
}
}
U_NAMESPACE_END
#endif // !UCONFIG_NO_COLLATION
|