Sha256: 2d17c9915f676a372294e66c07c616521033cb1bc5d05cef5bebcb35f170c9f4
Contents?: true
Size: 847 Bytes
Versions: 17
Compression:
Stored size: 847 Bytes
Contents
# frozen_string_literal: true String.class_eval do # Remove all non-UTF-8 chars from a string. # # @param replace_with [String, nil] What to replace invalid chars with. # # @return [String] # def clean!(replace_with = '') replace(encode('UTF-8', invalid: :replace, undef: :replace, replace: replace_with)) end # @see {#clean!} def clean(replace_with = '') dup.clean!(replace_with) end # Remove all non-UTF-8 chars from a string and convert to binary. # # @param replace_with [String, nil] What to replace invalid chars with. # # @return [String] # def clean_binary!(replace_with = '') replace(encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: replace_with)) end # @see {#clean_binary!} def clean_binary(replace_with = '') dup.clean_binary!(replace_with) end end
Version data entries
17 entries across 17 versions & 1 rubygems