1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rss/converter.rb: handled Uconv::Error.

* lib/rss/dublincore.rb: DublincoreModel -> DublinCoreModel


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2004-03-02 16:21:11 +00:00
parent a5e13ce5ff
commit 40daca4a87
4 changed files with 42 additions and 45 deletions

View file

@ -1,3 +1,9 @@
Wed Mar 3 01:18:52 2004 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/converter.rb: handled Uconv::Error.
* lib/rss/dublincore.rb: DublincoreModel -> DublinCoreModel
Wed Mar 3 00:59:30 2004 David Black <dblack@wobblini.net>
* scanf.rb: soak_up_spaces only ungetc's non-space last

View file

@ -75,11 +75,11 @@ EORDF
private
def xmldecl
rv = "<?xml version='#{@version}'"
rv = %Q[<?xml version="#{@version}"]
if @output_encoding or @encoding
rv << " encoding='#{@output_encoding or @encoding}'"
rv << %Q[ encoding="#{@output_encoding or @encoding}"]
end
rv << " standalone='#{@standalone}'" if @standalone
rv << %Q[ standalone="#{@standalone}"] if @standalone
rv << '?>'
rv
end
@ -138,10 +138,10 @@ EORDF
def to_s(convert=true)
<<-EOT
<#{PREFIX}:Seq>
#{li_elements(convert, "\t\t\t\t\t")}
#{other_element(convert, "\t\t\t\t\t")}
</#{PREFIX}:Seq>
<#{PREFIX}:Seq>
#{li_elements(convert, "\t\t\t\t")}
#{other_element(convert, "\t\t\t\t")}
</#{PREFIX}:Seq>
EOT
end
@ -189,7 +189,7 @@ EOT
def to_s(convert=true)
if @resource
rv = %Q!<#{PREFIX}:li resource="#{h @resource}" />!
rv = %Q!<#{PREFIX}:li resource="#{h @resource}" />\n!
rv = @converter.convert(rv) if convert and @converter
rv
else

View file

@ -47,9 +47,8 @@ module RSS
@iconv.iconv(#{value})
rescue Iconv::Failure
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
#{value}
end
EOC
EOC
end
rescue LoadError, ArgumentError, SystemCallError
raise UnknownConversionMethodError.new(to_enc, from_enc)
@ -66,48 +65,37 @@ EOC
end
end
def def_to_euc_jp_from_utf_8
def def_uconv_convert_if_can(meth, to_enc, from_enc)
begin
require "uconv"
def_convert do |value|
"Uconv.u8toeuc(#{value})"
<<-EOC
begin
Uconv.#{meth}(#{value})
rescue Uconv::Error
raise ConversionError.new(#{value}, "#{to_enc}", "#{from_enc}")
end
EOC
end
rescue LoadError
def_iconv_convert('EUC-JP', 'UTF-8')
def_iconv_convert(to_enc, from_enc)
end
end
def def_to_euc_jp_from_utf_8
def_uconv_convert_if_can('u8toeuc', 'EUC-JP', 'UTF-8')
end
def def_to_utf_8_from_euc_jp
begin
require "uconv"
def_convert do |value|
"Uconv.euctou8(#{value})"
end
rescue LoadError
def_iconv_convert('UTF-8', 'EUC-JP')
end
def_uconv_convert_if_can('euctou8', 'UTF-8', 'EUC-JP')
end
def def_to_shift_jis_from_utf_8
begin
require "uconv"
def_convert do |value|
"Uconv.u8tosjis(#{value})"
end
rescue LoadError
def_iconv_convert('Shift_JIS', 'UTF-8')
end
def_uconv_convert_if_can('u8tosjis', 'Shift_JIS', 'UTF-8')
end
def def_to_utf_8_from_shift_jis
begin
require "uconv"
def_convert do |value|
"Uconv.sjistou8(#{value})"
end
rescue LoadError
def_iconv_convert('UTF-8', 'Shift_JIS')
end
def_uconv_convert_if_can('sjistou8', 'UTF-8', 'Shift_JIS')
end
def def_to_euc_jp_from_shift_jis
@ -157,7 +145,7 @@ EOC
end
end
array_enc.pack('C*')
EOC
EOC
end
end

View file

@ -7,7 +7,7 @@ module RSS
RDF.install_ns(DC_PREFIX, DC_URI)
module DublincoreModel
module DublinCoreModel
extend BaseModel
@ -43,16 +43,19 @@ module RSS
end
# For backward compatibility
DublincoreModel = DublinCoreModel
class RDF
class Channel; include DublincoreModel; end
class Image; include DublincoreModel; end
class Item; include DublincoreModel; end
class Textinput; include DublincoreModel; end
class Channel; include DublinCoreModel; end
class Image; include DublinCoreModel; end
class Item; include DublinCoreModel; end
class Textinput; include DublinCoreModel; end
end
prefix_size = DC_PREFIX.size + 1
DublincoreModel::ELEMENTS.uniq!
DublincoreModel::ELEMENTS.each do |x|
DublinCoreModel::ELEMENTS.uniq!
DublinCoreModel::ELEMENTS.each do |x|
BaseListener.install_get_text_element(x[prefix_size..-1], DC_URI, "#{x}=")
end