3   # Checks that a string is valid UTF-8 by trying to convert it to UTF-8
 
   4   # using the iconv library, which is in the standard library.
 
   5   if String.new.respond_to?("valid_encoding?")
 
   7       return true if str.nil?
 
   8       return str.valid_encoding?
 
  14       return true if str.nil?
 
  15       Iconv.conv("UTF-8", "UTF-8", str)