# File lib/types/strings.rb, line 22 def self.is_valid_utf?(value) # In Ruby 1.9+ we have encoding methods that can check the content of # the string, so use them to see if what we have is unicode. If so, # good! If not, then just treat is as binary. # # No such thing in Ruby 1.8. So there we need to use Iconv to try and # convert it to unicode. If it works, good! But if it raises an # exception then we'll treat it as binary. if RUBY_VERSION < "1.9" return true if value.isutf8 return false else return true if (value.encoding == "UTF-8" || value.encode("UTF-8").valid_encoding?) return false end end