Skip to content

Commit

Permalink
Run rbeautify over all files
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jan 15, 2010
1 parent 99a2454 commit 15a1325
Show file tree
Hide file tree
Showing 35 changed files with 4,904 additions and 4,904 deletions.
4 changes: 2 additions & 2 deletions lib/rchardet.rb
Expand Up @@ -3,12 +3,12 @@
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Expand Down
1,774 changes: 887 additions & 887 deletions lib/rchardet/big5freq.rb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lib/rchardet/big5prober.rb
@@ -1,11 +1,11 @@
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
#
# Contributor(s):
# Jeff Hodges - port to Ruby
# Mark Pilgrim - port to Python
Expand All @@ -14,20 +14,20 @@
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################

module CharDet
class Big5Prober < MultiByteCharSetProber
class Big5Prober < MultiByteCharSetProber
def initialize
super
@_mCodingSM = CodingStateMachine.new(Big5SMModel)
Expand Down
84 changes: 42 additions & 42 deletions lib/rchardet/chardistribution.rb
@@ -1,11 +1,11 @@
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
#
# Contributor(s):
# Jeff Hodges
# Mark Pilgrim - port to Python
Expand All @@ -14,12 +14,12 @@
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Expand Down Expand Up @@ -49,34 +49,34 @@ def reset
def feed(aStr, aCharLen)
# # """feed a character with known length"""
if aCharLen == 2
# we only care about 2-bytes character in our distribution analysis
order = get_order(aStr)
# we only care about 2-bytes character in our distribution analysis
order = get_order(aStr)
else
order = -1
order = -1
end
if order >= 0
@_mTotalChars += 1
# order is valid
if order < @_mTableSize
if 512 > @_mCharToFreqOrder[order]
@_mFreqChars += 1
end
end
@_mTotalChars += 1
# order is valid
if order < @_mTableSize
if 512 > @_mCharToFreqOrder[order]
@_mFreqChars += 1
end
end
end
end

def get_confidence
# """return confidence based on existing data"""
# if we didn't receive any character in our consideration range, return negative answer
if @_mTotalChars <= 0
return SURE_NO
return SURE_NO
end

if @_mTotalChars != @_mFreqChars
r = @_mFreqChars / ((@_mTotalChars - @_mFreqChars) * @_mTypicalDistributionRatio)
if r < SURE_YES
return r
end
r = @_mFreqChars / ((@_mTotalChars - @_mFreqChars) * @_mTypicalDistributionRatio)
if r < SURE_YES
return r
end
end

# normalize confidence (we don't want to be 100% sure)
Expand All @@ -90,7 +90,7 @@ def got_enough_data
end

def get_order(aStr)
# We do not handle characters based on the original encoding string, but
# We do not handle characters based on the original encoding string, but
# convert this encoding string to a number, here called order.
# This allows multiple encodings of a language to share one frequency table.
return -1
Expand All @@ -106,14 +106,14 @@ def initialize
end

def get_order(aStr)
# for euc-TW encoding, we are interested
# for euc-TW encoding, we are interested
# first byte range: 0xc4 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
if aStr[0..0] >= "\xC4"
return 94 * (aStr[0] - 0xC4) + aStr[1] - 0xA1
return 94 * (aStr[0] - 0xC4) + aStr[1] - 0xA1
else
return -1
return -1
end
end
end
Expand All @@ -127,14 +127,14 @@ def initialize
end

def get_order(aStr)
# for euc-KR encoding, we are interested
# for euc-KR 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..0] >= "\xB0"
return 94 * (aStr[0] - 0xB0) + aStr[1] - 0xA1
return 94 * (aStr[0] - 0xB0) + aStr[1] - 0xA1
else
return -1
return -1
end
end
end
Expand All @@ -148,14 +148,14 @@ def initialize
end

def get_order(aStr)
# for GB2312 encoding, we are interested
# for GB2312 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..0] >= "\xB0") and (aStr[1..1] >= "\xA1")
return 94 * (aStr[0] - 0xB0) + aStr[1] - 0xA1
return 94 * (aStr[0] - 0xB0) + aStr[1] - 0xA1
else
return -1
return -1
end
end
end
Expand All @@ -169,18 +169,18 @@ def initialize
end

