1 | # |
---|
2 | # Decoder input: transposed basis bit streams. |
---|
3 | # |
---|
4 | class Basis_bits(): |
---|
5 | bit0 = 0 |
---|
6 | bit1 = 0 |
---|
7 | bit2 = 0 |
---|
8 | bit3 = 0 |
---|
9 | bit4 = 0 |
---|
10 | bit5 = 0 |
---|
11 | bit6 = 0 |
---|
12 | bit7 = 0 |
---|
13 | |
---|
14 | class Decoded(): |
---|
15 | # The delmask marks bit stream positions that should be |
---|
16 | # considered deleted, i.e., positions at no corresponding |
---|
17 | # character data should be produced. |
---|
18 | delmask = 0 |
---|
19 | XML_error = 0 # 0x0-0x1F except HT, LF CR, 0xFFFE, 0xFFFF |
---|
20 | ch_error = 0 # Bad ASCII characters |
---|
21 | normalized_LF = 0 |
---|
22 | pseudo_bit0 = 0 |
---|
23 | |
---|
24 | u16hi_bit0 = 0 |
---|
25 | u16hi_bit1 = 0 |
---|
26 | u16hi_bit2 = 0 |
---|
27 | u16hi_bit3 = 0 |
---|
28 | u16hi_bit4 = 0 |
---|
29 | u16hi_bit5 = 0 |
---|
30 | u16hi_bit6 = 0 |
---|
31 | u16hi_bit7 = 0 |
---|
32 | |
---|
33 | u16lo_bit0 = 0 |
---|
34 | u16lo_bit1 = 0 |
---|
35 | u16lo_bit2 = 0 |
---|
36 | u16lo_bit3 = 0 |
---|
37 | u16lo_bit4 = 0 |
---|
38 | u16lo_bit5 = 0 |
---|
39 | u16lo_bit6 = 0 |
---|
40 | u16lo_bit7 = 0 |
---|
41 | |
---|
42 | def ascii_u16(basis_bits, decoded): |
---|
43 | temp1 = (basis_bits.bit0 | basis_bits.bit1) |
---|
44 | temp2 = (temp1 | basis_bits.bit2) |
---|
45 | x00_x1F = (~temp2) |
---|
46 | temp3 = (basis_bits.bit2 | basis_bits.bit3) |
---|
47 | temp4 = (temp1 | temp3) |
---|
48 | temp5 = (basis_bits.bit4 & basis_bits.bit5) |
---|
49 | temp6 = (basis_bits.bit7 &~ basis_bits.bit6) |
---|
50 | temp7 = (temp5 & temp6) |
---|
51 | CR = (temp7 &~ temp4) |
---|
52 | temp8 = (basis_bits.bit4 &~ basis_bits.bit5) |
---|
53 | temp9 = (basis_bits.bit6 &~ basis_bits.bit7) |
---|
54 | temp10 = (temp8 & temp9) |
---|
55 | LF = (temp10 &~ temp4) |
---|
56 | temp11 = (temp8 & temp6) |
---|
57 | HT = (temp11 &~ temp4) |
---|
58 | # |
---|
59 | decoded.XML_error = x00_x1F & ~(CR | HT | LF) |
---|
60 | decoded.ch_error = basis_bits.bit0 # Legal ASCII requires bit0 = 0 |
---|
61 | # |
---|
62 | decoded.u16hi_bit0 = 0 |
---|
63 | decoded.u16hi_bit1 = 0 |
---|
64 | decoded.u16hi_bit2 = 0 |
---|
65 | decoded.u16hi_bit3 = 0 |
---|
66 | decoded.u16hi_bit4 = 0 |
---|
67 | decoded.u16hi_bit5 = 0 |
---|
68 | decoded.u16hi_bit6 = 0 |
---|
69 | decoded.u16hi_bit7 = 0 |
---|
70 | decoded.u16lo_bit0 = 0 |
---|
71 | decoded.u16lo_bit1 = basis_bits.bit1 |
---|
72 | decoded.u16lo_bit2 = basis_bits.bit2 |
---|
73 | decoded.u16lo_bit3 = basis_bits.bit3 |
---|
74 | decoded.u16lo_bit4 = basis_bits.bit4 |
---|
75 | decoded.u16lo_bit5 = basis_bits.bit5 |
---|
76 | decoded.u16lo_bit6 = basis_bits.bit6 |
---|
77 | decoded.u16lo_bit7 = basis_bits.bit7 |
---|
78 | |
---|
79 | # |
---|
80 | # Line Break Normalization |
---|
81 | # Convert CRs to LFs (flip bits 5, 6 and 7 with xor). |
---|
82 | decoded.u16lo_bit5 ^= CR |
---|
83 | decoded.u16lo_bit6 ^= CR |
---|
84 | decoded.u16lo_bit7 ^= CR |
---|
85 | CRLF = bitutil.Advance(CR) & LF |
---|
86 | decoded.delmask = CRLF |
---|
87 | decoded.pseudo_bit0 = CR # Inverse transposition required |
---|
88 | decoded.normalized_LF = LF | CR |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|