class UnicodePlugin::UnicodeFilter

Public Class Methods

new(oenc, *iencs) click to toggle source
# File lib/rbot/core/unicode.rb, line 31
def initialize(oenc, *iencs)
    o = oenc.dup
    o += '//ignore' if !o.include?('/')
    i = iencs[0].dup
    # i += '//ignore' if !i.include?('/')
    @iencs = iencs.dup
    @iconvs = @iencs.map { |_| Iconv.new('utf-8', _) }
    debug "*** o = #{o}, i = #{i}, iencs = #{iencs.inspect}"
    @default_in = Iconv.new('utf-8//ignore', i)
    @default_out = Iconv.new(o, 'utf-8//ignore')
end

Public Instance Methods

in(data) click to toggle source
# File lib/rbot/core/unicode.rb, line 43
def in(data)
    rv = nil
    @iconvs.each_with_index { |ic, idx|
        begin
            debug "trying #{@iencs[idx]}"
            rv = ic.iconv(data)
            break
        rescue
        end
    }

    rv = @default_in.iconv(data) if !rv
    debug ">> #{rv.inspect}"
    return rv
end
out(data) click to toggle source
# File lib/rbot/core/unicode.rb, line 59
def out(data)
    rv = @default_out.iconv(data) rescue data # XXX: yeah, i know :/
    debug "<< #{rv}"
    rv
end