isomorfeus-ferret 0.12.6 → 0.12.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -4
  3. data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
  4. data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
  5. data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
  6. data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
  7. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
  8. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
  9. data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
  10. data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
  11. data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
  12. data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
  13. data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
  14. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
  15. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
  16. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
  17. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
  18. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
  19. data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
  20. data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
  21. data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
  22. data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
  23. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
  24. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
  25. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
  26. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
  27. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
  28. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
  29. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
  30. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
  31. data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
  32. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
  33. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
  34. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
  35. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
  36. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
  37. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
  38. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
  39. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
  40. data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
  41. data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
  42. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
  43. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
  44. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
  45. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
  46. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
  47. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
  48. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
  49. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
  50. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
  51. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
  52. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
  53. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
  54. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
  55. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
  56. data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
  57. data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
  58. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
  59. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
  60. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
  61. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
  62. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
  63. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
  64. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
  65. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
  66. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
  67. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
  68. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
  69. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
  70. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
  71. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
  72. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
  73. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
  74. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
  75. data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
  76. data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
  77. data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
  78. data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
  79. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
  80. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
  81. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
  82. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
  83. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
  84. data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
  85. data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
  86. data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
  87. data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
  88. data/ext/isomorfeus_ferret_ext/frb_index.c +35 -4
  89. data/ext/isomorfeus_ferret_ext/frt_document.h +1 -0
  90. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  91. data/ext/isomorfeus_ferret_ext/frt_index.c +174 -25
  92. data/ext/isomorfeus_ferret_ext/frt_index.h +6 -3
  93. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +1 -0
  94. data/ext/isomorfeus_ferret_ext/test_fields.c +57 -45
  95. data/ext/isomorfeus_ferret_ext/test_index.c +4 -1
  96. data/lib/isomorfeus/ferret/version.rb +1 -1
  97. metadata +88 -3
