source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/xsd/iconvcharset.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 697 bytes
Line 
1# XSD4R - Charset handling with iconv.
2# Copyright (C) 2003 NAKAMURA, Hiroshi <[email protected]>.
3
4# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5# redistribute it and/or modify it under the same terms of Ruby's license;
6# either the dual license version in 2003, or any later version.
7
8
9require 'iconv'
10
11
12module XSD
13
14
15class IconvCharset
16 def self.safe_iconv(to, from, str)
17 iconv = Iconv.new(to, from)
18 out = ""
19 begin
20 out << iconv.iconv(str)
21 rescue Iconv::IllegalSequence => e
22 out << e.success
23 ch, str = e.failed.split(//, 2)
24 out << '?'
25 warn("Failed to convert #{ch}")
26 retry
27 end
28 return out
29 end
30end
31
32
33end
Note: See TracBrowser for help on using the repository browser.