GIF87a;
# # kconv.rb - Kanji Converter. # # $Id: kconv.rb 30112 2010-12-07 11:47:39Z naruse $ # # ---- # # kconv.rb implements the Kconv class for Kanji Converter. Additionally, # some methods in String classes are added to allow easy conversion. # require 'nkf' # # Kanji Converter for Ruby. # module Kconv # # Public Constants # #Constant of Encoding # Auto-Detect AUTO = NKF::AUTO # ISO-2022-JP JIS = NKF::JIS # EUC-JP EUC = NKF::EUC # Shift_JIS SJIS = NKF::SJIS # BINARY BINARY = NKF::BINARY # NOCONV NOCONV = NKF::NOCONV # ASCII ASCII = NKF::ASCII # UTF-8 UTF8 = NKF::UTF8 # UTF-16 UTF16 = NKF::UTF16 # UTF-32 UTF32 = NKF::UTF32 # UNKNOWN UNKNOWN = NKF::UNKNOWN # # Public Methods # # call-seq: # Kconv.kconv(str, to_enc, from_enc=nil) # # Convert <code>str</code> to <code>to_enc</code>. # <code>to_enc</code> and <code>from_enc</code> are given as constants of Kconv or Encoding objects. def kconv(str, to_enc, from_enc=nil) opt = '' opt += ' --ic=' + from_enc.to_s if from_enc opt += ' --oc=' + to_enc.to_s if to_enc ::NKF::nkf(opt, str) end module_function :kconv # # Encode to # # call-seq: # Kconv.tojis(str) => string # # Convert <code>str</code> to ISO-2022-JP def tojis(str) kconv(str, JIS) end module_function :tojis # call-seq: # Kconv.toeuc(str) => string # # Convert <code>str</code> to EUC-JP def toeuc(str) kconv(str, EUC) end module_function :toeuc # call-seq: # Kconv.tosjis(str) => string # # Convert <code>str</code> to Shift_JIS def tosjis(str) kconv(str, SJIS) end module_function :tosjis # call-seq: # Kconv.toutf8(str) => string # # Convert <code>str</code> to UTF-8 def toutf8(str) kconv(str, UTF8) end module_function :toutf8 # call-seq: # Kconv.toutf16(str) => string # # Convert <code>str</code> to UTF-16 def toutf16(str) kconv(str, UTF16) end module_function :toutf16 # call-seq: # Kconv.toutf32(str) => string # # Convert <code>str</code> to UTF-32 def toutf32(str) kconv(str, UTF32) end module_function :toutf32 # call-seq: # Kconv.tolocale => string # # Convert <code>self</code> to locale encoding def tolocale(str) kconv(str, Encoding.locale_charmap) end module_function :tolocale # # guess # # call-seq: # Kconv.guess(str) => encoding # # Guess input encoding by NKF.guess def guess(str) ::NKF::guess(str) end module_function :guess # # isEncoding # # call-seq: # Kconv.iseuc(str) => true or false # # Returns whether input encoding is EUC-JP or not. # # *Note* don't expect this return value is MatchData. def iseuc(str) str.dup.force_encoding(EUC).valid_encoding? end module_function :iseuc # call-seq: # Kconv.issjis(str) => true or false # # Returns whether input encoding is Shift_JIS or not. def issjis(str) str.dup.force_encoding(SJIS).valid_encoding? end module_function :issjis # call-seq: # Kconv.isjis(str) => true or false # # Returns whether input encoding is ISO-2022-JP or not. def isjis(str) /\A [\t\n\r\x20-\x7E]* (?: (?:\x1b \x28 I [\x21-\x7E]* |\x1b \x28 J [\x21-\x7E]* |\x1b \x24 @ (?:[\x21-\x7E]{2})* |\x1b \x24 B (?:[\x21-\x7E]{2})* |\x1b \x24 \x28 D (?:[\x21-\x7E]{2})* )* \x1b \x28 B [\t\n\r\x20-\x7E]* )* \z/nox =~ str.dup.force_encoding('BINARY') ? true : false end module_function :isjis # call-seq: # Kconv.isutf8(str) => true or false # # Returns whether input encoding is UTF-8 or not. def isutf8(str) str.dup.force_encoding(UTF8).valid_encoding? end module_function :isutf8 end class String # call-seq: # String#kconv(to_enc, from_enc) # # Convert <code>self</code> to <code>to_enc</code>. # <code>to_enc</code> and <code>from_enc</code> are given as constants of Kconv or Encoding objects. def kconv(to_enc, from_enc=nil) from_enc = self.encoding if !from_enc && self.encoding != Encoding.list[0] Kconv::kconv(self, to_enc, from_enc) end # # to Encoding # # call-seq: # String#tojis => string # # Convert <code>self</code> to ISO-2022-JP def tojis; Kconv.tojis(self) end # call-seq: # String#toeuc => string # # Convert <code>self</code> to EUC-JP def toeuc; Kconv.toeuc(self) end # call-seq: # String#tosjis => string # # Convert <code>self</code> to Shift_JIS def tosjis; Kconv.tosjis(self) end # call-seq: # String#toutf8 => string # # Convert <code>self</code> to UTF-8 def toutf8; Kconv.toutf8(self) end # call-seq: # String#toutf16 => string # # Convert <code>self</code> to UTF-16 def toutf16; Kconv.toutf16(self) end # call-seq: # String#toutf32 => string # # Convert <code>self</code> to UTF-32 def toutf32; Kconv.toutf32(self) end # call-seq: # String#tolocale => string # # Convert <code>self</code> to locale encoding def tolocale; Kconv.tolocale(self) end # # is Encoding # # call-seq: # String#iseuc => true or false # # Returns whether <code>self</code>'s encoding is EUC-JP or not. def iseuc; Kconv.iseuc(self) end # call-seq: # String#issjis => true or false # # Returns whether <code>self</code>'s encoding is Shift_JIS or not. def issjis; Kconv.issjis(self) end # call-seq: # String#isjis => true or false # # Returns whether <code>self</code>'s encoding is ISO-2022-JP or not. def isjis; Kconv.isjis(self) end # call-seq: # String#isutf8 => true or false # # Returns whether <code>self</code>'s encoding is UTF-8 or not. def isutf8; Kconv.isutf8(self) end end
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
bigdecimal | Folder | 0755 |
|
|
cgi | Folder | 0755 |
|
|
date | Folder | 0755 |
|
|
digest | Folder | 0755 |
|
|
dl | Folder | 0755 |
|
|
drb | Folder | 0755 |
|
|
fiddle | Folder | 0755 |
|
|
io | Folder | 0755 |
|
|
irb | Folder | 0755 |
|
|
json | Folder | 0755 |
|
|
matrix | Folder | 0755 |
|
|
net | Folder | 0755 |
|
|
openssl | Folder | 0755 |
|
|
optparse | Folder | 0755 |
|
|
psych | Folder | 0755 |
|
|
racc | Folder | 0755 |
|
|
rbconfig | Folder | 0755 |
|
|
rexml | Folder | 0755 |
|
|
rinda | Folder | 0755 |
|
|
ripper | Folder | 0755 |
|
|
rss | Folder | 0755 |
|
|
shell | Folder | 0755 |
|
|
syslog | Folder | 0755 |
|
|
test | Folder | 0755 |
|
|
uri | Folder | 0755 |
|
|
vendor_ruby | Folder | 0755 |
|
|
webrick | Folder | 0755 |
|
|
xmlrpc | Folder | 0755 |
|
|
yaml | Folder | 0755 |
|
|
English.rb | File | 6.44 KB | 0644 |
|
abbrev.rb | File | 3.31 KB | 0644 |
|
base64.rb | File | 2.63 KB | 0644 |
|
benchmark.rb | File | 17.94 KB | 0644 |
|
cgi.rb | File | 9.39 KB | 0644 |
|
cmath.rb | File | 7.22 KB | 0644 |
|
complex.rb | File | 380 B | 0644 |
|
csv.rb | File | 81.32 KB | 0644 |
|
date.rb | File | 946 B | 0644 |
|
debug.rb | File | 28.9 KB | 0644 |
|
delegate.rb | File | 9.78 KB | 0644 |
|
digest.rb | File | 2.24 KB | 0644 |
|
dl.rb | File | 280 B | 0644 |
|
drb.rb | File | 19 B | 0644 |
|
e2mmap.rb | File | 3.8 KB | 0644 |
|
erb.rb | File | 26.08 KB | 0644 |
|
expect.rb | File | 2.14 KB | 0644 |
|
fiddle.rb | File | 1.25 KB | 0644 |
|
fileutils.rb | File | 46.35 KB | 0644 |
|
find.rb | File | 2.08 KB | 0644 |
|
forwardable.rb | File | 7.56 KB | 0644 |
|
getoptlong.rb | File | 15.38 KB | 0644 |
|
gserver.rb | File | 8.86 KB | 0644 |
|
ipaddr.rb | File | 26.17 KB | 0644 |
|
irb.rb | File | 20.03 KB | 0644 |
|
json.rb | File | 1.74 KB | 0644 |
|
kconv.rb | File | 5.74 KB | 0644 |
|
logger.rb | File | 20.96 KB | 0644 |
|
mathn.rb | File | 6.52 KB | 0644 |
|
matrix.rb | File | 45.02 KB | 0644 |
|
mkmf.rb | File | 78.13 KB | 0644 |
|
monitor.rb | File | 6.93 KB | 0644 |
|
mutex_m.rb | File | 2 KB | 0644 |
|
observer.rb | File | 5.71 KB | 0644 |
|
open-uri.rb | File | 23.66 KB | 0644 |
|
open3.rb | File | 21.17 KB | 0644 |
|
openssl.rb | File | 528 B | 0644 |
|
optparse.rb | File | 51.27 KB | 0644 |
|
ostruct.rb | File | 7.64 KB | 0644 |
|
pathname.rb | File | 15.3 KB | 0644 |
|
pp.rb | File | 13.14 KB | 0644 |
|
prettyprint.rb | File | 9.63 KB | 0644 |
|
prime.rb | File | 13.98 KB | 0644 |
|
profile.rb | File | 205 B | 0644 |
|
profiler.rb | File | 4.29 KB | 0644 |
|
pstore.rb | File | 14.85 KB | 0644 |
|
psych.rb | File | 11.45 KB | 0644 |
|
rational.rb | File | 308 B | 0644 |
|
resolv-replace.rb | File | 1.73 KB | 0644 |
|
resolv.rb | File | 61.46 KB | 0644 |
|
ripper.rb | File | 2.53 KB | 0644 |
|
rss.rb | File | 2.84 KB | 0644 |
|
scanf.rb | File | 23.52 KB | 0644 |
|
securerandom.rb | File | 8.56 KB | 0644 |
|
set.rb | File | 17.32 KB | 0644 |
|
shell.rb | File | 10.3 KB | 0644 |
|
shellwords.rb | File | 5.94 KB | 0644 |
|
singleton.rb | File | 4.02 KB | 0644 |
|
socket.rb | File | 25.76 KB | 0644 |
|
sync.rb | File | 7.26 KB | 0644 |
|
tempfile.rb | File | 10.15 KB | 0644 |
|
thread.rb | File | 6.94 KB | 0644 |
|
thwait.rb | File | 3.38 KB | 0644 |
|
time.rb | File | 21.09 KB | 0644 |
|
timeout.rb | File | 3.16 KB | 0644 |
|
tmpdir.rb | File | 4.29 KB | 0644 |
|
tracer.rb | File | 6.54 KB | 0644 |
|
tsort.rb | File | 6.79 KB | 0644 |
|
un.rb | File | 8.34 KB | 0644 |
|
uri.rb | File | 3.07 KB | 0644 |
|
weakref.rb | File | 3.23 KB | 0644 |
|
webrick.rb | File | 6.7 KB | 0644 |
|
xmlrpc.rb | File | 8.49 KB | 0644 |
|
yaml.rb | File | 2.3 KB | 0644 |
|