]> git.cworth.org Git - sup/blobdiff - lib/sup/util.rb
Allow multi_edit_labels to remove labels using -lab (the "; l" key binding)
[sup] / lib / sup / util.rb
index 9909022ffa9b0b1c5796f4fbdff925087dec2519..fc625328b2afb63310b4fa39ed196217d4eeae0b 100644 (file)
@@ -617,3 +617,20 @@ class FinishLine
     @m.synchronize { !@over && @over = true }
   end
 end
+
+class Iconv
+  def self.easy_decode target, charset, text
+    return text if charset =~ /^(x-unknown|unknown[-_]?8bit|ascii[-_]?7[-_]?bit)$/i
+    charset = case charset
+                when /UTF[-_]?8/i: "utf-8"
+                when /(iso[-_])?latin[-_]?1$/i: "ISO-8859-1"
+                when /unicode[-_]1[-_]1[-_]utf[-_]7/i: "utf-7"
+                else charset
+              end
+
+    # Convert:
+    #
+    # Remember - Iconv.open(to, from)!
+    Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2]
+  end
+end