From 7b792bea7a644309623d67b5d49528ae13da3e7b Mon Sep 17 00:00:00 2001 From: Matthias Hecker Date: Thu, 2 Apr 2020 09:19:40 +0200 Subject: plugin(search): fix search and gcalc, closes #28, #29 --- lib/rbot/core/utils/extends.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index 11ebfc61..08278261 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -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 -- cgit v1.2.3