brotli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -0
  3. data/Rakefile +6 -1
  4. data/brotli.gemspec +1 -1
  5. data/docs/Brotli.html +485 -0
  6. data/docs/Brotli/Error.html +124 -0
  7. data/docs/_index.html +122 -0
  8. data/docs/class_list.html +51 -0
  9. data/docs/css/common.css +1 -0
  10. data/docs/css/full_list.css +58 -0
  11. data/docs/css/style.css +496 -0
  12. data/docs/file.README.html +127 -0
  13. data/docs/file_list.html +56 -0
  14. data/docs/frames.html +17 -0
  15. data/docs/index.html +127 -0
  16. data/docs/js/app.js +292 -0
  17. data/docs/js/full_list.js +216 -0
  18. data/docs/js/jquery.js +4 -0
  19. data/docs/method_list.html +67 -0
  20. data/docs/top-level-namespace.html +110 -0
  21. data/ext/brotli/brotli.c +20 -0
  22. data/lib/brotli/version.rb +1 -1
  23. data/vendor/brotli/c/common/constants.h +13 -6
  24. data/vendor/brotli/c/{dec → common}/context.h +182 -172
  25. data/vendor/brotli/c/common/dictionary.bin +0 -0
  26. data/vendor/brotli/c/common/dictionary.bin.br +0 -0
  27. data/vendor/brotli/c/common/dictionary.c +1 -1
  28. data/vendor/brotli/c/common/dictionary.h +4 -4
  29. data/vendor/brotli/c/common/platform.h +509 -0
  30. data/vendor/brotli/c/common/transform.c +235 -0
  31. data/vendor/brotli/c/common/transform.h +80 -0
  32. data/vendor/brotli/c/common/version.h +8 -1
  33. data/vendor/brotli/c/dec/bit_reader.c +1 -1
  34. data/vendor/brotli/c/dec/bit_reader.h +35 -86
  35. data/vendor/brotli/c/dec/decode.c +322 -205
  36. data/vendor/brotli/c/dec/huffman.c +35 -37
  37. data/vendor/brotli/c/dec/huffman.h +13 -9
  38. data/vendor/brotli/c/dec/prefix.h +3 -4
  39. data/vendor/brotli/c/dec/state.c +26 -34
  40. data/vendor/brotli/c/dec/state.h +34 -23
  41. data/vendor/brotli/c/enc/backward_references.c +25 -15
  42. data/vendor/brotli/c/enc/backward_references.h +5 -6
  43. data/vendor/brotli/c/enc/backward_references_hq.c +94 -68
  44. data/vendor/brotli/c/enc/backward_references_hq.h +22 -25
  45. data/vendor/brotli/c/enc/backward_references_inc.h +10 -10
  46. data/vendor/brotli/c/enc/bit_cost.c +1 -1
  47. data/vendor/brotli/c/enc/bit_cost.h +5 -5
  48. data/vendor/brotli/c/enc/block_encoder_inc.h +7 -6
  49. data/vendor/brotli/c/enc/block_splitter.c +2 -3
  50. data/vendor/brotli/c/enc/block_splitter.h +1 -1
  51. data/vendor/brotli/c/enc/block_splitter_inc.h +11 -11
  52. data/vendor/brotli/c/enc/brotli_bit_stream.c +102 -101
  53. data/vendor/brotli/c/enc/brotli_bit_stream.h +19 -38
  54. data/vendor/brotli/c/enc/cluster.c +1 -1
  55. data/vendor/brotli/c/enc/cluster.h +1 -1
  56. data/vendor/brotli/c/enc/command.h +40 -30
  57. data/vendor/brotli/c/enc/compress_fragment.c +21 -22
  58. data/vendor/brotli/c/enc/compress_fragment.h +1 -1
  59. data/vendor/brotli/c/enc/compress_fragment_two_pass.c +101 -68
  60. data/vendor/brotli/c/enc/compress_fragment_two_pass.h +1 -1
  61. data/vendor/brotli/c/enc/dictionary_hash.c +1 -1
  62. data/vendor/brotli/c/enc/encode.c +262 -162
  63. data/vendor/brotli/c/enc/encoder_dict.c +32 -0
  64. data/vendor/brotli/c/enc/encoder_dict.h +41 -0
  65. data/vendor/brotli/c/enc/entropy_encode.c +14 -14
  66. data/vendor/brotli/c/enc/entropy_encode.h +5 -5
  67. data/vendor/brotli/c/enc/entropy_encode_static.h +3 -3
  68. data/vendor/brotli/c/enc/fast_log.h +4 -2
  69. data/vendor/brotli/c/enc/find_match_length.h +3 -3
  70. data/vendor/brotli/c/enc/hash.h +75 -24
  71. data/vendor/brotli/c/enc/hash_composite_inc.h +133 -0
  72. data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +9 -8
  73. data/vendor/brotli/c/enc/hash_longest_match64_inc.h +8 -8
  74. data/vendor/brotli/c/enc/hash_longest_match_inc.h +8 -8
  75. data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +10 -9
  76. data/vendor/brotli/c/enc/hash_rolling_inc.h +215 -0
  77. data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +9 -8
  78. data/vendor/brotli/c/enc/histogram.c +9 -6
  79. data/vendor/brotli/c/enc/histogram.h +6 -3
  80. data/vendor/brotli/c/enc/histogram_inc.h +1 -1
  81. data/vendor/brotli/c/enc/literal_cost.c +5 -5
  82. data/vendor/brotli/c/enc/literal_cost.h +2 -2
  83. data/vendor/brotli/c/enc/memory.c +5 -16
  84. data/vendor/brotli/c/enc/memory.h +40 -1
  85. data/vendor/brotli/c/enc/metablock.c +163 -25
  86. data/vendor/brotli/c/enc/metablock.h +13 -8
  87. data/vendor/brotli/c/enc/metablock_inc.h +1 -1
  88. data/vendor/brotli/c/enc/params.h +44 -0
  89. data/vendor/brotli/c/enc/prefix.h +3 -4
  90. data/vendor/brotli/c/enc/quality.h +29 -24
  91. data/vendor/brotli/c/enc/ringbuffer.h +15 -11
  92. data/vendor/brotli/c/enc/static_dict.c +49 -45
  93. data/vendor/brotli/c/enc/static_dict.h +4 -3
  94. data/vendor/brotli/c/enc/static_dict_lut.h +1 -1
  95. data/vendor/brotli/c/enc/utf8_util.c +20 -20
  96. data/vendor/brotli/c/enc/utf8_util.h +1 -1
  97. data/vendor/brotli/c/enc/write_bits.h +16 -21
  98. data/vendor/brotli/c/include/brotli/decode.h +13 -8
  99. data/vendor/brotli/c/include/brotli/encode.h +33 -8
  100. data/vendor/brotli/c/include/brotli/port.h +211 -83
  101. data/vendor/brotli/c/include/brotli/types.h +0 -7
  102. metadata +33 -12
  103. data/vendor/brotli/c/dec/port.h +0 -168
  104. data/vendor/brotli/c/dec/transform.h +0 -300
  105. data/vendor/brotli/c/enc/context.h +0 -184
  106. data/vendor/brotli/c/enc/port.h +0 -184
