Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: kconv.rb
#
[0] Fix | Delete
# kconv.rb - Kanji Converter.
[1] Fix | Delete
#
[2] Fix | Delete
# $Id: kconv.rb 30112 2010-12-07 11:47:39Z naruse $
[3] Fix | Delete
#
[4] Fix | Delete
# ----
[5] Fix | Delete
#
[6] Fix | Delete
# kconv.rb implements the Kconv class for Kanji Converter. Additionally,
[7] Fix | Delete
# some methods in String classes are added to allow easy conversion.
[8] Fix | Delete
#
[9] Fix | Delete
[10] Fix | Delete
require 'nkf'
[11] Fix | Delete
[12] Fix | Delete
#
[13] Fix | Delete
# Kanji Converter for Ruby.
[14] Fix | Delete
#
[15] Fix | Delete
module Kconv
[16] Fix | Delete
#
[17] Fix | Delete
# Public Constants
[18] Fix | Delete
#
[19] Fix | Delete
[20] Fix | Delete
#Constant of Encoding
[21] Fix | Delete
[22] Fix | Delete
# Auto-Detect
[23] Fix | Delete
AUTO = NKF::AUTO
[24] Fix | Delete
# ISO-2022-JP
[25] Fix | Delete
JIS = NKF::JIS
[26] Fix | Delete
# EUC-JP
[27] Fix | Delete
EUC = NKF::EUC
[28] Fix | Delete
# Shift_JIS
[29] Fix | Delete
SJIS = NKF::SJIS
[30] Fix | Delete
# BINARY
[31] Fix | Delete
BINARY = NKF::BINARY
[32] Fix | Delete
# NOCONV
[33] Fix | Delete
NOCONV = NKF::NOCONV
[34] Fix | Delete
# ASCII
[35] Fix | Delete
ASCII = NKF::ASCII
[36] Fix | Delete
# UTF-8
[37] Fix | Delete
UTF8 = NKF::UTF8
[38] Fix | Delete
# UTF-16
[39] Fix | Delete
UTF16 = NKF::UTF16
[40] Fix | Delete
# UTF-32
[41] Fix | Delete
UTF32 = NKF::UTF32
[42] Fix | Delete
# UNKNOWN
[43] Fix | Delete
UNKNOWN = NKF::UNKNOWN
[44] Fix | Delete
[45] Fix | Delete
#
[46] Fix | Delete
# Public Methods
[47] Fix | Delete
#
[48] Fix | Delete
[49] Fix | Delete
# call-seq:
[50] Fix | Delete
# Kconv.kconv(str, to_enc, from_enc=nil)
[51] Fix | Delete
#
[52] Fix | Delete
# Convert <code>str</code> to <code>to_enc</code>.
[53] Fix | Delete
# <code>to_enc</code> and <code>from_enc</code> are given as constants of Kconv or Encoding objects.
[54] Fix | Delete
def kconv(str, to_enc, from_enc=nil)
[55] Fix | Delete
opt = ''
[56] Fix | Delete
opt += ' --ic=' + from_enc.to_s if from_enc
[57] Fix | Delete
opt += ' --oc=' + to_enc.to_s if to_enc
[58] Fix | Delete
[59] Fix | Delete
::NKF::nkf(opt, str)
[60] Fix | Delete
end
[61] Fix | Delete
module_function :kconv
[62] Fix | Delete
[63] Fix | Delete
#
[64] Fix | Delete
# Encode to
[65] Fix | Delete
#
[66] Fix | Delete
[67] Fix | Delete
# call-seq:
[68] Fix | Delete
# Kconv.tojis(str) => string
[69] Fix | Delete
#
[70] Fix | Delete
# Convert <code>str</code> to ISO-2022-JP
[71] Fix | Delete
def tojis(str)
[72] Fix | Delete
kconv(str, JIS)
[73] Fix | Delete
end
[74] Fix | Delete
module_function :tojis
[75] Fix | Delete
[76] Fix | Delete
# call-seq:
[77] Fix | Delete
# Kconv.toeuc(str) => string
[78] Fix | Delete
#
[79] Fix | Delete
# Convert <code>str</code> to EUC-JP
[80] Fix | Delete
def toeuc(str)
[81] Fix | Delete
kconv(str, EUC)
[82] Fix | Delete
end
[83] Fix | Delete
module_function :toeuc
[84] Fix | Delete
[85] Fix | Delete
# call-seq:
[86] Fix | Delete
# Kconv.tosjis(str) => string
[87] Fix | Delete
#
[88] Fix | Delete
# Convert <code>str</code> to Shift_JIS
[89] Fix | Delete
def tosjis(str)
[90] Fix | Delete
kconv(str, SJIS)
[91] Fix | Delete
end
[92] Fix | Delete
module_function :tosjis
[93] Fix | Delete
[94] Fix | Delete
# call-seq:
[95] Fix | Delete
# Kconv.toutf8(str) => string
[96] Fix | Delete
#
[97] Fix | Delete
# Convert <code>str</code> to UTF-8
[98] Fix | Delete
def toutf8(str)
[99] Fix | Delete
kconv(str, UTF8)
[100] Fix | Delete
end
[101] Fix | Delete
module_function :toutf8
[102] Fix | Delete
[103] Fix | Delete
# call-seq:
[104] Fix | Delete
# Kconv.toutf16(str) => string
[105] Fix | Delete
#
[106] Fix | Delete
# Convert <code>str</code> to UTF-16
[107] Fix | Delete
def toutf16(str)
[108] Fix | Delete
kconv(str, UTF16)
[109] Fix | Delete
end
[110] Fix | Delete
module_function :toutf16
[111] Fix | Delete
[112] Fix | Delete
# call-seq:
[113] Fix | Delete
# Kconv.toutf32(str) => string
[114] Fix | Delete
#
[115] Fix | Delete
# Convert <code>str</code> to UTF-32
[116] Fix | Delete
def toutf32(str)
[117] Fix | Delete
kconv(str, UTF32)
[118] Fix | Delete
end
[119] Fix | Delete
module_function :toutf32
[120] Fix | Delete
[121] Fix | Delete
# call-seq:
[122] Fix | Delete
# Kconv.tolocale => string
[123] Fix | Delete
#
[124] Fix | Delete
# Convert <code>self</code> to locale encoding
[125] Fix | Delete
def tolocale(str)
[126] Fix | Delete
kconv(str, Encoding.locale_charmap)
[127] Fix | Delete
end
[128] Fix | Delete
module_function :tolocale
[129] Fix | Delete
[130] Fix | Delete
#
[131] Fix | Delete
# guess
[132] Fix | Delete
#
[133] Fix | Delete
[134] Fix | Delete
# call-seq:
[135] Fix | Delete
# Kconv.guess(str) => encoding
[136] Fix | Delete
#
[137] Fix | Delete
# Guess input encoding by NKF.guess
[138] Fix | Delete
def guess(str)
[139] Fix | Delete
::NKF::guess(str)
[140] Fix | Delete
end
[141] Fix | Delete
module_function :guess
[142] Fix | Delete
[143] Fix | Delete
#
[144] Fix | Delete
# isEncoding
[145] Fix | Delete
#
[146] Fix | Delete
[147] Fix | Delete
# call-seq:
[148] Fix | Delete
# Kconv.iseuc(str) => true or false
[149] Fix | Delete
#
[150] Fix | Delete
# Returns whether input encoding is EUC-JP or not.
[151] Fix | Delete
#
[152] Fix | Delete
# *Note* don't expect this return value is MatchData.
[153] Fix | Delete
def iseuc(str)
[154] Fix | Delete
str.dup.force_encoding(EUC).valid_encoding?
[155] Fix | Delete
end
[156] Fix | Delete
module_function :iseuc
[157] Fix | Delete
[158] Fix | Delete
# call-seq:
[159] Fix | Delete
# Kconv.issjis(str) => true or false
[160] Fix | Delete
#
[161] Fix | Delete
# Returns whether input encoding is Shift_JIS or not.
[162] Fix | Delete
def issjis(str)
[163] Fix | Delete
str.dup.force_encoding(SJIS).valid_encoding?
[164] Fix | Delete
end
[165] Fix | Delete
module_function :issjis
[166] Fix | Delete
[167] Fix | Delete
# call-seq:
[168] Fix | Delete
# Kconv.isjis(str) => true or false
[169] Fix | Delete
#
[170] Fix | Delete
# Returns whether input encoding is ISO-2022-JP or not.
[171] Fix | Delete
def isjis(str)
[172] Fix | Delete
/\A [\t\n\r\x20-\x7E]*
[173] Fix | Delete
(?:
[174] Fix | Delete
(?:\x1b \x28 I [\x21-\x7E]*
[175] Fix | Delete
|\x1b \x28 J [\x21-\x7E]*
[176] Fix | Delete
|\x1b \x24 @ (?:[\x21-\x7E]{2})*
[177] Fix | Delete
|\x1b \x24 B (?:[\x21-\x7E]{2})*
[178] Fix | Delete
|\x1b \x24 \x28 D (?:[\x21-\x7E]{2})*
[179] Fix | Delete
)*
[180] Fix | Delete
\x1b \x28 B [\t\n\r\x20-\x7E]*
[181] Fix | Delete
)*
[182] Fix | Delete
\z/nox =~ str.dup.force_encoding('BINARY') ? true : false
[183] Fix | Delete
end
[184] Fix | Delete
module_function :isjis
[185] Fix | Delete
[186] Fix | Delete
# call-seq:
[187] Fix | Delete
# Kconv.isutf8(str) => true or false
[188] Fix | Delete
#
[189] Fix | Delete
# Returns whether input encoding is UTF-8 or not.
[190] Fix | Delete
def isutf8(str)
[191] Fix | Delete
str.dup.force_encoding(UTF8).valid_encoding?
[192] Fix | Delete
end
[193] Fix | Delete
module_function :isutf8
[194] Fix | Delete
end
[195] Fix | Delete
[196] Fix | Delete
class String
[197] Fix | Delete
# call-seq:
[198] Fix | Delete
# String#kconv(to_enc, from_enc)
[199] Fix | Delete
#
[200] Fix | Delete
# Convert <code>self</code> to <code>to_enc</code>.
[201] Fix | Delete
# <code>to_enc</code> and <code>from_enc</code> are given as constants of Kconv or Encoding objects.
[202] Fix | Delete
def kconv(to_enc, from_enc=nil)
[203] Fix | Delete
from_enc = self.encoding if !from_enc && self.encoding != Encoding.list[0]
[204] Fix | Delete
Kconv::kconv(self, to_enc, from_enc)
[205] Fix | Delete
end
[206] Fix | Delete
[207] Fix | Delete
#
[208] Fix | Delete
# to Encoding
[209] Fix | Delete
#
[210] Fix | Delete
[211] Fix | Delete
# call-seq:
[212] Fix | Delete
# String#tojis => string
[213] Fix | Delete
#
[214] Fix | Delete
# Convert <code>self</code> to ISO-2022-JP
[215] Fix | Delete
def tojis; Kconv.tojis(self) end
[216] Fix | Delete
[217] Fix | Delete
# call-seq:
[218] Fix | Delete
# String#toeuc => string
[219] Fix | Delete
#
[220] Fix | Delete
# Convert <code>self</code> to EUC-JP
[221] Fix | Delete
def toeuc; Kconv.toeuc(self) end
[222] Fix | Delete
[223] Fix | Delete
# call-seq:
[224] Fix | Delete
# String#tosjis => string
[225] Fix | Delete
#
[226] Fix | Delete
# Convert <code>self</code> to Shift_JIS
[227] Fix | Delete
def tosjis; Kconv.tosjis(self) end
[228] Fix | Delete
[229] Fix | Delete
# call-seq:
[230] Fix | Delete
# String#toutf8 => string
[231] Fix | Delete
#
[232] Fix | Delete
# Convert <code>self</code> to UTF-8
[233] Fix | Delete
def toutf8; Kconv.toutf8(self) end
[234] Fix | Delete
[235] Fix | Delete
# call-seq:
[236] Fix | Delete
# String#toutf16 => string
[237] Fix | Delete
#
[238] Fix | Delete
# Convert <code>self</code> to UTF-16
[239] Fix | Delete
def toutf16; Kconv.toutf16(self) end
[240] Fix | Delete
[241] Fix | Delete
# call-seq:
[242] Fix | Delete
# String#toutf32 => string
[243] Fix | Delete
#
[244] Fix | Delete
# Convert <code>self</code> to UTF-32
[245] Fix | Delete
def toutf32; Kconv.toutf32(self) end
[246] Fix | Delete
[247] Fix | Delete
# call-seq:
[248] Fix | Delete
# String#tolocale => string
[249] Fix | Delete
#
[250] Fix | Delete
# Convert <code>self</code> to locale encoding
[251] Fix | Delete
def tolocale; Kconv.tolocale(self) end
[252] Fix | Delete
[253] Fix | Delete
#
[254] Fix | Delete
# is Encoding
[255] Fix | Delete
#
[256] Fix | Delete
[257] Fix | Delete
# call-seq:
[258] Fix | Delete
# String#iseuc => true or false
[259] Fix | Delete
#
[260] Fix | Delete
# Returns whether <code>self</code>'s encoding is EUC-JP or not.
[261] Fix | Delete
def iseuc; Kconv.iseuc(self) end
[262] Fix | Delete
[263] Fix | Delete
# call-seq:
[264] Fix | Delete
# String#issjis => true or false
[265] Fix | Delete
#
[266] Fix | Delete
# Returns whether <code>self</code>'s encoding is Shift_JIS or not.
[267] Fix | Delete
def issjis; Kconv.issjis(self) end
[268] Fix | Delete
[269] Fix | Delete
# call-seq:
[270] Fix | Delete
# String#isjis => true or false
[271] Fix | Delete
#
[272] Fix | Delete
# Returns whether <code>self</code>'s encoding is ISO-2022-JP or not.
[273] Fix | Delete
def isjis; Kconv.isjis(self) end
[274] Fix | Delete
[275] Fix | Delete
# call-seq:
[276] Fix | Delete
# String#isutf8 => true or false
[277] Fix | Delete
#
[278] Fix | Delete
# Returns whether <code>self</code>'s encoding is UTF-8 or not.
[279] Fix | Delete
def isutf8; Kconv.isutf8(self) end
[280] Fix | Delete
end
[281] Fix | Delete
[282] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function