@@ -0,0 +1,291 @@
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 "brotli_common_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 - implicit trailing zero. */
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 const BrotliTransforms kBrotliTransforms = {
164
+ sizeof(kPrefixSuffix),
165
+ (const uint8_t*)kPrefixSuffix,
166
+ kPrefixSuffixMap,
167
+ sizeof(kTransformsData) / (3 * sizeof(kTransformsData[0])),
168
+ kTransformsData,
169
+ NULL, /* no extra parameters */
170
+ {0, 12, 27, 23, 42, 63, 56, 48, 59, 64}
171
+ };
172
+
173
+ const BrotliTransforms* BrotliGetTransforms(void) {
174
+ return &kBrotliTransforms;
175
+ }
176
+
177
+ static int ToUpperCase(uint8_t* p) {
178
+ if (p[0] < 0xC0) {
179
+ if (p[0] >= 'a' && p[0] <= 'z') {
180
+ p[0] ^= 32;
181
+ }
182
+ return 1;
183
+ }
184
+ /* An overly simplified uppercasing model for UTF-8. */
185
+ if (p[0] < 0xE0) {
186
+ p[1] ^= 32;
187
+ return 2;
188
+ }
189
+ /* An arbitrary transform for three byte characters. */
190
+ p[2] ^= 5;
191
+ return 3;
192
+ }
193
+
194
+ static int Shift(uint8_t* word, int word_len, uint16_t parameter) {
195
+ /* Limited sign extension: scalar < (1 << 24). */
196
+ uint32_t scalar =
197
+ (parameter & 0x7FFFu) + (0x1000000u - (parameter & 0x8000u));
198
+ if (word[0] < 0x80) {
199
+ /* 1-byte rune / 0sssssss / 7 bit scalar (ASCII). */
200
+ scalar += (uint32_t)word[0];
201
+ word[0] = (uint8_t)(scalar & 0x7Fu);
202
+ return 1;
203
+ } else if (word[0] < 0xC0) {
204
+ /* Continuation / 10AAAAAA. */
205
+ return 1;
206
+ } else if (word[0] < 0xE0) {
207
+ /* 2-byte rune / 110sssss AAssssss / 11 bit scalar. */
208
+ if (word_len < 2) return 1;
209
+ scalar += (uint32_t)((word[1] & 0x3Fu) | ((word[0] & 0x1Fu) << 6u));
210
+ word[0] = (uint8_t)(0xC0 | ((scalar >> 6u) & 0x1F));
211
+ word[1] = (uint8_t)((word[1] & 0xC0) | (scalar & 0x3F));
212
+ return 2;
213
+ } else if (word[0] < 0xF0) {
214
+ /* 3-byte rune / 1110ssss AAssssss BBssssss / 16 bit scalar. */
215
+ if (word_len < 3) return word_len;
216
+ scalar += (uint32_t)((word[2] & 0x3Fu) | ((word[1] & 0x3Fu) << 6u) |
217
+ ((word[0] & 0x0Fu) << 12u));
218
+ word[0] = (uint8_t)(0xE0 | ((scalar >> 12u) & 0x0F));
219
+ word[1] = (uint8_t)((word[1] & 0xC0) | ((scalar >> 6u) & 0x3F));
220
+ word[2] = (uint8_t)((word[2] & 0xC0) | (scalar & 0x3F));
221
+ return 3;
222
+ } else if (word[0] < 0xF8) {
223
+ /* 4-byte rune / 11110sss AAssssss BBssssss CCssssss / 21 bit scalar. */
224
+ if (word_len < 4) return word_len;
225
+ scalar += (uint32_t)((word[3] & 0x3Fu) | ((word[2] & 0x3Fu) << 6u) |
226
+ ((word[1] & 0x3Fu) << 12u) | ((word[0] & 0x07u) << 18u));
227
+ word[0] = (uint8_t)(0xF0 | ((scalar >> 18u) & 0x07));
228
+ word[1] = (uint8_t)((word[1] & 0xC0) | ((scalar >> 12u) & 0x3F));
229
+ word[2] = (uint8_t)((word[2] & 0xC0) | ((scalar >> 6u) & 0x3F));
230
+ word[3] = (uint8_t)((word[3] & 0xC0) | (scalar & 0x3F));
231
+ return 4;
232
+ }
233
+ return 1;
234
+ }
235
+
236
+ int BrotliTransformDictionaryWord(uint8_t* dst, const uint8_t* word, int len,
237
+ const BrotliTransforms* transforms, int transform_idx) {
238
+ int idx = 0;
239
+ const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
240
+ uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
241
+ const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
242
+ {
243
+ int prefix_len = *prefix++;
244
+ while (prefix_len--) { dst[idx++] = *prefix++; }
245
+ }
246
+ {
247
+ const int t = type;
248
+ int i = 0;
249
+ if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
250
+ len -= t;
251
+ } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
252
+ && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
253
+ int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
254
+ word += skip;
255
+ len -= skip;
256
+ }
257
+ while (i < len) { dst[idx++] = word[i++]; }
258
+ if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
259
+ ToUpperCase(&dst[idx - len]);
260
+ } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
261
+ uint8_t* uppercase = &dst[idx - len];
262
+ while (len > 0) {
263
+ int step = ToUpperCase(uppercase);
264
+ uppercase += step;
265
+ len -= step;
266
+ }
267
+ } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
268
+ uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
269
+ + (transforms->params[transform_idx * 2 + 1] << 8u));
270
+ Shift(&dst[idx - len], len, param);
271
+ } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
272
+ uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
273
+ + (transforms->params[transform_idx * 2 + 1] << 8u));
274
+ uint8_t* shift = &dst[idx - len];
275
+ while (len > 0) {
276
+ int step = Shift(shift, len, param);
277
+ shift += step;
278
+ len -= step;
279
+ }
280
+ }
281
+ }
282
+ {
283
+ int suffix_len = *suffix++;
284
+ while (suffix_len--) { dst[idx++] = *suffix++; }
285
+ return idx;
286
+ }
287
+ }
288
+
289
+ #if defined(__cplusplus) || defined(c_plusplus)
290
+ } /* extern "C" */
291
+ #endif
@@ -0,0 +1,85 @@
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_TRANSFORM_SHIFT_FIRST = 21,
41
+ BROTLI_TRANSFORM_SHIFT_ALL = 22,
42
+ BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */
43
+ };
44
+
45
+ #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
46
+
47
+ typedef struct BrotliTransforms {
48
+ uint16_t prefix_suffix_size;
49
+ /* Last character must be null, so prefix_suffix_size must be at least 1. */
50
+ const uint8_t* prefix_suffix;
51
+ const uint16_t* prefix_suffix_map;
52
+ uint32_t num_transforms;
53
+ /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
54
+ const uint8_t* transforms;
55
+ /* Shift for BROTLI_TRANSFORM_SHIFT_FIRST and BROTLI_TRANSFORM_SHIFT_ALL,
56
+ must be NULL if and only if no such transforms are present. */
57
+ const uint8_t* params;
58
+ /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
59
+ 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
60
+ -1, if cut-off transform does not exist. */
61
+ int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
62
+ } BrotliTransforms;
63
+
64
+ /* T is BrotliTransforms*; result is uint8_t. */
65
+ #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
66
+ #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1])
67
+ #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
68
+
69
+ /* T is BrotliTransforms*; result is const uint8_t*. */
70
+ #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
71
+ (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
72
+ #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
73
+ (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
74
+
75
+ BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
76
+
77
+ BROTLI_COMMON_API int BrotliTransformDictionaryWord(
78
+ uint8_t* dst, const uint8_t* word, int len,
79
+ const BrotliTransforms* transforms, int transform_idx);
80
+
81
+ #if defined(__cplusplus) || defined(c_plusplus)
82
+ } /* extern "C" */
83
+ #endif
84
+
85
+ #endif /* BROTLI_COMMON_TRANSFORM_H_ */
@@ -0,0 +1,26 @@
1
+ /* Copyright 2016 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
+ /* Version definition. */
8
+
9
+ #ifndef BROTLI_COMMON_VERSION_H_
10
+ #define BROTLI_COMMON_VERSION_H_
11
+
12
+ /* This macro should only be used when library is compiled together with client.
13
+ If library is dynamically linked, use BrotliDecoderVersion and
14
+ BrotliEncoderVersion methods. */
15
+
16
+ /* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */
17
+ #define BROTLI_VERSION 0x1000009
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 0x1009000
25
+
26
+ #endif /* BROTLI_COMMON_VERSION_H_ */
@@ -0,0 +1,76 @@
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
+ /* Bit reading helpers */
8
+
9
+ #include "brotli_dec_bit_reader.h"
10
+
11
+ #include "brotli_common_platform.h"
12
+ #include "brotli_types.h"
13
+
14
+ #if defined(__cplusplus) || defined(c_plusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ const uint32_t kBrotliBitMask[33] = { 0x00000000,
19
+ 0x00000001, 0x00000003, 0x00000007, 0x0000000F,
20
+ 0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF,
21
+ 0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF,
22
+ 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF,
23
+ 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, 0x000FFFFF,
24
+ 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, 0x00FFFFFF,
25
+ 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF,
26
+ 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
27
+ };
28
+
29
+ void BrotliInitBitReader(BrotliBitReader* const br) {
30
+ br->val_ = 0;
31
+ br->bit_pos_ = sizeof(br->val_) << 3;
32
+ }
33
+
34
+ BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) {
35
+ size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1;
36
+ /* Fixing alignment after unaligned BrotliFillWindow would result accumulator
37
+ overflow. If unalignment is caused by BrotliSafeReadBits, then there is
38
+ enough space in accumulator to fix alignment. */
39
+ if (!BROTLI_ALIGNED_READ) {
40
+ aligned_read_mask = 0;
41
+ }
42
+ if (BrotliGetAvailableBits(br) == 0) {
43
+ if (!BrotliPullByte(br)) {
44
+ return BROTLI_FALSE;
45
+ }
46
+ }
47
+
48
+ while ((((size_t)br->next_in) & aligned_read_mask) != 0) {
49
+ if (!BrotliPullByte(br)) {
50
+ /* If we consumed all the input, we don't care about the alignment. */
51
+ return BROTLI_TRUE;
52
+ }
53
+ }
54
+ return BROTLI_TRUE;
55
+ }
56
+
57
+ BROTLI_BOOL BrotliSafeReadBits32Slow(BrotliBitReader* const br,
58
+ uint32_t n_bits, uint32_t* val) {
59
+ uint32_t low_val;
60
+ uint32_t high_val;
61
+ BrotliBitReaderState memento;
62
+ BROTLI_DCHECK(n_bits <= 32);
63
+ BROTLI_DCHECK(n_bits > 24);
64
+ BrotliBitReaderSaveState(br, &memento);
65
+ if (!BrotliSafeReadBits(br, 16, &low_val) ||
66
+ !BrotliSafeReadBits(br, n_bits - 16, &high_val)) {
67
+ BrotliBitReaderRestoreState(br, &memento);
68
+ return BROTLI_FALSE;
69
+ }
70
+ *val = low_val | (high_val << 16);
71
+ return BROTLI_TRUE;
72
+ }
73
+
74
+ #if defined(__cplusplus) || defined(c_plusplus)
75
+ } /* extern "C" */
76
+ #endif