| 130 | |
| 131 | |
| 132 | class EUCKRDistributionAnalysis(CharDistributionAnalysis): |
| 133 | def __init__(self): |
| 134 | super(EUCKRDistributionAnalysis, self).__init__() |
| 135 | self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER |
| 136 | self._table_size = EUCKR_TABLE_SIZE |
| 137 | self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO |
| 138 | |
| 139 | def get_order(self, byte_str): |
| 140 | # for euc-KR encoding, we are interested |
| 141 | # first byte range: 0xb0 -- 0xfe |
| 142 | # second byte range: 0xa1 -- 0xfe |
| 143 | # no validation needed here. State machine has done that |
| 144 | first_char = byte_str[0] |
| 145 | if first_char >= 0xB0: |
| 146 | return 94 * (first_char - 0xB0) + byte_str[1] - 0xA1 |
| 147 | else: |
| 148 | return -1 |
| 149 | |
| 150 | |
| 151 | class GB2312DistributionAnalysis(CharDistributionAnalysis): |