Sha256: 366d6e7586ef8bb3bd8b7b6d175963b950b8a544b64abd8289a5e810f6f82f06
Contents?: true
Size: 659 Bytes
Versions: 1
Compression:
Stored size: 659 Bytes
Contents
module UTF8Util # use '?' intsead of the unicode replace char, since that is 3 bytes # and can increase the string size if it's done a lot REPLACEMENT_CHAR = "?" # Replace invalid UTF-8 character sequences with a replacement character # # Returns self as valid UTF-8. def self.clean!(str) return str if str.encoding.to_s == "UTF-8" str.force_encoding("binary").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => REPLACEMENT_CHAR) end # Replace invalid UTF-8 character sequences with a replacement character # # Returns a copy of this String as valid UTF-8. def self.clean(str) clean!(str.dup) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
resque_sqs-1.25.2 | lib/resque_sqs/vendor/utf8_util.rb |