Method: ActiveSupport::Multibyte::Unicode#tidy_bytes

Defined in:
lib/active_support/multibyte/unicode.rb,
lib/active_support/multibyte/unicode.rb

#tidy_bytes(string, force = false) ⇒ Object

Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent resulting in a valid UTF-8 string.

Passing true will forcibly tidy all bytes, assuming that the string’s encoding is entirely CP1252 or ISO-8859-1.



44
45
46
47
48
# File 'lib/active_support/multibyte/unicode.rb', line 44

def tidy_bytes(string, force = false)
  return string if string.empty? || string.ascii_only?
  return recode_windows1252_chars(string) if force
  string.scrub { |bad| recode_windows1252_chars(bad) }
end