Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • iconv/charset_alias.rb
  • iconv/mkwrapper.rb

Parent

Methods

Object

Public Instance Methods

charset_alias(config_charset, mapfile = nil) click to toggle source
 
               # File iconv/mkwrapper.rb, line 15
def charset_alias(config_charset, mapfile = nil)
  found = nil
  src = [HEADER]
  open(config_charset) do |input|
    input.find {|line| /^case "\$os" in/ =~ line} or return
    input.each do |line|
      case line
      when /^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/
        (s = "  when ") << $&.split('|').collect {|targ|
          targ.strip!
          tail = targ.chomp!("*") ? '' : '\z'
          head = targ.slice!(/\A\*/) ? '' : '\A'
          targ.gsub!(/\*/, '.*')
          "/#{head}#{targ}#{tail}/"
        }.join(", ")
        src << s
        found = {}
      when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
        sys, can = $1, $2
        can.downcase!
        unless found[can] or (/\Aen_(?!US\z)/ =~ sys && /\ACP437\z/i =~ can)
          found[can] = true
          src << "    charset_map['#{can}'] = '#{sys}'.freeze"
        end
      when /^\s*;;/
        found = nil
      end
    end
  end
  src << "  end" << "end"
  if mapfile
    open(mapfile, "wb") {|f| f.puts(*src)}
  else
    puts(*src)
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.