Class: CharDet::GB18030DistributionAnalysis

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

#initializeGB18030DistributionAnalysis

Returns a new instance of GB18030DistributionAnalysis.



153
154
155
156
157
158
# File 'lib/rchardet/chardistribution.rb', line 153

def initialize
  super()
  @charToFreqOrder = GB18030CharToFreqOrder
  @tableSize = GB18030_TABLE_SIZE
  @typicalDistributionRatio = GB18030_TYPICAL_DISTRIBUTION_RATIO
end

Instance Method Details

#get_order(aStr) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rchardet/chardistribution.rb', line 160

def get_order(aStr)
  # for GB18030 encoding, we are interested 
  #  first  byte range: 0xb0 -- 0xfe
  #  second byte range: 0xa1 -- 0xfe
  # no validation needed here. State machine has done that
  if (aStr[0, 1] >= "\xB0") and (aStr[1, 1] >= "\xA1")
    bytes = aStr.bytes.to_a
    return 94 * (bytes[0] - 0xB0) + bytes[1] - 0xA1
  else
    return -1
  end
end