]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/extends.rb
plugin(search): fix search and gcalc, closes #28, #29
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / extends.rb
index 11ebfc613fd7d6022e5e0bbc61e1ae6918669285..08278261fdfa435b21991a069cd66cb7664b9d31 100644 (file)
@@ -380,6 +380,18 @@ class ::String
 
     return txt
   end
+  
+  # Removes non-ASCII symbols from string
+  def remove_nonascii(replace='')
+    encoding_options = {
+      :invalid           => :replace,  # Replace invalid byte sequences
+      :undef             => :replace,  # Replace anything not defined in ASCII
+      :replace           => replace,   
+      :universal_newline => true       # Always break lines with \n
+    }
+
+    self.encode(Encoding.find('ASCII'), encoding_options)
+  end
 end
 
 # Extensions to the Regexp class, with some common and/or complex regular