[774] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | |
---|
[1822] | 3 | |
---|
| 4 | class u8_bits(): |
---|
| 5 | bit_0 = 0 |
---|
| 6 | bit_1 = 0 |
---|
| 7 | bit_2 = 0 |
---|
| 8 | bit_3 = 0 |
---|
| 9 | bit_4 = 0 |
---|
| 10 | bit_5 = 0 |
---|
| 11 | bit_6 = 0 |
---|
| 12 | bit_7 = 0 |
---|
| 13 | |
---|
| 14 | class u16hi(): |
---|
| 15 | bit_0 = 0 |
---|
| 16 | bit_1 = 0 |
---|
| 17 | bit_2 = 0 |
---|
| 18 | bit_3 = 0 |
---|
| 19 | bit_4 = 0 |
---|
| 20 | bit_5 = 0 |
---|
| 21 | bit_6 = 0 |
---|
| 22 | bit_7 = 0 |
---|
| 23 | |
---|
| 24 | class u16lo(): |
---|
| 25 | bit_0 = 0 |
---|
| 26 | bit_1 = 0 |
---|
| 27 | bit_2 = 0 |
---|
| 28 | bit_3 = 0 |
---|
| 29 | bit_4 = 0 |
---|
| 30 | bit_5 = 0 |
---|
| 31 | bit_6 = 0 |
---|
| 32 | bit_7 = 0 |
---|
| 33 | |
---|
| 34 | |
---|
[774] | 35 | class u8 (): |
---|
| 36 | unibyte = 0 |
---|
| 37 | prefix = 0 |
---|
| 38 | prefix2 = 0 |
---|
| 39 | prefix3 = 0 |
---|
| 40 | prefix4 = 0 |
---|
| 41 | suffix = 0 |
---|
| 42 | scope22 = 0 |
---|
| 43 | scope32 = 0 |
---|
| 44 | scope33 = 0 |
---|
| 45 | scope42 = 0 |
---|
| 46 | scope43 = 0 |
---|
| 47 | scope44 = 0 |
---|
[1822] | 48 | surrogate = 0 |
---|
[774] | 49 | xE0_scope = 0 |
---|
| 50 | xED_scope = 0 |
---|
| 51 | xF0_scope = 0 |
---|
| 52 | xF4_scope = 0 |
---|
| 53 | xEF_scope = 0 |
---|
| 54 | error = 0 |
---|
[1822] | 55 | delmask = 0 |
---|
[774] | 56 | |
---|
[1822] | 57 | def Utf8_to_utf16(u8_bits, u8, u16hi, u16lo): |
---|
[1866] | 58 | u8.unibyte = (~u8_bits.bit_0) |
---|
| 59 | u8.prefix = (u8_bits.bit_0 & u8_bits.bit_1) |
---|
| 60 | u8.prefix2 = (u8.prefix &~ u8_bits.bit_2) |
---|
| 61 | temp1 = (u8_bits.bit_2 &~ u8_bits.bit_3) |
---|
| 62 | u8.prefix3 = (u8.prefix & temp1) |
---|
| 63 | temp2 = (u8_bits.bit_2 & u8_bits.bit_3) |
---|
| 64 | u8.prefix4 = (u8.prefix & temp2) |
---|
| 65 | u8.suffix = (u8_bits.bit_0 &~ u8_bits.bit_1) |
---|
[774] | 66 | # |
---|
[1822] | 67 | u8.delmask = 0 |
---|
[851] | 68 | error_mask = 0 |
---|
| 69 | u8anyscope = 0 |
---|
[1822] | 70 | if u8_bits.bit_0: |
---|
[1866] | 71 | temp3 = (u8_bits.bit_2 | u8_bits.bit_3) |
---|
| 72 | temp4 = (u8.prefix &~ temp3) |
---|
| 73 | temp5 = (u8_bits.bit_4 | u8_bits.bit_5) |
---|
| 74 | temp6 = (temp5 | u8_bits.bit_6) |
---|
| 75 | badprefix2 = (temp4 &~ temp6) |
---|
[851] | 76 | error_mask = badprefix2 |
---|
[1592] | 77 | u8.scope22 = pablo.Advance(u8.prefix2) |
---|
[1822] | 78 | adv_bit3 = pablo.Advance(u8_bits.bit_3) |
---|
| 79 | adv_bit4 = pablo.Advance(u8_bits.bit_4) |
---|
| 80 | adv_bit5 = pablo.Advance(u8_bits.bit_5) |
---|
| 81 | adv_bit6 = pablo.Advance(u8_bits.bit_6) |
---|
| 82 | adv_bit7 = pablo.Advance(u8_bits.bit_7) |
---|
[851] | 83 | u8lastscope = u8.scope22 |
---|
| 84 | u8anyscope = u8.scope22 |
---|
| 85 | u8lastbyte = u8.unibyte | u8lastscope |
---|
[1822] | 86 | u8.delmask = u8.prefix |
---|
[851] | 87 | if u8.prefix3 | u8.prefix4: |
---|
[1866] | 88 | temp7 = (u8_bits.bit_6 | u8_bits.bit_7) |
---|
| 89 | temp8 = (temp5 | temp7) |
---|
| 90 | xE0 = (u8.prefix3 &~ temp8) |
---|
| 91 | temp9 = (u8_bits.bit_4 & u8_bits.bit_5) |
---|
| 92 | temp10 = (u8_bits.bit_7 &~ u8_bits.bit_6) |
---|
| 93 | temp11 = (temp9 & temp10) |
---|
| 94 | xED = (u8.prefix3 & temp11) |
---|
| 95 | xA0_xBF = (u8.suffix & u8_bits.bit_2) |
---|
| 96 | x80_x9F = (u8.suffix &~ u8_bits.bit_2) |
---|
[1592] | 97 | error_mask |= pablo.Advance(xE0) & x80_x9F |
---|
| 98 | error_mask |= pablo.Advance(xED) & xA0_xBF |
---|
| 99 | u8.scope32 = pablo.Advance(u8.prefix3) |
---|
| 100 | u8.scope33 = pablo.Advance(u8.scope32) |
---|
[1822] | 101 | adv_bit2 = pablo.Advance(u8_bits.bit_2) |
---|
[1592] | 102 | advadv_bit4 = pablo.Advance(adv_bit4) |
---|
| 103 | advadv_bit5 = pablo.Advance(adv_bit5) |
---|
| 104 | advadv_bit6 = pablo.Advance(adv_bit6) |
---|
| 105 | advadv_bit7 = pablo.Advance(adv_bit7) |
---|
[851] | 106 | u8lastscope |= u8.scope33 |
---|
| 107 | u8anyscope = u8lastscope | u8.scope32 |
---|
| 108 | u8lastbyte = u8.unibyte | u8lastscope |
---|
[1822] | 109 | u8.delmask |= u8.scope32 |
---|
[851] | 110 | if u8.prefix4: |
---|
[1866] | 111 | temp12 = (u8_bits.bit_5 & temp7) |
---|
| 112 | temp13 = (u8_bits.bit_4 | temp12) |
---|
| 113 | badprefix4 = (u8.prefix4 & temp13) |
---|
[851] | 114 | error_mask |= badprefix4 |
---|
[1866] | 115 | xF0 = (u8.prefix4 &~ temp8) |
---|
| 116 | temp14 = (u8_bits.bit_5 &~ u8_bits.bit_4) |
---|
| 117 | temp15 = (temp14 &~ temp7) |
---|
| 118 | xF4 = (u8.prefix4 & temp15) |
---|
| 119 | x90_xBF = (u8.suffix & temp3) |
---|
| 120 | x80_x8F = (u8.suffix &~ temp3) |
---|
[1592] | 121 | error_mask |= pablo.Advance(xF0) & x80_x8F |
---|
| 122 | error_mask |= pablo.Advance(xF4) & x90_xBF |
---|
| 123 | u8.scope42 = pablo.Advance(u8.prefix4) |
---|
| 124 | u8.scope43 = pablo.Advance(u8.scope42) |
---|
| 125 | u8.scope44 = pablo.Advance(u8.scope43) |
---|
[1822] | 126 | u8.surrogate = u8.scope43 | u8.scope44 |
---|
[851] | 127 | u8lastscope |= u8.scope44 |
---|
| 128 | u8anyscope = u8lastscope | u8.scope32 | u8.scope42 | u8.scope43 |
---|
| 129 | u8lastbyte = u8.unibyte | u8lastscope |
---|
[1822] | 130 | u8.delmask |= u8.scope42 |
---|
| 131 | u16lo.bit_1 = (u8.unibyte & u8_bits.bit_1) | (u8lastscope & adv_bit7) |
---|
| 132 | u16lo.bit_0 = u8lastscope & adv_bit6 |
---|
| 133 | u16hi.bit_5 = u8lastscope & adv_bit3 |
---|
| 134 | u16hi.bit_6 = u8lastscope & adv_bit4 |
---|
| 135 | u16hi.bit_7 = u8lastscope & adv_bit5 |
---|
| 136 | u16hi.bit_0 = u8.scope33 & advadv_bit4 | u8.surrogate |
---|
| 137 | u16hi.bit_1 = u8.scope33 & advadv_bit5 | u8.surrogate |
---|
| 138 | u16hi.bit_2 = u8.scope33 & advadv_bit6 |
---|
| 139 | u16hi.bit_3 = u8.scope33 & advadv_bit7 | u8.surrogate |
---|
| 140 | u16hi.bit_4 = u8.scope33 & adv_bit2 | u8.surrogate |
---|
| 141 | u16hi.bit_5 = u8lastscope & adv_bit3 | u8.scope44 |
---|
[851] | 142 | s43lo1 = ~adv_bit3 # subtract 1 |
---|
[1822] | 143 | u16lo.bit_1 = u16lo.bit_1 | u8.scope43 & s43lo1 |
---|
[851] | 144 | s43lo0 = adv_bit2 ^ s43lo1 # borrow * |
---|
[1822] | 145 | u16lo.bit_0 = u16lo.bit_0 | u8.scope43 & s43lo0 |
---|
[851] | 146 | s43borrow1 = s43lo1 & ~adv_bit2 |
---|
| 147 | s43hi7 = advadv_bit7 ^ s43borrow1 |
---|
| 148 | s43borrow2 = s43borrow1 & ~advadv_bit7 |
---|
| 149 | s43hi6 = advadv_bit6 ^ s43borrow2 |
---|
[1822] | 150 | u16hi.bit_7 = u8lastscope & adv_bit5 | (u8.scope43 & s43hi7) |
---|
| 151 | u16hi.bit_6 = u8lastscope & adv_bit4 | (u8.scope43 & s43hi6) |
---|
| 152 | u16lo.bit_2 = u8lastbyte & u8_bits.bit_2 | (u8.scope43 & adv_bit4) |
---|
| 153 | u16lo.bit_3 = u8lastbyte & u8_bits.bit_3 | (u8.scope43 & adv_bit5) |
---|
| 154 | u16lo.bit_4 = u8lastbyte & u8_bits.bit_4 | (u8.scope43 & adv_bit6) |
---|
| 155 | u16lo.bit_5 = u8lastbyte & u8_bits.bit_5 | (u8.scope43 & adv_bit7) |
---|
| 156 | u16lo.bit_6 = u8lastbyte & u8_bits.bit_6 | (u8.scope43 & u8_bits.bit_2) |
---|
| 157 | u16lo.bit_7 = u8lastbyte & u8_bits.bit_7 | (u8.scope43 & u8_bits.bit_3) |
---|
[851] | 158 | else: |
---|
| 159 | u8.scope42 = 0 |
---|
| 160 | u8.scope43 = 0 |
---|
| 161 | u8.scope44 = 0 |
---|
[1822] | 162 | u16hi.bit_0 = u8.scope33 & advadv_bit4 |
---|
| 163 | u16hi.bit_1 = u8.scope33 & advadv_bit5 |
---|
| 164 | u16hi.bit_2 = u8.scope33 & advadv_bit6 |
---|
| 165 | u16hi.bit_3 = u8.scope33 & advadv_bit7 |
---|
| 166 | u16hi.bit_4 = u8.scope33 & adv_bit2 |
---|
| 167 | u16hi.bit_5 = u8lastscope & adv_bit3 |
---|
| 168 | u16hi.bit_6 = u8lastscope & adv_bit4 |
---|
| 169 | u16hi.bit_7 = u8lastscope & adv_bit5 |
---|
| 170 | u16lo.bit_2 = u8lastbyte & u8_bits.bit_2 |
---|
| 171 | u16lo.bit_3 = u8lastbyte & u8_bits.bit_3 |
---|
| 172 | u16lo.bit_4 = u8lastbyte & u8_bits.bit_4 |
---|
| 173 | u16lo.bit_5 = u8lastbyte & u8_bits.bit_5 |
---|
| 174 | u16lo.bit_6 = u8lastbyte & u8_bits.bit_6 |
---|
| 175 | u16lo.bit_7 = u8lastbyte & u8_bits.bit_7 |
---|
| 176 | u16lo.bit_1 = (u8.unibyte & u8_bits.bit_1) | (u8lastscope & adv_bit7) |
---|
| 177 | u16lo.bit_0 = u8lastscope & adv_bit6 |
---|
[851] | 178 | else: |
---|
| 179 | u8.scope32 = 0 |
---|
| 180 | u8.scope33 = 0 |
---|
| 181 | u8.scope42 = 0 |
---|
| 182 | u8.scope43 = 0 |
---|
| 183 | u8.scope44 = 0 |
---|
[1822] | 184 | u16hi.bit_0 = 0 |
---|
| 185 | u16hi.bit_1 = 0 |
---|
| 186 | u16hi.bit_2 = 0 |
---|
| 187 | u16hi.bit_3 = 0 |
---|
| 188 | u16hi.bit_4 = 0 |
---|
| 189 | u16hi.bit_5 = u8lastscope & adv_bit3 |
---|
| 190 | u16hi.bit_6 = u8lastscope & adv_bit4 |
---|
| 191 | u16hi.bit_7 = u8lastscope & adv_bit5 |
---|
| 192 | u16lo.bit_2 = u8lastbyte & u8_bits.bit_2 |
---|
| 193 | u16lo.bit_3 = u8lastbyte & u8_bits.bit_3 |
---|
| 194 | u16lo.bit_4 = u8lastbyte & u8_bits.bit_4 |
---|
| 195 | u16lo.bit_5 = u8lastbyte & u8_bits.bit_5 |
---|
| 196 | u16lo.bit_6 = u8lastbyte & u8_bits.bit_6 |
---|
| 197 | u16lo.bit_7 = u8lastbyte & u8_bits.bit_7 |
---|
| 198 | u16lo.bit_1 = (u8.unibyte & u8_bits.bit_1) | (u8lastscope & adv_bit7) |
---|
| 199 | u16lo.bit_0 = u8lastscope & adv_bit6 |
---|
[851] | 200 | else: |
---|
| 201 | u8.scope22 = 0 |
---|
| 202 | u8.scope32 = 0 |
---|
| 203 | u8.scope33 = 0 |
---|
| 204 | u8.scope42 = 0 |
---|
| 205 | u8.scope43 = 0 |
---|
| 206 | u8.scope44 = 0 |
---|
[1822] | 207 | u16hi.bit_0 = 0 |
---|
| 208 | u16hi.bit_1 = 0 |
---|
| 209 | u16hi.bit_2 = 0 |
---|
| 210 | u16hi.bit_3 = 0 |
---|
| 211 | u16hi.bit_4 = 0 |
---|
| 212 | u16hi.bit_5 = 0 |
---|
| 213 | u16hi.bit_6 = 0 |
---|
| 214 | u16hi.bit_7 = 0 |
---|
| 215 | u16lo.bit_2 = u8_bits.bit_2 |
---|
| 216 | u16lo.bit_3 = u8_bits.bit_3 |
---|
| 217 | u16lo.bit_4 = u8_bits.bit_4 |
---|
| 218 | u16lo.bit_5 = u8_bits.bit_5 |
---|
| 219 | u16lo.bit_6 = u8_bits.bit_6 |
---|
| 220 | u16lo.bit_7 = u8_bits.bit_7 |
---|
| 221 | u16lo.bit_1 = u8_bits.bit_1 |
---|
| 222 | u16lo.bit_0 = 0 |
---|
[774] | 223 | error_mask |= u8anyscope ^ u8.suffix |
---|
| 224 | u8.error = error_mask |
---|
| 225 | |
---|
[1822] | 226 | def Main(u8_bits, u8, u16hi, u16lo): |
---|
| 227 | Utf8_to_utf16(u8_bits, u8, u16hi, u16lo) |
---|
| 228 | |
---|