]> git.openstreetmap.org Git - rails.git/blob - lib/utf8.rb
Use larger 'spinner' when waiting for route request. Replace HTML in content to avoid...
[rails.git] / lib / utf8.rb
1 module UTF8
2   ##
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?")
6     def self.valid?(str)
7       return true if str.nil?
8       return str.valid_encoding?
9     end
10   else
11     require 'iconv'
12
13     def self.valid?(str)
14       return true if str.nil?
15       Iconv.conv("UTF-8", "UTF-8", str)
16       return true
17     rescue
18       return false
19     end
20   end
21 end