summaryrefslogtreecommitdiff
path: root/ext/nkf/lib/kconv.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-27 16:53:48 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-27 16:53:48 +0000
commit8e70a60da0d3a34cf6c748d81a6fab42a5734e26 (patch)
tree3ceaa8d49e00d068c70f7c90e1158d28f68d1de1 /ext/nkf/lib/kconv.rb
parent41d2099e9646b4ad0c191083ec9da05461eb006a (diff)
* ext/nkf/lib/kconv.rb: add Kconv::VERSION
* ext/nkf/lib/kconv.rb (conv): can process arrayed options * ext/nkf/nkf-utf8/nkf.c: imported Revision 1.69 * ext/nkf/nkf-utf8/utf8tbl.c: imported Revision 1.9 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/nkf/lib/kconv.rb')
-rw-r--r--ext/nkf/lib/kconv.rb50
1 files changed, 12 insertions, 38 deletions
diff --git a/ext/nkf/lib/kconv.rb b/ext/nkf/lib/kconv.rb
index fecddee978a..8d57c2a5d2d 100644
--- a/ext/nkf/lib/kconv.rb
+++ b/ext/nkf/lib/kconv.rb
@@ -11,6 +11,8 @@ module Kconv
# Public Constants
#
+ VERSION = '1.8'
+
#Constant of Encoding
AUTO = ::NKF::AUTO
JIS = ::NKF::JIS
@@ -28,6 +30,8 @@ module Kconv
# Private Constants
#
+ REVISON = %q$Revison$
+
#Regexp of Encoding
RegexpShiftjis = /\A(?:
[\x00-\x7f\xa1-\xdf] |
@@ -100,30 +104,6 @@ module Kconv
UNKNOWN => :unknown
}
- SYMBOL_TO_CONSTANT = {
- :auto => AUTO,
- :unknown => UNKNOWN,
- :binary => BINARY,
- :ascii => ASCII,
- :ascii => ASCII,
- :shiftjis => SJIS,
- :sjis => SJIS,
- :cp932 => SJIS,
- :eucjp => EUC,
- :euc => EUC,
- :eucjpms => EUC,
- :iso2022jp => JIS,
- :jis => JIS,
- :utf8 => UTF8,
- :utf8n => UTF8,
- :utf16 => UTF16,
- :utf16be => UTF16,
- :utf16ben => UTF16,
- :utf16le => UTF16,
- :utf16len => UTF16,
- :noconv => NOCONV
- }
-
#
# Public Methods
#
@@ -186,14 +166,9 @@ module Kconv
to = symbol_to_option(option[0])
from = symbol_to_option(option[1]).to_s.sub(/(-[jesw])/o){$1.upcase}
- opt = Array.new
- if option[2].is_a? Array
- opt << option[2].map{|x|symbol_to_option(x)}.compact.join('')
- elsif option[2].is_a? String
- opt << option[2]
- end
+ opt = option[2..-1].to_a.map{|x|symbol_to_option(x)}.compact.join('')
- nkf_opt = ('-x -m0 %s %s %s' % [to, from, opt.join(' ')])
+ nkf_opt = ('-x -m0 %s %s %s' % [to, from, opt])
result = ::NKF::nkf( nkf_opt, str)
end
module_function :conv
@@ -300,12 +275,12 @@ module Kconv
#
# Private Methods
#
-
+ private
def symbol_to_option(symbol)
- if symbol.to_s[0] == ?-
- return symbol.to_s
- elsif symbol.is_a? Integer
+ if symbol.is_a? Integer
symbol = CONSTANT_TO_SYMBOL[symbol]
+ elsif symbol.to_s[0] == ?-
+ return symbol.to_s
end
begin
SYMBOL_TO_OPTION[ symbol.to_s.downcase.delete('-_').to_sym ]
@@ -313,13 +288,12 @@ module Kconv
return nil
end
end
-private :symbol_to_option
module_function :symbol_to_option
end
class String
- def kconv(out_code, in_code=Kconv::AUTO)
- Kconv::kconv(self, out_code, in_code)
+ def kconv(*args)
+ Kconv::kconv(self, *args)
end
def conv(*args)