From: Tilman Sauerbeck Date: Wed, 3 Mar 2010 20:39:44 +0000 (+0100) Subject: Added locale_from_utf8, dropped the glib dependency. X-Git-Url: http://git.code-monkey.de/?p=rb-rip.git;a=commitdiff_plain;h=491ceca784024c01e8cb771d75c87419397a8928 Added locale_from_utf8, dropped the glib dependency. --- diff --git a/rb-rip b/rb-rip index 33c96bf..58e3bc3 100755 --- a/rb-rip +++ b/rb-rip @@ -4,7 +4,7 @@ require 'fileutils' require "musicbrainz" require "yaml" require "ostruct" -#require "glib2" +require 'iconv' require "tempfile" class Track @@ -176,6 +176,18 @@ class String end end +def locale_from_utf8(s) + # FIXME: Encoding is only available in Ruby 1.9 + to_charset = Encoding.locale_charmap + utf8 = 'UTF-8'.freeze + + if to_charset == utf8 + s.dup + else + Iconv.iconv to_charset, utf8, s + end +end + cfg_file = ARGV.first || File.expand_path("~/.rbrip.yaml") begin @@ -230,8 +242,7 @@ puts "Disc info:\n Tracks:\n" album.tracks.each_with_index do |t, i| - #tmp = GLib.locale_from_utf8(t.name) - tmp = t.name + tmp = locale_from_utf8 t.name puts "%3s." % (i + 1) + " #{tmp}" end