2019-03-07 01:55:38 +03:00
package brotli
const (
2019-03-16 04:00:20 +03:00
transformIdentity = 0
transformOmitLast1 = 1
transformOmitLast2 = 2
transformOmitLast3 = 3
transformOmitLast4 = 4
transformOmitLast5 = 5
transformOmitLast6 = 6
transformOmitLast7 = 7
transformOmitLast8 = 8
transformOmitLast9 = 9
transformUppercaseFirst = 10
transformUppercaseAll = 11
transformOmitFirst1 = 12
transformOmitFirst2 = 13
transformOmitFirst3 = 14
transformOmitFirst4 = 15
transformOmitFirst5 = 16
transformOmitFirst6 = 17
transformOmitFirst7 = 18
transformOmitFirst8 = 19
transformOmitFirst9 = 20
transformShiftFirst = 21
transformShiftAll = 22 + iota - 22
numTransformTypes
2019-03-07 01:55:38 +03:00
)
2019-03-16 04:00:20 +03:00
const transformsMaxCutOff = transformOmitLast9
2019-03-07 01:55:38 +03:00
2019-03-16 04:00:20 +03:00
type transforms struct {
2019-03-07 01:55:38 +03:00
prefix_suffix_size uint16
prefix_suffix [ ] byte
prefix_suffix_map [ ] uint16
num_transforms uint32
transforms [ ] byte
params [ ] byte
2019-03-16 04:00:20 +03:00
cutOffTransforms [ transformsMaxCutOff + 1 ] int16
2019-03-07 01:55:38 +03:00
}
2019-03-16 04:00:20 +03:00
func transformPrefixId ( t * transforms , I int ) byte {
2019-03-07 01:55:38 +03:00
return t . transforms [ ( I * 3 ) + 0 ]
}
2019-03-16 04:00:20 +03:00
func transformType ( t * transforms , I int ) byte {
2019-03-07 01:55:38 +03:00
return t . transforms [ ( I * 3 ) + 1 ]
}
2019-03-16 04:00:20 +03:00
func transformSuffixId ( t * transforms , I int ) byte {
2019-03-07 01:55:38 +03:00
return t . transforms [ ( I * 3 ) + 2 ]
}
2019-03-16 04:00:20 +03:00
func transformPrefix ( t * transforms , I int ) [ ] byte {
return t . prefix_suffix [ t . prefix_suffix_map [ transformPrefixId ( t , I ) ] : ]
2019-03-07 01:55:38 +03:00
}
2019-03-16 04:00:20 +03:00
func transformSuffix ( t * transforms , I int ) [ ] byte {
return t . prefix_suffix [ t . prefix_suffix_map [ transformSuffixId ( t , I ) ] : ]
2019-03-07 01:55:38 +03:00
}
/* RFC 7932 transforms string data */
2019-03-22 02:15:39 +03:00
const kPrefixSuffix string = "\001 \002, \010 of the \004 of \002s \001.\005 and \004 " + "in \001\"\004 to \002\">\001\n\002. \001]\005 for \003 a \006 " + "that \001'\006 with \006 from \004 by \001(\006. T" + "he \004 on \004 as \004 is \004ing \002\n\t\001:\003ed " + "\002=\"\004 at \003ly \001,\002='\005.com/\007. This \005" + " not \003er \003al \004ful \004ive \005less \004es" + "t \004ize \002\xc2\xa0\004ous \005 the \002e \000"
2019-03-07 01:55:38 +03:00
var kPrefixSuffixMap = [ 50 ] uint16 {
0x00 ,
0x02 ,
0x05 ,
0x0E ,
0x13 ,
0x16 ,
0x18 ,
0x1E ,
0x23 ,
0x25 ,
0x2A ,
0x2D ,
0x2F ,
0x32 ,
0x34 ,
0x3A ,
0x3E ,
0x45 ,
0x47 ,
0x4E ,
0x55 ,
0x5A ,
0x5C ,
0x63 ,
0x68 ,
0x6D ,
0x72 ,
0x77 ,
0x7A ,
0x7C ,
0x80 ,
0x83 ,
0x88 ,
0x8C ,
0x8E ,
0x91 ,
0x97 ,
0x9F ,
0xA5 ,
0xA9 ,
0xAD ,
0xB2 ,
0xB7 ,
0xBD ,
0xC2 ,
0xC7 ,
0xCA ,
0xCF ,
0xD5 ,
0xD8 ,
}
/* RFC 7932 transforms */
var kTransformsData = [ ] byte {
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst1 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
47 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
4 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
3 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
6 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst2 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast1 ,
2019-03-07 01:55:38 +03:00
49 ,
1 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
1 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
7 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
9 ,
48 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
8 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
5 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
10 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
11 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast3 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
13 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
14 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst3 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast2 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
15 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
16 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
12 ,
5 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
1 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst4 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
18 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
17 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
19 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
20 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst5 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst6 ,
2019-03-07 01:55:38 +03:00
49 ,
47 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast4 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
22 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
23 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
24 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
25 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast7 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast1 ,
2019-03-07 01:55:38 +03:00
26 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
27 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
28 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
12 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
29 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst9 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitFirst7 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast6 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
21 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
1 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast8 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
31 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
32 ,
47 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
3 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast5 ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformOmitLast9 ,
2019-03-07 01:55:38 +03:00
49 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
1 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
8 ,
5 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
21 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
10 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
30 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
5 ,
35 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
47 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
2 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
17 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
36 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
33 ,
5 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
21 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
5 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
37 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
30 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
38 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
0 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
39 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
49 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
34 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
8 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
12 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
21 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
40 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
12 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
41 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
42 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
17 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
43 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
5 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
10 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
34 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
33 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
44 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
5 ,
45 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
49 ,
0 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
33 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
30 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
30 ,
49 ,
2019-03-16 04:00:20 +03:00
transformIdentity ,
2019-03-07 01:55:38 +03:00
46 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
1 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
34 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
33 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
30 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
1 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
33 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
21 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
12 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
5 ,
49 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
34 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
12 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
30 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseAll ,
2019-03-07 01:55:38 +03:00
34 ,
0 ,
2019-03-16 04:00:20 +03:00
transformUppercaseFirst ,
2019-03-07 01:55:38 +03:00
34 ,
}
2019-03-16 04:00:20 +03:00
var kBrotliTransforms = transforms {
2019-03-07 01:55:38 +03:00
217 ,
[ ] byte ( kPrefixSuffix ) ,
kPrefixSuffixMap [ : ] ,
121 ,
kTransformsData ,
nil , /* no extra parameters */
2019-03-16 04:00:20 +03:00
[ transformsMaxCutOff + 1 ] int16 { 0 , 12 , 27 , 23 , 42 , 63 , 56 , 48 , 59 , 64 } ,
2019-03-07 01:55:38 +03:00
}
2019-03-16 04:00:20 +03:00
func getTransforms ( ) * transforms {
2019-03-07 01:55:38 +03:00
return & kBrotliTransforms
}
2019-03-16 04:00:20 +03:00
func toUpperCase ( p [ ] byte ) int {
2019-03-07 01:55:38 +03:00
if p [ 0 ] < 0xC0 {
if p [ 0 ] >= 'a' && p [ 0 ] <= 'z' {
p [ 0 ] ^ = 32
}
return 1
}
/* An overly simplified uppercasing model for UTF-8. */
if p [ 0 ] < 0xE0 {
p [ 1 ] ^ = 32
return 2
}
/* An arbitrary transform for three byte characters. */
p [ 2 ] ^ = 5
return 3
}
2019-03-16 04:00:20 +03:00
func shiftTransform ( word [ ] byte , word_len int , parameter uint16 ) int {
2019-03-07 01:55:38 +03:00
/* Limited sign extension: scalar < (1 << 24). */
var scalar uint32 = ( uint32 ( parameter ) & 0x7FFF ) + ( 0x1000000 - ( uint32 ( parameter ) & 0x8000 ) )
if word [ 0 ] < 0x80 {
/* 1-byte rune / 0sssssss / 7 bit scalar (ASCII). */
scalar += uint32 ( word [ 0 ] )
word [ 0 ] = byte ( scalar & 0x7F )
return 1
} else if word [ 0 ] < 0xC0 {
/* Continuation / 10AAAAAA. */
return 1
} else if word [ 0 ] < 0xE0 {
/* 2-byte rune / 110sssss AAssssss / 11 bit scalar. */
if word_len < 2 {
return 1
}
scalar += uint32 ( word [ 1 ] & 0x3F | ( word [ 0 ] & 0x1F ) << 6 )
word [ 0 ] = byte ( 0xC0 | ( scalar >> 6 ) & 0x1F )
word [ 1 ] = byte ( uint32 ( word [ 1 ] & 0xC0 ) | scalar & 0x3F )
return 2
} else if word [ 0 ] < 0xF0 {
/* 3-byte rune / 1110ssss AAssssss BBssssss / 16 bit scalar. */
if word_len < 3 {
return word_len
}
scalar += uint32 ( word [ 2 ] & 0x3F | ( word [ 1 ] & 0x3F ) << 6 | ( word [ 0 ] & 0x0F ) << 12 )
word [ 0 ] = byte ( 0xE0 | ( scalar >> 12 ) & 0x0F )
word [ 1 ] = byte ( uint32 ( word [ 1 ] & 0xC0 ) | ( scalar >> 6 ) & 0x3F )
word [ 2 ] = byte ( uint32 ( word [ 2 ] & 0xC0 ) | scalar & 0x3F )
return 3
} else if word [ 0 ] < 0xF8 {
/* 4-byte rune / 11110sss AAssssss BBssssss CCssssss / 21 bit scalar. */
if word_len < 4 {
return word_len
}
scalar += uint32 ( word [ 3 ] & 0x3F | ( word [ 2 ] & 0x3F ) << 6 | ( word [ 1 ] & 0x3F ) << 12 | ( word [ 0 ] & 0x07 ) << 18 )
word [ 0 ] = byte ( 0xF0 | ( scalar >> 18 ) & 0x07 )
word [ 1 ] = byte ( uint32 ( word [ 1 ] & 0xC0 ) | ( scalar >> 12 ) & 0x3F )
word [ 2 ] = byte ( uint32 ( word [ 2 ] & 0xC0 ) | ( scalar >> 6 ) & 0x3F )
word [ 3 ] = byte ( uint32 ( word [ 3 ] & 0xC0 ) | scalar & 0x3F )
return 4
}
return 1
}
2019-03-16 04:00:20 +03:00
func transformDictionaryWord ( dst [ ] byte , word [ ] byte , len int , trans * transforms , transform_idx int ) int {
2019-03-07 01:55:38 +03:00
var idx int = 0
2019-03-16 04:00:20 +03:00
var prefix [ ] byte = transformPrefix ( trans , transform_idx )
var type_ byte = transformType ( trans , transform_idx )
var suffix [ ] byte = transformSuffix ( trans , transform_idx )
2019-03-07 01:55:38 +03:00
{
var prefix_len int = int ( prefix [ 0 ] )
prefix = prefix [ 1 : ]
for {
tmp1 := prefix_len
prefix_len --
if tmp1 == 0 {
break
}
dst [ idx ] = prefix [ 0 ]
idx ++
prefix = prefix [ 1 : ]
}
}
{
var t int = int ( type_ )
var i int = 0
2019-03-16 04:00:20 +03:00
if t <= transformOmitLast9 {
2019-03-07 01:55:38 +03:00
len -= t
2019-03-16 04:00:20 +03:00
} else if t >= transformOmitFirst1 && t <= transformOmitFirst9 {
var skip int = t - ( transformOmitFirst1 - 1 )
2019-03-07 01:55:38 +03:00
word = word [ skip : ]
len -= skip
}
for i < len {
dst [ idx ] = word [ i ]
idx ++
i ++
}
2019-03-16 04:00:20 +03:00
if t == transformUppercaseFirst {
toUpperCase ( dst [ idx - len : ] )
} else if t == transformUppercaseAll {
2019-03-07 01:55:38 +03:00
var uppercase [ ] byte = dst
uppercase = uppercase [ idx - len : ]
for len > 0 {
2019-03-16 04:00:20 +03:00
var step int = toUpperCase ( uppercase )
2019-03-07 01:55:38 +03:00
uppercase = uppercase [ step : ]
len -= step
}
2019-03-16 04:00:20 +03:00
} else if t == transformShiftFirst {
var param uint16 = uint16 ( trans . params [ transform_idx * 2 ] + ( trans . params [ transform_idx * 2 + 1 ] << 8 ) )
shiftTransform ( dst [ idx - len : ] , int ( len ) , param )
} else if t == transformShiftAll {
var param uint16 = uint16 ( trans . params [ transform_idx * 2 ] + ( trans . params [ transform_idx * 2 + 1 ] << 8 ) )
2019-03-07 01:55:38 +03:00
var shift [ ] byte = dst
shift = shift [ idx - len : ]
for len > 0 {
2019-03-16 04:00:20 +03:00
var step int = shiftTransform ( shift , int ( len ) , param )
2019-03-07 01:55:38 +03:00
shift = shift [ step : ]
len -= step
}
}
}
{
var suffix_len int = int ( suffix [ 0 ] )
suffix = suffix [ 1 : ]
for {
tmp2 := suffix_len
suffix_len --
if tmp2 == 0 {
break
}
dst [ idx ] = suffix [ 0 ]
idx ++
suffix = suffix [ 1 : ]
}
return idx
}
}