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