@@ -0,0 +1,235 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ #include "./transform.h"
8
+
9
+ #if defined(__cplusplus) || defined(c_plusplus)
10
+ extern "C" {
11
+ #endif
12
+
13
+ /* RFC 7932 transforms string data */
14
+ static const char kPrefixSuffix[217] =
15
+ "\1 \2, \10 of the \4 of \2s \1.\5 and \4 "
16
+ /* 0x _0 _2 __5 _E _3 _6 _8 _E */
17
+ "in \1\"\4 to \2\">\1\n\2. \1]\5 for \3 a \6 "
18
+ /* 2x _3_ _5 _A_ _D_ _F _2 _4 _A _E */
19
+ "that \1\'\6 with \6 from \4 by \1(\6. T"
20
+ /* 4x _5_ _7 _E _5 _A _C */
21
+ "he \4 on \4 as \4 is \4ing \2\n\t\1:\3ed "
22
+ /* 6x _3 _8 _D _2 _7_ _ _A _C */
23
+ "\2=\"\4 at \3ly \1,\2=\'\5.com/\7. This \5"
24
+ /* 8x _0 _ _3 _8 _C _E _ _1 _7 _F */
25
+ " not \3er \3al \4ful \4ive \5less \4es"
26
+ /* Ax _5 _9 _D _2 _7 _D */
27
+ "t \4ize \2\xc2\xa0\4ous \5 the \2e \0";
28
+ /* Cx _2 _7___ ___ _A _F _5 _8 */
29
+
30
+ static const uint16_t kPrefixSuffixMap[50] = {
31
+ 0x00, 0x02, 0x05, 0x0E, 0x13, 0x16, 0x18, 0x1E, 0x23, 0x25,
32
+ 0x2A, 0x2D, 0x2F, 0x32, 0x34, 0x3A, 0x3E, 0x45, 0x47, 0x4E,
33
+ 0x55, 0x5A, 0x5C, 0x63, 0x68, 0x6D, 0x72, 0x77, 0x7A, 0x7C,
34
+ 0x80, 0x83, 0x88, 0x8C, 0x8E, 0x91, 0x97, 0x9F, 0xA5, 0xA9,
35
+ 0xAD, 0xB2, 0xB7, 0xBD, 0xC2, 0xC7, 0xCA, 0xCF, 0xD5, 0xD8
36
+ };
37
+
38
+ /* RFC 7932 transforms */
39
+ static const uint8_t kTransformsData[] = {
40
+ 49, BROTLI_TRANSFORM_IDENTITY, 49,
41
+ 49, BROTLI_TRANSFORM_IDENTITY, 0,
42
+ 0, BROTLI_TRANSFORM_IDENTITY, 0,
43
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_1, 49,
44
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 0,
45
+ 49, BROTLI_TRANSFORM_IDENTITY, 47,
46
+ 0, BROTLI_TRANSFORM_IDENTITY, 49,
47
+ 4, BROTLI_TRANSFORM_IDENTITY, 0,
48
+ 49, BROTLI_TRANSFORM_IDENTITY, 3,
49
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 49,
50
+ 49, BROTLI_TRANSFORM_IDENTITY, 6,
51
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_2, 49,
52
+ 49, BROTLI_TRANSFORM_OMIT_LAST_1, 49,
53
+ 1, BROTLI_TRANSFORM_IDENTITY, 0,
54
+ 49, BROTLI_TRANSFORM_IDENTITY, 1,
55
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 0,
56
+ 49, BROTLI_TRANSFORM_IDENTITY, 7,
57
+ 49, BROTLI_TRANSFORM_IDENTITY, 9,
58
+ 48, BROTLI_TRANSFORM_IDENTITY, 0,
59
+ 49, BROTLI_TRANSFORM_IDENTITY, 8,
60
+ 49, BROTLI_TRANSFORM_IDENTITY, 5,
61
+ 49, BROTLI_TRANSFORM_IDENTITY, 10,
62
+ 49, BROTLI_TRANSFORM_IDENTITY, 11,
63
+ 49, BROTLI_TRANSFORM_OMIT_LAST_3, 49,
64
+ 49, BROTLI_TRANSFORM_IDENTITY, 13,
65
+ 49, BROTLI_TRANSFORM_IDENTITY, 14,
66
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_3, 49,
67
+ 49, BROTLI_TRANSFORM_OMIT_LAST_2, 49,
68
+ 49, BROTLI_TRANSFORM_IDENTITY, 15,
69
+ 49, BROTLI_TRANSFORM_IDENTITY, 16,
70
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 49,
71
+ 49, BROTLI_TRANSFORM_IDENTITY, 12,
72
+ 5, BROTLI_TRANSFORM_IDENTITY, 49,
73
+ 0, BROTLI_TRANSFORM_IDENTITY, 1,
74
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_4, 49,
75
+ 49, BROTLI_TRANSFORM_IDENTITY, 18,
76
+ 49, BROTLI_TRANSFORM_IDENTITY, 17,
77
+ 49, BROTLI_TRANSFORM_IDENTITY, 19,
78
+ 49, BROTLI_TRANSFORM_IDENTITY, 20,
79
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_5, 49,
80
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_6, 49,
81
+ 47, BROTLI_TRANSFORM_IDENTITY, 49,
82
+ 49, BROTLI_TRANSFORM_OMIT_LAST_4, 49,
83
+ 49, BROTLI_TRANSFORM_IDENTITY, 22,
84
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 49,
85
+ 49, BROTLI_TRANSFORM_IDENTITY, 23,
86
+ 49, BROTLI_TRANSFORM_IDENTITY, 24,
87
+ 49, BROTLI_TRANSFORM_IDENTITY, 25,
88
+ 49, BROTLI_TRANSFORM_OMIT_LAST_7, 49,
89
+ 49, BROTLI_TRANSFORM_OMIT_LAST_1, 26,
90
+ 49, BROTLI_TRANSFORM_IDENTITY, 27,
91
+ 49, BROTLI_TRANSFORM_IDENTITY, 28,
92
+ 0, BROTLI_TRANSFORM_IDENTITY, 12,
93
+ 49, BROTLI_TRANSFORM_IDENTITY, 29,
94
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_9, 49,
95
+ 49, BROTLI_TRANSFORM_OMIT_FIRST_7, 49,
96
+ 49, BROTLI_TRANSFORM_OMIT_LAST_6, 49,
97
+ 49, BROTLI_TRANSFORM_IDENTITY, 21,
98
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 1,
99
+ 49, BROTLI_TRANSFORM_OMIT_LAST_8, 49,
100
+ 49, BROTLI_TRANSFORM_IDENTITY, 31,
101
+ 49, BROTLI_TRANSFORM_IDENTITY, 32,
102
+ 47, BROTLI_TRANSFORM_IDENTITY, 3,
103
+ 49, BROTLI_TRANSFORM_OMIT_LAST_5, 49,
104
+ 49, BROTLI_TRANSFORM_OMIT_LAST_9, 49,
105
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 1,
106
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 8,
107
+ 5, BROTLI_TRANSFORM_IDENTITY, 21,
108
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 0,
109
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 10,
110
+ 49, BROTLI_TRANSFORM_IDENTITY, 30,
111
+ 0, BROTLI_TRANSFORM_IDENTITY, 5,
112
+ 35, BROTLI_TRANSFORM_IDENTITY, 49,
113
+ 47, BROTLI_TRANSFORM_IDENTITY, 2,
114
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 17,
115
+ 49, BROTLI_TRANSFORM_IDENTITY, 36,
116
+ 49, BROTLI_TRANSFORM_IDENTITY, 33,
117
+ 5, BROTLI_TRANSFORM_IDENTITY, 0,
118
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 21,
119
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 5,
120
+ 49, BROTLI_TRANSFORM_IDENTITY, 37,
121
+ 0, BROTLI_TRANSFORM_IDENTITY, 30,
122
+ 49, BROTLI_TRANSFORM_IDENTITY, 38,
123
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 0,
124
+ 49, BROTLI_TRANSFORM_IDENTITY, 39,
125
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 49,
126
+ 49, BROTLI_TRANSFORM_IDENTITY, 34,
127
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 8,
128
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 12,
129
+ 0, BROTLI_TRANSFORM_IDENTITY, 21,
130
+ 49, BROTLI_TRANSFORM_IDENTITY, 40,
131
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 12,
132
+ 49, BROTLI_TRANSFORM_IDENTITY, 41,
133
+ 49, BROTLI_TRANSFORM_IDENTITY, 42,
134
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 17,
135
+ 49, BROTLI_TRANSFORM_IDENTITY, 43,
136
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 5,
137
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 10,
138
+ 0, BROTLI_TRANSFORM_IDENTITY, 34,
139
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 33,
140
+ 49, BROTLI_TRANSFORM_IDENTITY, 44,
141
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 5,
142
+ 45, BROTLI_TRANSFORM_IDENTITY, 49,
143
+ 0, BROTLI_TRANSFORM_IDENTITY, 33,
144
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 30,
145
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 30,
146
+ 49, BROTLI_TRANSFORM_IDENTITY, 46,
147
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 1,
148
+ 49, BROTLI_TRANSFORM_UPPERCASE_FIRST, 34,
149
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 33,
150
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 30,
151
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 1,
152
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 33,
153
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 21,
154
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 12,
155
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 5,
156
+ 49, BROTLI_TRANSFORM_UPPERCASE_ALL, 34,
157
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 12,
158
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 30,
159
+ 0, BROTLI_TRANSFORM_UPPERCASE_ALL, 34,
160
+ 0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 34,
161
+ };
162
+
163
+ static BrotliTransforms kBrotliTransforms = {
164
+ sizeof(kPrefixSuffix),
165
+ (const uint8_t*)kPrefixSuffix,
166
+ kPrefixSuffixMap,
167
+ sizeof(kTransformsData) / (3 * sizeof(kTransformsData[0])),
168
+ kTransformsData,
169
+ {0, 12, 27, 23, 42, 63, 56, 48, 59, 64}
170
+ };
171
+
172
+ const BrotliTransforms* BrotliGetTransforms(void) {
173
+ return &kBrotliTransforms;
174
+ }
175
+
176
+ static int ToUpperCase(uint8_t* p) {
177
+ if (p[0] < 0xC0) {
178
+ if (p[0] >= 'a' && p[0] <= 'z') {
179
+ p[0] ^= 32;
180
+ }
181
+ return 1;
182
+ }
183
+ /* An overly simplified uppercasing model for UTF-8. */
184
+ if (p[0] < 0xE0) {
185
+ p[1] ^= 32;
186
+ return 2;
187
+ }
188
+ /* An arbitrary transform for three byte characters. */
189
+ p[2] ^= 5;
190
+ return 3;
191
+ }
192
+
193
+ int BrotliTransformDictionaryWord(uint8_t* dst, const uint8_t* word, int len,
194
+ const BrotliTransforms* transforms, int transfom_idx) {
195
+ int idx = 0;
196
+ const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transfom_idx);
197
+ uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transfom_idx);
198
+ const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transfom_idx);
199
+ {
200
+ int prefix_len = *prefix++;
201
+ while (prefix_len--) { dst[idx++] = *prefix++; }
202
+ }
203
+ {
204
+ const int t = type;
205
+ int i = 0;
206
+ if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
207
+ len -= t;
208
+ } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
209
+ && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
210
+ int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
211
+ word += skip;
212
+ len -= skip;
213
+ }
214
+ while (i < len) { dst[idx++] = word[i++]; }
215
+ if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
216
+ ToUpperCase(&dst[idx - len]);
217
+ } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
218
+ uint8_t* uppercase = &dst[idx - len];
219
+ while (len > 0) {
220
+ int step = ToUpperCase(uppercase);
221
+ uppercase += step;
222
+ len -= step;
223
+ }
224
+ }
225
+ }
226
+ {
227
+ int suffix_len = *suffix++;
228
+ while (suffix_len--) { dst[idx++] = *suffix++; }
229
+ return idx;
230
+ }
231
+ }
232
+
233
+ #if defined(__cplusplus) || defined(c_plusplus)
234
+ } /* extern "C" */
235
+ #endif
@@ -0,0 +1,80 @@
1
+ /* transforms is a part of ABI, but not API.
2
+
3
+ It means that there are some functions that are supposed to be in "common"
4
+ library, but header itself is not placed into include/brotli. This way,
5
+ aforementioned functions will be available only to brotli internals.
6
+ */
7
+
8
+ #ifndef BROTLI_COMMON_TRANSFORM_H_
9
+ #define BROTLI_COMMON_TRANSFORM_H_
10
+
11
+ #include <brotli/port.h>
12
+ #include <brotli/types.h>
13
+
14
+ #if defined(__cplusplus) || defined(c_plusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ enum BrotliWordTransformType {
19
+ BROTLI_TRANSFORM_IDENTITY = 0,
20
+ BROTLI_TRANSFORM_OMIT_LAST_1 = 1,
21
+ BROTLI_TRANSFORM_OMIT_LAST_2 = 2,
22
+ BROTLI_TRANSFORM_OMIT_LAST_3 = 3,
23
+ BROTLI_TRANSFORM_OMIT_LAST_4 = 4,
24
+ BROTLI_TRANSFORM_OMIT_LAST_5 = 5,
25
+ BROTLI_TRANSFORM_OMIT_LAST_6 = 6,
26
+ BROTLI_TRANSFORM_OMIT_LAST_7 = 7,
27
+ BROTLI_TRANSFORM_OMIT_LAST_8 = 8,
28
+ BROTLI_TRANSFORM_OMIT_LAST_9 = 9,
29
+ BROTLI_TRANSFORM_UPPERCASE_FIRST = 10,
30
+ BROTLI_TRANSFORM_UPPERCASE_ALL = 11,
31
+ BROTLI_TRANSFORM_OMIT_FIRST_1 = 12,
32
+ BROTLI_TRANSFORM_OMIT_FIRST_2 = 13,
33
+ BROTLI_TRANSFORM_OMIT_FIRST_3 = 14,
34
+ BROTLI_TRANSFORM_OMIT_FIRST_4 = 15,
35
+ BROTLI_TRANSFORM_OMIT_FIRST_5 = 16,
36
+ BROTLI_TRANSFORM_OMIT_FIRST_6 = 17,
37
+ BROTLI_TRANSFORM_OMIT_FIRST_7 = 18,
38
+ BROTLI_TRANSFORM_OMIT_FIRST_8 = 19,
39
+ BROTLI_TRANSFORM_OMIT_FIRST_9 = 20,
40
+ BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */
41
+ };
42
+
43
+ #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
44
+
45
+ typedef struct BrotliTransforms {
46
+ uint16_t prefix_suffix_size;
47
+ /* Last character must be null, so prefix_suffix_size must be at least 1. */
48
+ const uint8_t* prefix_suffix;
49
+ const uint16_t* prefix_suffix_map;
50
+ uint32_t num_transforms;
51
+ /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
52
+ const uint8_t* transforms;
53
+ /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
54
+ 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
55
+ -1, if cut-off transform does not exist. */
56
+ int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
57
+ } BrotliTransforms;
58
+
59
+ /* T is BrotliTransforms*; result is uint8_t. */
60
+ #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
61
+ #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1])
62
+ #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
63
+
64
+ /* T is BrotliTransforms*; result is const uint8_t*. */
65
+ #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
66
+ (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
67
+ #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
68
+ (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
69
+
70
+ BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
71
+
72
+ BROTLI_COMMON_API int BrotliTransformDictionaryWord(
73
+ uint8_t* dst, const uint8_t* word, int len,
74
+ const BrotliTransforms* transforms, int transform_idx);
75
+
76
+ #if defined(__cplusplus) || defined(c_plusplus)
77
+ } /* extern "C" */
78
+ #endif
79
+
80
+ #endif /* BROTLI_COMMON_TRANSFORM_H_ */
@@ -14,6 +14,13 @@
14
14
  BrotliEncoderVersion methods. */
15
15
 
16
16
  /* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */
17
- #define BROTLI_VERSION 0x1000001
17
+ #define BROTLI_VERSION 0x1000005
18
+
19
+ /* This macro is used by build system to produce Libtool-friendly soname. See
20
+ https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
21
+ */
22
+
23
+ /* ABI version, calculated as (CURRENT << 24) | (REVISION << 12) | AGE */
24
+ #define BROTLI_ABI_VERSION 0x1005000
18
25
 
19
26
  #endif /* BROTLI_COMMON_VERSION_H_ */
@@ -8,8 +8,8 @@
8
8
 
9
9
  #include "./bit_reader.h"
10
10
 
11
+ #include "../common/platform.h"
11
12
  #include <brotli/types.h>
12
- #include "./port.h"
13
13
 
14
14
  #if defined(__cplusplus) || defined(c_plusplus)
15
15
  extern "C" {
@@ -11,16 +11,16 @@
11
11
 
12
12
  #include <string.h> /* memcpy */
13
13
 
14
+ #include "../common/platform.h"
14
15
  #include <brotli/types.h>
15
- #include "./port.h"
16
16
 
17
17
  #if defined(__cplusplus) || defined(c_plusplus)
18
18
  extern "C" {
19
19
  #endif
20
20
 
21
- #define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(reg_t) >> 1)
21
+ #define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
22
22
 
23
- static const uint32_t kBitMask[33] = { 0x0000,
23
+ static const uint32_t kBitMask[33] = { 0x00000000,
24
24
  0x00000001, 0x00000003, 0x00000007, 0x0000000F,
25
25
  0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF,
26
26
  0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF,
@@ -32,24 +32,24 @@ static const uint32_t kBitMask[33] = { 0x0000,
32
32
  };
33
33
 
34
34
  static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
35
- if (IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
35
+ if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
36
36
  /* Masking with this expression turns to a single
37
37
  "Unsigned Bit Field Extract" UBFX instruction on ARM. */
38
- return ~((0xffffffffU) << n);
38
+ return ~((0xFFFFFFFFu) << n);
39
39
  } else {
40
40
  return kBitMask[n];
41
41
  }
42
42
  }
43
43
 
44
44
  typedef struct {
45
- reg_t val_; /* pre-fetched bits */
45
+ brotli_reg_t val_; /* pre-fetched bits */
46
46
  uint32_t bit_pos_; /* current bit-reading position in val_ */
47
47
  const uint8_t* next_in; /* the byte we're reading from */
48
48
  size_t avail_in;
49
49
  } BrotliBitReader;
50
50
 
51
51
  typedef struct {
52
- reg_t val_;
52
+ brotli_reg_t val_;
53
53
  uint32_t bit_pos_;
54
54
  const uint8_t* next_in;
55
55
  size_t avail_in;
@@ -58,8 +58,9 @@ typedef struct {
58
58
  /* Initializes the BrotliBitReader fields. */
59
59
  BROTLI_INTERNAL void BrotliInitBitReader(BrotliBitReader* const br);
60
60
 
61
- /* Ensures that accumulator is not empty. May consume one byte of input.
62
- Returns 0 if data is required but there is no input available.
61
+ /* Ensures that accumulator is not empty.
62
+ May consume up to sizeof(brotli_reg_t) - 1 bytes of input.
63
+ Returns BROTLI_FALSE if data is required but there is no input available.
63
64
  For BROTLI_ALIGNED_READ this function also prepares bit reader for aligned
64
65
  reading. */
65
66
  BROTLI_INTERNAL BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br);
@@ -98,82 +99,27 @@ static BROTLI_INLINE BROTLI_BOOL BrotliCheckInputAmount(
98
99
  return TO_BROTLI_BOOL(br->avail_in >= num);
99
100
  }
100
101
 
101
- static BROTLI_INLINE uint16_t BrotliLoad16LE(const uint8_t* in) {
102
- if (BROTLI_LITTLE_ENDIAN) {
103
- return *((const uint16_t*)in);
104
- } else if (BROTLI_BIG_ENDIAN) {
105
- uint16_t value = *((const uint16_t*)in);
106
- return (uint16_t)(((value & 0xFFU) << 8) | ((value & 0xFF00U) >> 8));
107
- } else {
108
- return (uint16_t)(in[0] | (in[1] << 8));
109
- }
110
- }
111
-
112
- static BROTLI_INLINE uint32_t BrotliLoad32LE(const uint8_t* in) {
113
- if (BROTLI_LITTLE_ENDIAN) {
114
- return *((const uint32_t*)in);
115
- } else if (BROTLI_BIG_ENDIAN) {
116
- uint32_t value = *((const uint32_t*)in);
117
- return ((value & 0xFFU) << 24) | ((value & 0xFF00U) << 8) |
118
- ((value & 0xFF0000U) >> 8) | ((value & 0xFF000000U) >> 24);
119
- } else {
120
- uint32_t value = (uint32_t)(*(in++));
121
- value |= (uint32_t)(*(in++)) << 8;
122
- value |= (uint32_t)(*(in++)) << 16;
123
- value |= (uint32_t)(*(in++)) << 24;
124
- return value;
125
- }
126
- }
127
-
128
- #if (BROTLI_64_BITS)
129
- static BROTLI_INLINE uint64_t BrotliLoad64LE(const uint8_t* in) {
130
- if (BROTLI_LITTLE_ENDIAN) {
131
- return *((const uint64_t*)in);
132
- } else if (BROTLI_BIG_ENDIAN) {
133
- uint64_t value = *((const uint64_t*)in);
134
- return
135
- ((value & 0xFFU) << 56) |
136
- ((value & 0xFF00U) << 40) |
137
- ((value & 0xFF0000U) << 24) |
138
- ((value & 0xFF000000U) << 8) |
139
- ((value & 0xFF00000000U) >> 8) |
140
- ((value & 0xFF0000000000U) >> 24) |
141
- ((value & 0xFF000000000000U) >> 40) |
142
- ((value & 0xFF00000000000000U) >> 56);
143
- } else {
144
- uint64_t value = (uint64_t)(*(in++));
145
- value |= (uint64_t)(*(in++)) << 8;
146
- value |= (uint64_t)(*(in++)) << 16;
147
- value |= (uint64_t)(*(in++)) << 24;
148
- value |= (uint64_t)(*(in++)) << 32;
149
- value |= (uint64_t)(*(in++)) << 40;
150
- value |= (uint64_t)(*(in++)) << 48;
151
- value |= (uint64_t)(*(in++)) << 56;
152
- return value;
153
- }
154
- }
155
- #endif
156
-
157
- /* Guarantees that there are at least n_bits + 1 bits in accumulator.
102
+ /* Guarantees that there are at least |n_bits| + 1 bits in accumulator.
158
103
  Precondition: accumulator contains at least 1 bit.
159
- n_bits should be in the range [1..24] for regular build. For portable
104
+ |n_bits| should be in the range [1..24] for regular build. For portable
160
105
  non-64-bit little-endian build only 16 bits are safe to request. */
161
106
  static BROTLI_INLINE void BrotliFillBitWindow(
162
107
  BrotliBitReader* const br, uint32_t n_bits) {
163
108
  #if (BROTLI_64_BITS)
164
- if (!BROTLI_ALIGNED_READ && IS_CONSTANT(n_bits) && (n_bits <= 8)) {
109
+ if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
165
110
  if (br->bit_pos_ >= 56) {
166
111
  br->val_ >>= 56;
167
112
  br->bit_pos_ ^= 56; /* here same as -= 56 because of the if condition */
168
- br->val_ |= BrotliLoad64LE(br->next_in) << 8;
113
+ br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
169
114
  br->avail_in -= 7;
170
115
  br->next_in += 7;
171
116
  }
172
- } else if (!BROTLI_ALIGNED_READ && IS_CONSTANT(n_bits) && (n_bits <= 16)) {
117
+ } else if (
118
+ !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
173
119
  if (br->bit_pos_ >= 48) {
174
120
  br->val_ >>= 48;
175
121
  br->bit_pos_ ^= 48; /* here same as -= 48 because of the if condition */
176
- br->val_ |= BrotliLoad64LE(br->next_in) << 16;
122
+ br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
177
123
  br->avail_in -= 6;
178
124
  br->next_in += 6;
179
125
  }
@@ -181,17 +127,17 @@ static BROTLI_INLINE void BrotliFillBitWindow(
181
127
  if (br->bit_pos_ >= 32) {
182
128
  br->val_ >>= 32;
183
129
  br->bit_pos_ ^= 32; /* here same as -= 32 because of the if condition */
184
- br->val_ |= ((uint64_t)BrotliLoad32LE(br->next_in)) << 32;
130
+ br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
185
131
  br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
186
132
  br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
187
133
  }
188
134
  }
189
135
  #else
190
- if (!BROTLI_ALIGNED_READ && IS_CONSTANT(n_bits) && (n_bits <= 8)) {
136
+ if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
191
137
  if (br->bit_pos_ >= 24) {
192
138
  br->val_ >>= 24;
193
139
  br->bit_pos_ ^= 24; /* here same as -= 24 because of the if condition */
194
- br->val_ |= BrotliLoad32LE(br->next_in) << 8;
140
+ br->val_ |= BROTLI_UNALIGNED_LOAD32LE(br->next_in) << 8;
195
141
  br->avail_in -= 3;
196
142
  br->next_in += 3;
197
143
  }
@@ -199,7 +145,7 @@ static BROTLI_INLINE void BrotliFillBitWindow(
199
145
  if (br->bit_pos_ >= 16) {
200
146
  br->val_ >>= 16;
201
147
  br->bit_pos_ ^= 16; /* here same as -= 16 because of the if condition */
202
- br->val_ |= ((uint32_t)BrotliLoad16LE(br->next_in)) << 16;
148
+ br->val_ |= ((uint32_t)BROTLI_UNALIGNED_LOAD16LE(br->next_in)) << 16;
203
149
  br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
204
150
  br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
205
151
  }
@@ -213,7 +159,8 @@ static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
213
159
  BrotliFillBitWindow(br, 17);
214
160
  }
215
161
 
216
- /* Pulls one byte of input to accumulator. */
162
+ /* Tries to pull one byte of input to accumulator.
163
+ Returns BROTLI_FALSE if there is no input available. */
217
164
  static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
218
165
  if (br->avail_in == 0) {
219
166
  return BROTLI_FALSE;
@@ -232,7 +179,8 @@ static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
232
179
 
233
180
  /* Returns currently available bits.
234
181
  The number of valid bits could be calculated by BrotliGetAvailableBits. */
235
- static BROTLI_INLINE reg_t BrotliGetBitsUnmasked(BrotliBitReader* const br) {
182
+ static BROTLI_INLINE brotli_reg_t BrotliGetBitsUnmasked(
183
+ BrotliBitReader* const br) {
236
184
  return br->val_ >> br->bit_pos_;
237
185
  }
238
186
 
@@ -244,15 +192,16 @@ static BROTLI_INLINE uint32_t BrotliGet16BitsUnmasked(
244
192
  return (uint32_t)BrotliGetBitsUnmasked(br);
245
193
  }
246
194
 
247
- /* Returns the specified number of bits from |br| without advancing bit pos. */
195
+ /* Returns the specified number of bits from |br| without advancing bit
196
+ position. */
248
197
  static BROTLI_INLINE uint32_t BrotliGetBits(
249
198
  BrotliBitReader* const br, uint32_t n_bits) {
250
199
  BrotliFillBitWindow(br, n_bits);
251
200
  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
252
201
  }
253
202
 
254
- /* Tries to peek the specified amount of bits. Returns 0, if there is not
255
- enough input. */
203
+ /* Tries to peek the specified amount of bits. Returns BROTLI_FALSE, if there
204
+ is not enough input. */
256
205
  static BROTLI_INLINE BROTLI_BOOL BrotliSafeGetBits(
257
206
  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
258
207
  while (BrotliGetAvailableBits(br) < n_bits) {
@@ -264,7 +213,7 @@ static BROTLI_INLINE BROTLI_BOOL BrotliSafeGetBits(
264
213
  return BROTLI_TRUE;
265
214
  }
266
215
 
267
- /* Advances the bit pos by n_bits. */
216
+ /* Advances the bit pos by |n_bits|. */
268
217
  static BROTLI_INLINE void BrotliDropBits(
269
218
  BrotliBitReader* const br, uint32_t n_bits) {
270
219
  br->bit_pos_ += n_bits;
@@ -284,12 +233,12 @@ static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
284
233
  }
285
234
 
286
235
  /* Reads the specified number of bits from |br| and advances the bit pos.
287
- Precondition: accumulator MUST contain at least n_bits. */
236
+ Precondition: accumulator MUST contain at least |n_bits|. */
288
237
  static BROTLI_INLINE void BrotliTakeBits(
289
238
  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
290
239
  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
291
240
  BROTLI_LOG(("[BrotliReadBits] %d %d %d val: %6x\n",
292
- (int)br->avail_in, (int)br->bit_pos_, n_bits, (int)*val));
241
+ (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
293
242
  BrotliDropBits(br, n_bits);
294
243
  }
295
244
 
@@ -313,8 +262,8 @@ static BROTLI_INLINE uint32_t BrotliReadBits(
313
262
  }
314
263
  }
315
264
 
316
- /* Tries to read the specified amount of bits. Returns 0, if there is not
317
- enough input. n_bits MUST be positive. */
265
+ /* Tries to read the specified amount of bits. Returns BROTLI_FALSE, if there
266
+ is not enough input. |n_bits| MUST be positive. */
318
267
  static BROTLI_INLINE BROTLI_BOOL BrotliSafeReadBits(
319
268
  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
320
269
  while (BrotliGetAvailableBits(br) < n_bits) {
@@ -338,7 +287,7 @@ static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
338
287
  }
339
288
 
340
289
  /* Copies remaining input bytes stored in the bit reader to the output. Value
341
- num may not be larger than BrotliGetRemainingBytes. The bit reader must be
290
+ |num| may not be larger than BrotliGetRemainingBytes. The bit reader must be
342
291
  warmed up again after this. */
343
292
  static BROTLI_INLINE void BrotliCopyBytes(uint8_t* dest,
344
293
  BrotliBitReader* br, size_t num) {