Class: UniversalDetector::SJISDistributionAnalysis
- Inherits:
-
CharDistributionAnalysis
- Object
- CharDistributionAnalysis
- UniversalDetector::SJISDistributionAnalysis
- Defined in:
- lib/CharDistributionAnalysis.rb
Constant Summary
Constants inherited from CharDistributionAnalysis
CharDistributionAnalysis::ENOUGH_DATA_THRESHOLD, CharDistributionAnalysis::SURE_NO, CharDistributionAnalysis::SURE_YES
Instance Method Summary collapse
- #get_order(aStr) ⇒ Object
-
#initialize ⇒ SJISDistributionAnalysis
constructor
A new instance of SJISDistributionAnalysis.
Methods inherited from CharDistributionAnalysis
#feed, #get_confidence, #got_enough_data, #reset
Constructor Details
#initialize ⇒ SJISDistributionAnalysis
Returns a new instance of SJISDistributionAnalysis.
197 198 199 200 201 202 |
# File 'lib/CharDistributionAnalysis.rb', line 197 def initialize super @_mCharToFreqOrder = JISCharToFreqOrder @_mTableSize = JIS_TABLE_SIZE @_mTypicalDistributionRatio = JIS_TYPICAL_DISTRIBUTION_RATIO end |
Instance Method Details
#get_order(aStr) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/CharDistributionAnalysis.rb', line 204 def get_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 if (aStr[0] >= 0x81) && (aStr[0] <= 0x9F) order = 188 * (aStr[0] - 0x81) elsif (aStr[0] >= 0xE0) and (aStr[0] <= 0xEF) order = 188 * (aStr[0] - 0xE0 + 31) else return -1; end order = order + aStr[1] - 0x40 if aStr[1] > 0x7F order =- 1 end return order end |