Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/rss
File: converter.rb
# frozen_string_literal: false
[0] Fix | Delete
require_relative "utils"
[1] Fix | Delete
[2] Fix | Delete
module RSS
[3] Fix | Delete
[4] Fix | Delete
class Converter
[5] Fix | Delete
[6] Fix | Delete
include Utils
[7] Fix | Delete
[8] Fix | Delete
def initialize(to_enc, from_enc=nil)
[9] Fix | Delete
if "".respond_to?(:encode)
[10] Fix | Delete
@to_encoding = to_enc
[11] Fix | Delete
return
[12] Fix | Delete
end
[13] Fix | Delete
normalized_to_enc = to_enc.downcase.gsub(/-/, '_')
[14] Fix | Delete
from_enc ||= 'utf-8'
[15] Fix | Delete
normalized_from_enc = from_enc.downcase.gsub(/-/, '_')
[16] Fix | Delete
if normalized_to_enc == normalized_from_enc
[17] Fix | Delete
def_same_enc()
[18] Fix | Delete
else
[19] Fix | Delete
def_diff_enc = "def_to_#{normalized_to_enc}_from_#{normalized_from_enc}"
[20] Fix | Delete
if respond_to?(def_diff_enc)
[21] Fix | Delete
__send__(def_diff_enc)
[22] Fix | Delete
else
[23] Fix | Delete
def_else_enc(to_enc, from_enc)
[24] Fix | Delete
end
[25] Fix | Delete
end
[26] Fix | Delete
end
[27] Fix | Delete
[28] Fix | Delete
def convert(value)
[29] Fix | Delete
if value.is_a?(String) and value.respond_to?(:encode)
[30] Fix | Delete
value.encode(@to_encoding)
[31] Fix | Delete
else
[32] Fix | Delete
value
[33] Fix | Delete
end
[34] Fix | Delete
end
[35] Fix | Delete
[36] Fix | Delete
def def_convert(depth=0)
[37] Fix | Delete
instance_eval(<<-EOC, *get_file_and_line_from_caller(depth))
[38] Fix | Delete
def convert(value)
[39] Fix | Delete
if value.kind_of?(String)
[40] Fix | Delete
#{yield('value')}
[41] Fix | Delete
else
[42] Fix | Delete
value
[43] Fix | Delete
end
[44] Fix | Delete
end
[45] Fix | Delete
EOC
[46] Fix | Delete
end
[47] Fix | Delete
[48] Fix | Delete
def def_iconv_convert(to_enc, from_enc, depth=0)
[49] Fix | Delete
begin
[50] Fix | Delete
require "iconv"
[51] Fix | Delete
@iconv = Iconv.new(to_enc, from_enc)
[52] Fix | Delete
def_convert(depth+1) do |value|
[53] Fix | Delete
<<-EOC
[54] Fix | Delete
begin
[55] Fix | Delete
@iconv.iconv(#{value})
[56] Fix | Delete
rescue Iconv::Failure
[57] Fix | Delete
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
[58] Fix | Delete
end
[59] Fix | Delete
EOC
[60] Fix | Delete
end
[61] Fix | Delete
rescue LoadError, ArgumentError, SystemCallError
[62] Fix | Delete
raise UnknownConversionMethodError.new(to_enc, from_enc)
[63] Fix | Delete
end
[64] Fix | Delete
end
[65] Fix | Delete
[66] Fix | Delete
def def_else_enc(to_enc, from_enc)
[67] Fix | Delete
def_iconv_convert(to_enc, from_enc, 0)
[68] Fix | Delete
end
[69] Fix | Delete
[70] Fix | Delete
def def_same_enc()
[71] Fix | Delete
def_convert do |value|
[72] Fix | Delete
value
[73] Fix | Delete
end
[74] Fix | Delete
end
[75] Fix | Delete
[76] Fix | Delete
def def_uconv_convert_if_can(meth, to_enc, from_enc, nkf_arg)
[77] Fix | Delete
begin
[78] Fix | Delete
require "uconv"
[79] Fix | Delete
def_convert(1) do |value|
[80] Fix | Delete
<<-EOC
[81] Fix | Delete
begin
[82] Fix | Delete
Uconv.#{meth}(#{value})
[83] Fix | Delete
rescue Uconv::Error
[84] Fix | Delete
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
[85] Fix | Delete
end
[86] Fix | Delete
EOC
[87] Fix | Delete
end
[88] Fix | Delete
rescue LoadError
[89] Fix | Delete
require 'nkf'
[90] Fix | Delete
if NKF.const_defined?(:UTF8)
[91] Fix | Delete
def_convert(1) do |value|
[92] Fix | Delete
"NKF.nkf(#{nkf_arg.dump}, #{value})"
[93] Fix | Delete
end
[94] Fix | Delete
else
[95] Fix | Delete
def_iconv_convert(to_enc, from_enc, 1)
[96] Fix | Delete
end
[97] Fix | Delete
end
[98] Fix | Delete
end
[99] Fix | Delete
[100] Fix | Delete
def def_to_euc_jp_from_utf_8
[101] Fix | Delete
def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8', '-We')
[102] Fix | Delete
end
[103] Fix | Delete
[104] Fix | Delete
def def_to_utf_8_from_euc_jp
[105] Fix | Delete
def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP', '-Ew')
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
def def_to_shift_jis_from_utf_8
[109] Fix | Delete
def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8', '-Ws')
[110] Fix | Delete
end
[111] Fix | Delete
[112] Fix | Delete
def def_to_utf_8_from_shift_jis
[113] Fix | Delete
def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS', '-Sw')
[114] Fix | Delete
end
[115] Fix | Delete
[116] Fix | Delete
def def_to_euc_jp_from_shift_jis
[117] Fix | Delete
require "nkf"
[118] Fix | Delete
def_convert do |value|
[119] Fix | Delete
"NKF.nkf('-Se', #{value})"
[120] Fix | Delete
end
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
def def_to_shift_jis_from_euc_jp
[124] Fix | Delete
require "nkf"
[125] Fix | Delete
def_convert do |value|
[126] Fix | Delete
"NKF.nkf('-Es', #{value})"
[127] Fix | Delete
end
[128] Fix | Delete
end
[129] Fix | Delete
[130] Fix | Delete
def def_to_euc_jp_from_iso_2022_jp
[131] Fix | Delete
require "nkf"
[132] Fix | Delete
def_convert do |value|
[133] Fix | Delete
"NKF.nkf('-Je', #{value})"
[134] Fix | Delete
end
[135] Fix | Delete
end
[136] Fix | Delete
[137] Fix | Delete
def def_to_iso_2022_jp_from_euc_jp
[138] Fix | Delete
require "nkf"
[139] Fix | Delete
def_convert do |value|
[140] Fix | Delete
"NKF.nkf('-Ej', #{value})"
[141] Fix | Delete
end
[142] Fix | Delete
end
[143] Fix | Delete
[144] Fix | Delete
def def_to_utf_8_from_iso_8859_1
[145] Fix | Delete
def_convert do |value|
[146] Fix | Delete
"#{value}.unpack('C*').pack('U*')"
[147] Fix | Delete
end
[148] Fix | Delete
end
[149] Fix | Delete
[150] Fix | Delete
def def_to_iso_8859_1_from_utf_8
[151] Fix | Delete
def_convert do |value|
[152] Fix | Delete
<<-EOC
[153] Fix | Delete
array_utf8 = #{value}.unpack('U*')
[154] Fix | Delete
array_enc = []
[155] Fix | Delete
array_utf8.each do |num|
[156] Fix | Delete
if num <= 0xFF
[157] Fix | Delete
array_enc << num
[158] Fix | Delete
else
[159] Fix | Delete
array_enc.concat "&\#\#{num};".unpack('C*')
[160] Fix | Delete
end
[161] Fix | Delete
end
[162] Fix | Delete
array_enc.pack('C*')
[163] Fix | Delete
EOC
[164] Fix | Delete
end
[165] Fix | Delete
end
[166] Fix | Delete
[167] Fix | Delete
end
[168] Fix | Delete
[169] Fix | Delete
end
[170] Fix | Delete
[171] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function