Blob Blame History Raw
Index: lib/alexandria/utils.rb
===================================================================
--- lib/alexandria/utils.rb	(revision 1085)
+++ lib/alexandria/utils.rb	(revision 1086)
@@ -15,51 +15,17 @@
 # write to the Free Software Foundation, Inc., 51 Franklin Street,
 # Fifth Floor, Boston, MA 02110-1301 USA.
 
-#begin
 require 'glib2'
 
 class String
-  def convert(charset_from, charset_to)
-    GLib.convert(self, charset_from, charset_to)
+  
+  # Converts this string into the desired charset.
+  #
+  # Note that this may raise a GLib::ConvertError if the
+  # desired_charset cannot accommodate all the characters present in
+  # the string, e.g. trying to convert Japanese Kanji to ISO-8859-1
+  # will obviously not work.
+  def convert(desired_charset, source_data_charset)
+    GLib.convert(self, desired_charset, source_data_charset)
   end
 end
-
-=begin
-rescue LoadError
-
-  # We assume that Ruby/Cocoa is loaded there
-
-  #require 'iconv'
-
-  class String
-    def to_utf8_nsstring
-      # This should be writen in ObjC in order to catch the ObjC exception if the
-      # string could not be converted to UTF8.
-      (OSX::NSString.stringWithUTF8String(self) or self)
-    end
-
-    def convert(charset_from, charset_to)
-      # Do nothing for the moment...
-      self
-    end
-
-        return OSX::NSString.stringWithUTF8String(self)
-        x = Iconv.iconv(charset_to, charset_from, self).first
-        p "#{self} -> #{x}"
-        return x
-        #p charset_from, charset_to
-        #return self
-
-        from = OSX::NSString.alloc.initWithString(self)
-        encoding = charset_to.nsencoding
-        encoding = OSX::NSUnicodeStringEncoding
-        data = from.dataUsingEncoding(encoding)
-        s = OSX::NSString.alloc.initWithData_encoding(data, encoding).to_s
-        s
-        #self
-    end
-
-  end
-
-end
-=end