def get_order(aStr)
# for big5 encoding, we are interested
# 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
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
return -1
end
end
end
Expand All @@ -194,21 +194,21 @@ def initialize
end

def get_order(aStr)
# for sjis encoding, we are interested
# 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..0] >= "\x81") and (aStr[0..0] <= "\x9F")
order = 188 * (aStr[0] - 0x81)
order = 188 * (aStr[0] - 0x81)
elsif (aStr[0..0] >= "\xE0") and (aStr[0..0] <= "\xEF")
order = 188 * (aStr[0] - 0xE0 + 31)
order = 188 * (aStr[0] - 0xE0 + 31)
else
return -1
return -1
end
order = order + aStr[1] - 0x40
if aStr[1..1] > "\x7F"
order =- 1
order =- 1
end
return order
end
Expand All @@ -223,7 +223,7 @@ def initialize
end

def get_order(aStr)
# for euc-JP encoding, we are interested
# for euc-JP encoding, we are interested
# first byte range: 0xa0 -- 0xfe
# second byte range: 0xa1 -- 0xfe
# no validation needed here. State machine has done that
Expand Down
80 changes: 40 additions & 40 deletions lib/rchardet/charsetgroupprober.rb
@@ -1,11 +1,11 @@
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
#
# Contributor(s):
# Jeff Hodges - port to Ruby
# Mark Pilgrim - port to Python
Expand All @@ -14,12 +14,12 @@
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Expand All @@ -41,66 +41,66 @@ def reset
@_mActiveNum = 0

for prober in @_mProbers
if prober
prober.reset()
prober.active = true
@_mActiveNum += 1
end
if prober
prober.reset()
prober.active = true
@_mActiveNum += 1
end
end
@_mBestGuessProber = nil
end

def get_charset_name
if not @_mBestGuessProber
get_confidence()
return nil unless @_mBestGuessProber
# self._mBestGuessProber = self._mProbers[0]
get_confidence()
return nil unless @_mBestGuessProber
# self._mBestGuessProber = self._mProbers[0]
end
return @_mBestGuessProber.get_charset_name()
end

def feed(aBuf)
for prober in @_mProbers
next unless prober
next unless prober.active
st = prober.feed(aBuf)
next unless st
if st == EFoundIt
@_mBestGuessProber = prober
return get_state()
elsif st == ENotMe
prober.active = false
@_mActiveNum -= 1
if @_mActiveNum <= 0
@_mState = ENotMe
return get_state()
end
end
next unless prober
next unless prober.active
st = prober.feed(aBuf)
next unless st
if st == EFoundIt
@_mBestGuessProber = prober
return get_state()
elsif st == ENotMe
prober.active = false
@_mActiveNum -= 1
if @_mActiveNum <= 0
@_mState = ENotMe
return get_state()
end
end
end
return get_state()
end

def get_confidence()
st = get_state()
if st == EFoundIt
return 0.99
return 0.99
elsif st == ENotMe
return 0.01
return 0.01
end
bestConf = 0.0
@_mBestGuessProber = nil
for prober in @_mProbers
next unless prober
unless prober.active
$stderr << "#{prober.get_charset_name()} not active\n" if $debug
next
end
cf = prober.get_confidence()
$stderr << "#{prober.get_charset_name} confidence = #{cf}\n" if $debug
if bestConf < cf
bestConf = cf
@_mBestGuessProber = prober
end
next unless prober
unless prober.active
$stderr << "#{prober.get_charset_name()} not active\n" if $debug
next
end
cf = prober.get_confidence()
$stderr << "#{prober.get_charset_name} confidence = #{cf}\n" if $debug
if bestConf < cf
bestConf = cf
@_mBestGuessProber = prober
end
end
return 0.0 unless @_mBestGuessProber
return bestConf
Expand Down

0 comments on commit 15a1325

Please sign in to comment.