Class: CharDet::SJISDistributionAnalysis

Inherits:
CharDistributionAnalysis show all
Defined in:
lib/rchardet/chardistribution.rb

Instance Method Summary collapse

Methods inherited from CharDistributionAnalysis

#confidence, #feed, #got_enough_data, #reset

Constructor Details

#initializeSJISDistributionAnalysis

Returns a new instance of SJISDistributionAnalysis.



189
190
191
192
193
194
# File 'lib/rchardet/chardistribution.rb', line 189

def initialize
  super()
  @_mCharToFreqOrder = JISCharToFreqOrder
  @_mTableSize = JIS_TABLE_SIZE
  @_mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO
end

Instance Method Details

#order(aStr) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/rchardet/chardistribution.rb', line 196

def order(aStr)
  # for sjis encoding, we are interested
  #   first  byte range: 0x81 -- 0x9f , 0xe0 -- 0xfe
  #   second byte range: 0x40 -- 0x7e,  0x81 -- oxfe
  # no validation needed here. State machine has done that
  aStr = aStr[0..1].join if aStr.class == Array
  if (aStr[0] >= "\x81") and (aStr[0] <= "\x9F")
    order = 188 * (aStr[0].ord - 0x81)
  elsif (aStr[0] >= "\xE0") and (aStr[0] <= "\xEF")
    order = 188 * (aStr[0].ord - 0xE0 + 31)
  else
    return -1
  end
  order = order + aStr[1].ord - 0x40
  if aStr[1] > "\x7F"
    order =- 1
  end
  return order
end