source: subversion/sites/rails_port/lib/utf8.rb @ 17044

Last change on this file since 17044 was 16707, checked in by zere, 10 years ago

Added methods to strip those non-XML control characters from tags in AMF controller and give an error if there's invalid UTF-8.

File size: 302 bytes
Line 
1module 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  def self.valid?(str)
6    return true if str.nil?
7    Iconv.conv("UTF-8", "UTF-8", str)
8    return true
9   
10  rescue
11    return false
12  end 
13end
14
Note: See TracBrowser for help on using the repository browser.