Class: CharDet::Big5DistributionAnalysis

Inherits:
CharDistributionAnalysis show all
Defined in:
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.



175
176
177
178
179
180
# File 'lib/rchardet/chardistribution.rb', line 175

def initialize
  super
  @charToFreqOrder = Big5CharToFreqOrder
  @tableSize = BIG5_TABLE_SIZE
  @typicalDistributionRatio = BIG5_TYPICAL_DISTRIBUTION_RATIO
end

Instance Method Details

#get_order(aStr) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rchardet/chardistribution.rb', line 182

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, 1] >= "\xA4"
    bytes = aStr.bytes.to_a
    if aStr[1, 1] >= "\xA1"
      return 157 * (bytes[0] - 0xA4) + bytes[1] - 0xA1 + 63
    else
      return 157 * (bytes[0] - 0xA4) + bytes[1] - 0x40
    end
  else
    return -1
  end
end