Class: CharDet::Big5DistributionAnalysis

Inherits:
CharDistributionAnalysis show all
Defined in:
lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb

Instance Method Summary collapse

Methods inherited from CharDistributionAnalysis

#feed, #get_confidence, #got_enough_data, #reset

Constructor Details

#initializeBig5DistributionAnalysis

Returns a new instance of Big5DistributionAnalysis.



165
166
167
168
169
170
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb', line 165

def initialize
  super
  @_mCharToFreqOrder = Big5CharToFreqOrder
  @_mTableSize = BIG5_TABLE_SIZE
  @_mTypicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
end

Instance Method Details

#get_order(aStr) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb', line 172

def get_order(aStr)
  # for big5 encoding, we are interested 
  #   first  byte range: 0xa4 -- 0xfe
  #   second byte range: 0x40 -- 0x7e , 0xa1 -- 0xfe
  # no validation needed here. State machine has done that
  if aStr[0..0] >= "\xA4"
    if aStr[1..1] >= "\xA1"
      return 157 * (aStr[0] - 0xA4) + aStr[1] - 0xA1 + 63
    else
      return 157 * (aStr[0] - 0xA4) + aStr[1] - 0x40
    end
  else
    return -1
  end
end